trace.recordGeneration() / trace.record_generation() after the model call completes.
Record a generation
- TypeScript
- Python
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
UsestartGeneration() / start_generation() when you want a handle before the model call finishes. End it only after the provider returns or fails.
- TypeScript
- Python
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:- TypeScript
- Python
Next steps
Tool calls
Record tool arguments and results.
Spans
Trace retrieval, ranking, and app logic.