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 beforeinit(), such asfrom litellm import completion, stays unpatched. - In TypeScript,
axiosandmongooseare patched only when they were loaded beforeinit(). 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,requestsoraiohttp. TypeScript records it without bodies, as events on the model-call span for clients that usefetch, such as OpenAI and Anthropic, or as an HTTP span for clients onnode:http.
Model providers
| Provider | Python | TypeScript |
|---|---|---|
| OpenAI chat completions | Sync and async, streamed or not | Streamed or not, .withResponse() and beta.chat.completions.parse() included |
| OpenAI Responses | Sync and async, streamed or not, and responses.stream() | responses.create, streamed or not, responses.stream() and responses.parse() |
| Azure OpenAI and OpenAI-compatible servers | Through the openai client, recorded as OpenAI | Through the openai client, recorded as OpenAI |
| Anthropic | messages.create, streamed or not, and messages.stream(), sync and async, AnthropicVertex included | messages.create, streamed or not, AnthropicVertex included |
Google Gen AI (google-genai, @google/genai), for Gemini and Vertex AI | generate_content and generate_content_stream, sync and async | generateContent and generateContentStream |
Google AI, earlier SDK (google-generativeai, @google/generative-ai) | generate_content, streamed or not | generateContent and generateContentStream |
Vertex AI SDK (vertexai, @google-cloud/vertexai) | After one patch call per model; see What you wire up yourself | generateContent and generateContentStream |
| AWS Bedrock | boto3 and aiobotocore: Converse and InvokeModel, streamed or not, and the Bedrock Agent Runtime | The same, through the AWS SDK clients |
| Cohere | chat and chat_stream, v1 and v2 clients, sync and async | chat, chatStream and chat with stream: true, v1 and v2 clients |
| Mistral | chat.complete and chat.stream, sync and async | Not traced |
| Groq | As OpenAI chat completions | As OpenAI chat completions |
| Ollama | chat, streamed or not, sync and async | chat, streamed or not |
| LiteLLM | completion and acompletion, streamed or not | Not applicable |
| Speech and audio | OpenAI audio, ElevenLabs, AssemblyAI | OpenAI audio and AssemblyAI; ElevenLabs after one patch call per client |
| Realtime and live sessions | OpenAI Realtime, Gemini Live | OpenAI Realtime over WebSocket, Gemini Live |
Agent frameworks and tools
| Library | Python | TypeScript |
|---|---|---|
| LangChain and LangGraph | Yes. Spans inside a LangGraph node carry its node, step and triggers | Yes, 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 |
| LlamaIndex | Yes. A model call and the provider request it makes are one span | Yes |
| Claude Agent SDK | Yes | No |
| Google ADK | Yes | Yes |
| MCP clients | Yes | Yes |
| Other OpenTelemetry instrumentation that records model calls, such as Strands | Its spans are sent with EvalKit's and typed by gen_ai.operation.name | The same |
HTTP, databases, logs and your code
| Kind | Python | TypeScript |
|---|---|---|
| Outgoing HTTP | requests, httpx, httpx2, aiohttp, with headers and bodies | node:http and https with headers; fetch as events on the current span; bodies for axios |
| Incoming requests | FastAPI, Starlette, Flask, Django and Litestar, with one middleware line each; see Web frameworks | Every 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 |
| Databases | Redis, 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 driver | pg, mysql2, ioredis and mongoose, plus the MongoDB and Redis drivers through OpenTelemetry. Prisma after one call |
| Vector stores | Pinecone, Qdrant, Chroma, Weaviate | Pinecone, Qdrant, Chroma, Weaviate |
| Logs | Every record at log_level and up, WARNING by default, that reaches the root logger, as a log span; see Logs and console output | console.log, console.warn and console.error: an event on the current span, or, for warnings and errors, a log span outside one |
| Your own code | Public module-level functions of your source tree, by default | Only 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: textline 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 ingen_ai.request.bodyandgen_ai.response.body. - Each tool call the model asked for, streamed or not, as a
gen_ai.tool.callevent with its name, id and arguments. When the provider ran the tool itself and returned the result, that tool also gets atool_callspan 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
Streamkeepscontroller,tee()andtoReadableStream(), and helpers such asMessageStreamwithfinalMessage(),responses.stream()and.withResponse()work as without the SDK; in Pythonnext(),close(),isinstance(stream, openai.Stream)andwith_raw_responsework. - When the last chunk is read, the span gets the assembled completion, the token counts from the usage the provider sent,
gen_ai.streaming: trueand the time to first token. Both SDKs also assemble tool calls from their deltas intogen_ai.tool.callevents; TypeScript does so for OpenAI, Anthropic, Cohere, Bedrock, Gemini and Ollama. - If your code stops reading early, with
breakor by leaving awithblock 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
400or a401, both SDKs write anERRORmodel-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 of | Python | TypeScript |
|---|---|---|
| OpenAI chat completions and Groq | Traced, with time to first token | Traced, with time to first token |
| OpenAI Responses | Traced, with time to first token | Traced, with time to first token |
| Anthropic | create(stream=True) with time to first token; messages.stream() without it | create({ stream: true }) with time to first token |
| Google Gen AI | Traced, with time to first token | Traced, with time to first token |
| Google AI, earlier SDK, and the Vertex AI SDK | Traced, 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 token | Traced, with time to first token |
| Cohere | Traced, with time to first token | Traced, with time to first token |
| Mistral, LiteLLM | Traced, with time to first token | Not traced (LiteLLM has no TypeScript client) |
| Ollama | Traced, with time to first token | Traced, 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:
- 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.
- 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.
- 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.
- 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), orpatch_async_sqlalchemy_enginefor an async engine), the Vertex AI SDK (patch_vertex_generative_model(model)), and class methods (@evalkit.traced). From 0.3.6 apatch_*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.