Docs

    SDK reference

    What is traced automatically

    The model providers, agent frameworks, HTTP clients, databases and vector stores each SDK traces after init(), what a model-call span records, and how streamed calls are traced, with token counts through include_usage and the rules for time to first token.

    After init(), each SDK patches the supported libraries it finds installed; there is nothing to add per call. This page lists them for both SDKs, says what a model-call span holds, and explains how streamed calls are recorded. To narrow what is captured, see Configuration and privacy.

    • Call init() before the modules that create clients are imported. Most patches replace methods on a library's classes, so a client created earlier is covered too, but a function imported by name before init(), such as from litellm import completion, stays unpatched.
    • In TypeScript, axios and mongoose are patched only when they were loaded before init(). Loaded later, their calls still show through the Node.js HTTP and OpenTelemetry instrumentation.
    • The provider's own HTTP request is recorded too, when the client sends it through an HTTP library the SDK traces. Python records it as an HTTP span with its bodies, for clients on httpx, httpx2, requests or aiohttp. TypeScript records it without bodies, as events on the model-call span for clients that use fetch, such as OpenAI and Anthropic, or as an HTTP span for clients on node:http.

    Model providers

    ProviderPythonTypeScript
    OpenAI chat completionsSync and async, streamed or notStreamed or not, .withResponse() and beta.chat.completions.parse() included
    OpenAI ResponsesSync and async, streamed or not, and responses.stream()responses.create, streamed or not, responses.stream() and responses.parse()
    Azure OpenAI and OpenAI-compatible serversThrough the openai client, recorded as OpenAIThrough the openai client, recorded as OpenAI
    Anthropicmessages.create, streamed or not, and messages.stream(), sync and async, AnthropicVertex includedmessages.create, streamed or not, AnthropicVertex included
    Google Gen AI (google-genai, @google/genai), for Gemini and Vertex AIgenerate_content and generate_content_stream, sync and asyncgenerateContent and generateContentStream
    Google AI, earlier SDK (google-generativeai, @google/generative-ai)generate_content, streamed or notgenerateContent and generateContentStream
    Vertex AI SDK (vertexai, @google-cloud/vertexai)After one patch call per model; see What you wire up yourselfgenerateContent and generateContentStream
    AWS Bedrockboto3 and aiobotocore: Converse and InvokeModel, streamed or not, and the Bedrock Agent RuntimeThe same, through the AWS SDK clients
    Coherechat and chat_stream, v1 and v2 clients, sync and asyncchat, chatStream and chat with stream: true, v1 and v2 clients
    Mistralchat.complete and chat.stream, sync and asyncNot traced
    GroqAs OpenAI chat completionsAs OpenAI chat completions
    Ollamachat, streamed or not, sync and asyncchat, streamed or not
    LiteLLMcompletion and acompletion, streamed or notNot applicable
    Speech and audioOpenAI audio, ElevenLabs, AssemblyAIOpenAI audio and AssemblyAI; ElevenLabs after one patch call per client
    Realtime and live sessionsOpenAI Realtime, Gemini LiveOpenAI Realtime over WebSocket, Gemini Live

    Agent frameworks and tools

    LibraryPythonTypeScript
    LangChain and LangGraphYes. Spans inside a LangGraph node carry its node, step and triggersYes, through a callback handler added to every run, with the same LangGraph attributes. A graph run outside a request gets a root span, and each model call is one span
    LlamaIndexYes. A model call and the provider request it makes are one spanYes
    Claude Agent SDKYesNo
    Google ADKYesYes
    MCP clientsYesYes
    Other OpenTelemetry instrumentation that records model calls, such as StrandsIts spans are sent with EvalKit's and typed by gen_ai.operation.nameThe same

    HTTP, databases, logs and your code

    KindPythonTypeScript
    Outgoing HTTPrequests, httpx, httpx2, aiohttp, with headers and bodiesnode:http and https with headers; fetch as events on the current span; bodies for axios
    Incoming requestsFastAPI, Starlette, Flask, Django and Litestar, with one middleware line each; see Web frameworksEvery Node.js HTTP and HTTPS server, with no code. Express and NestJS requests are named by route; the Fastify, Koa, Hono and hapi adapters name them by route too
    DatabasesRedis, PyMongo, asyncpg, psycopg 3, psycopg2 and PyMySQL; psycopg2 also records each connect() as a postgresql CONNECT span. SQLAlchemy after one patch call per engine, and a statement SQLAlchemy records is not recorded again by the driverpg, mysql2, ioredis and mongoose, plus the MongoDB and Redis drivers through OpenTelemetry. Prisma after one call
    Vector storesPinecone, Qdrant, Chroma, WeaviatePinecone, Qdrant, Chroma, Weaviate
    LogsEvery record at log_level and up, WARNING by default, that reaches the root logger, as a log span; see Logs and console outputconsole.log, console.warn and console.error: an event on the current span, or, for warnings and errors, a log span outside one
    Your own codePublic module-level functions of your source tree, by defaultOnly what you wrap, or every provider and controller method on NestJS

    A database span records the SQL text with its operation, table, row count and latency; TypeScript's pg and mysql2 spans also record the bound parameters. How your own functions are traced, and how to keep their arguments out, is in Function inputs and outputs.

    What a model-call span records

    • The model asked for and the model that answered, the provider, the prompt as one role: text line per message, the completion, and the thinking text where the provider returns it.
    • Input, output, cache-read, cache-write and reasoning tokens as the provider reports them. Cost is worked out by the platform from the tokens and its price list, not by the SDK.
    • The names of the tools the request offered (gen_ai.request.tools), temperature, top-p and the max-tokens setting, which together tell one agent version from another. TypeScript, and Python for some providers, also keep the request and response bodies in gen_ai.request.body and gen_ai.response.body.
    • Each tool call the model asked for, streamed or not, as a gen_ai.tool.call event with its name, id and arguments. When the provider ran the tool itself and returned the result, that tool also gets a tool_call span of its own.
    • Latency, status, finish reasons and, on failure, the exception the provider raised, a stream that failed part way included, as on Errors and stack traces.

    When a provider reports no token counts, the trace service estimates them from the prompt and completion, at about four characters per token, and marks the span evalkit.cost_estimated: true.

    Streamed calls

    A streamed call is one model-call span. The SDK watches the stream the client returns: your code reads the same chunks, unchanged and as they arrive, while the SDK collects the text, the usage and the tool calls on the side. The span is written when the stream ends.

    • The stream your code gets is the provider SDK's own object, with its whole API: in TypeScript an OpenAI or Anthropic Stream keeps controller, tee() and toReadableStream(), and helpers such as MessageStream with finalMessage(), responses.stream() and .withResponse() work as without the SDK; in Python next(), close(), isinstance(stream, openai.Stream) and with_raw_response work.
    • When the last chunk is read, the span gets the assembled completion, the token counts from the usage the provider sent, gen_ai.streaming: true and the time to first token. Both SDKs also assemble tool calls from their deltas into gen_ai.tool.call events; TypeScript does so for OpenAI, Anthropic, Cohere, Bedrock, Gemini and Ollama.
    • If your code stops reading early, with break or by leaving a with block in Python, the span is written with what had arrived, as a success.
    • If the stream fails part way, the span is written with the text received so far, an error status and the error message, and without a time to first token.
    • A stream your code drops without reading writes its span when it is garbage collected.
    • If the request fails before the stream opens, such as a refused connection, a 400 or a 401, both SDKs write an ERROR model-call span with the model, the prompt and the error.
    • Nothing turns stream tracing off. Content capture off removes the completion as for any call; counts and timing stay.
    Streams ofPythonTypeScript
    OpenAI chat completions and GroqTraced, with time to first tokenTraced, with time to first token
    OpenAI ResponsesTraced, with time to first tokenTraced, with time to first token
    Anthropiccreate(stream=True) with time to first token; messages.stream() without itcreate({ stream: true }) with time to first token
    Google Gen AITraced, with time to first tokenTraced, with time to first token
    Google AI, earlier SDK, and the Vertex AI SDKTraced, with time to first token (Vertex after its patch call)Traced, with time to first token
    Bedrock streaming (Converse and InvokeModel)Traced, with time to first tokenTraced, with time to first token
    CohereTraced, with time to first tokenTraced, with time to first token
    Mistral, LiteLLMTraced, with time to first tokenNot traced (LiteLLM has no TypeScript client)
    OllamaTraced, with time to first tokenTraced, with time to first token

    Token counts in streams

    OpenAI sends usage in a stream only when the request asks for it. Without include_usage, the SDK records 0 input and 0 output tokens and logs a warning once per process. The trace service then estimates both from the text and marks the span evalkit.cost_estimated; with content capture off there is no text, and the call shows no tokens and no cost.

    stream = client.chat.completions.create(
        model="gpt-4o-mini",
        messages=messages,
        stream=True,
        stream_options={"include_usage": True},   # OpenAI sends a final usage chunk only when asked
    )
    for chunk in stream:
        if chunk.choices and chunk.choices[0].delta.content:   # the usage chunk has no choices
            print(chunk.choices[0].delta.content, end="")

    The warning is for OpenAI itself. OpenAI-compatible servers reached through the openai client follow the same option where they support it. Anthropic, Gemini and Bedrock send usage in the stream without an option.

    Time to first token

    A streamed span carries gen_ai.server.time_to_first_token_ms, the milliseconds from the call to the first generated text. Four rules decide it:

    1. The clock starts when your code makes the call, before the request is sent, so the time includes connecting and any queueing at the provider.
    2. Only generated text stops it: reply text, or reasoning text where the provider streams it, such as Anthropic thinking. Role markers, empty chunks, usage chunks and tool-call chunks do not.
    3. A reply made only of tool calls has no time to first token. The attribute is absent, not zero, so averages are not pulled toward zero.
    4. A stream that fails records none, even when text had arrived before the failure.

    An HTTP stream read through requests, httpx or aiohttp in Python carries http.server.time_to_first_byte_ms instead, measured from the request to the first chunk of the body. See Streaming for its switch.

    What you wire up yourself

    • Python: SQLAlchemy engines (patch_sqlalchemy_engine(engine), or patch_async_sqlalchemy_engine for an async engine), the Vertex AI SDK (patch_vertex_generative_model(model)), and class methods (@evalkit.traced). From 0.3.6 a patch_* call that cannot instrument its target logs a warning and leaves it untraced, instead of raising.
    • TypeScript: your own functions and classes (traceFunction, Traced, enableNestjsAutoTrace), ElevenLabs (patchElevenLabsClientInstance) and Prisma (instrumentPrisma).
    • Neither SDK traces code that runs in the browser. From 0.3.6 the TypeScript package imports there, and on edge runtimes, as a stub that traces nothing; see Serverless and edge runtimes.

    EvalKit is built by SyntropyLabs. Published on PyPI and npm.