Skip to main content
A generation is a single LLM call inside a trace. Record it with trace.recordGeneration() / trace.record_generation() after the model call completes.

Record a generation

Pass the full ordered message list for that call as both input and llmInputMessages / llm_input_messages. The root trace input is only the current user turn; the generation should include system, prior turns, tool results, and the current user message. When the provider returns token counts, pass them as usage (TypeScript camelCase) or input_tokens / output_tokens / … kwargs (Python). Omit usage when the provider did not supply it — do not invent zeros. Explicit zeros are fine and mean “provider reported zero.” See Token usage and Analytics telemetry.

Measure a live generation

Use startGeneration() / start_generation() when you want a handle before the model call finishes. End it only after the provider returns or fails.

What the SDK records

See Native contract props and Client fields vs ingest normalization.

Errors

If a model call fails, record a failed generation before rethrowing:

Next steps

Tool calls

Record tool arguments and results.

Spans

Trace retrieval, ranking, and app logic.