vercelAI() when your app calls generateText, streamText, or an AI SDK agent. The integration supports AI SDK v7 and v6. It creates one Lemma trace for each AI SDK run, puts the current user turn on the root, promotes threadId / userId from telemetry metadata, and records model calls and tool executions as child spans.
Create a new vercelAI() integration for each AI SDK operation. One integration object owns one in-flight run; concurrent reuse fails fast because AI SDK terminal events do not carry a reliable run ID. Sequential reuse after a completed run is supported.
Install
AI SDK v7
Pass a fresh Lemma telemetry integration to the AI SDKtelemetry.integrations option. Use telemetry.functionId for the agent name and put conversation identity in telemetry.metadata.
AI SDK v6
For AI SDK v6, pass the same helper throughexperimental_telemetry.integrations. Use experimental_telemetry.functionId for the agent name.
Streaming
Use the same per-operation integration withstreamText. Call flush() after the stream finishes to send the trace. Call fail(error) if the call throws before a terminal callback.
What Lemma records
AI SDK v7 provides model and tool durations directly. AI SDK v6 provides tool execution durations; model-call durations are inferred from start and finish timestamps when the AI SDK does not provide an explicit duration. For v6,
system + prompt are normalized into chat messages on the generation.
Use telemetry.functionId / experimental_telemetry.functionId for the agent name, or set it on the integration with vercelAI({ agentName: "support-agent" }).
Override metadata keys when needed:
vercelAI({ trace }) or by calling AI SDK inside a lemma.trace() callback. If you use the callback form of lemma.trace(), the callback owns trace closure. If you pass a trace handle to vercelAI({ trace }), the integration closes it automatically at the end of the AI SDK operation.
Prompts, tool inputs, tool outputs, model output, and error messages are always recorded. Redact secrets and sensitive user data before they reach the AI SDK call.