Skip to main content

Overview

The update() method allows you to modify an existing trace after it has been created. This is useful when you need to add or update output, latency, token usage, or cost information.

Parameters

string
required
The ID of the trace to update.

Output Fields

string
The generated output or response from the AI model.
string
The input text or prompt for the trace.
string
The context retrieved by a RAG system, if applicable.
When you set retrieval_context, Galtea also records it as a RETRIEVER span on this trace. Sending null (or an empty string) clears the value and removes that span.

Performance Fields

float
The time in milliseconds from request to response.

Usage Fields

int
Number of input tokens sent to the model.
int
Number of output tokens generated by the model.
int
Number of input tokens read from the cache.
int
Total tokens used in the model call.

Cost Fields

float
The total cost associated with the model call.
float
Cost per input token sent to the model.
float
Cost per output token generated by the model.
float
Cost per input token read from the cache.

Returns

Returns the updated Trace object.

Example

Use Cases

Deferred Output Update

Create a trace first, then update it after processing completes:

Adding Cost Information

Update a trace with cost data after receiving billing info:

Notes

All fields except trace_id default to PydanticUndefined (from pydantic_core). Omit a field (or pass PydanticUndefined) to leave it unchanged. Pass None to explicitly clear an optional field. Pass a value to update it.
  • The creditsUsed field cannot be modified through this method