trace.recordGeneration() / trace.record_generation() after the model call completes.
Record a generation
- TypeScript
- Python
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
| Field | Attribute keys |
|---|---|
| Generation kind | Lemma generation marker |
| Prompt / input | input.value |
| Completion / output | output.value |
| Model | gen_ai.request.model, ai.model.id |
| Contract props | Native props such as llmInputMessages, llmInvocationParameters, and llmPromptTemplate; raw attributes for escape-hatch keys |
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.