Skip to main content

Traces API

Read-side endpoints for traces, spans, and the timeline view.

GET /v1/traces

List traces for the active org.

Query parameters

ParamTypeDefaultNotes
limitint50Max 200
offsetint0
cursorstringCursor mode (overrides offset if set)
agent_idstringFilter by agent
outcomestringsuccess | error | timeout
min_duration_msint
max_duration_msint
sinceISO-8601
untilISO-8601
searchstringFull-text over prompts and responses
tagsstring[]Any-match

Response

{
"data": [
{
"trace_id": "trc_abc123",
"root_span_name": "checkout",
"agent_id": "agent_checkout_v2",
"outcome": "success",
"duration_ms": 1820,
"input_tokens": 1240,
"output_tokens": 410,
"cost_usd": 0.0023,
"started_at": "2026-06-19T10:30:00Z",
"ended_at": "2026-06-19T10:30:01.820Z",
"tags": ["prod", "checkout"]
}
],
"meta": {
"api_version": "1.7.0",
"request_id": "req_...",
"total": 1234,
"page": 1,
"per_page": 50
}
}

GET /v1/traces/{trace_id}/tree

The full span tree for a trace, ordered by parent_span_id then start_time. Used by the portal's Timeline tab.

{
"data": {
"trace_id": "trc_abc123",
"root_span_id": "spn_root",
"spans": [
{
"span_id": "spn_root",
"parent_span_id": null,
"name": "checkout",
"source_format": "openai",
"model": "gpt-4o-mini",
"outcome": "success",
"duration_ms": 1820,
"input_tokens": 1240,
"output_tokens": 410,
"cost_usd": 0.0023,
"started_at": "2026-06-19T10:30:00Z",
"ended_at": "2026-06-19T10:30:01.820Z",
"attributes": { "user_id": "u_abc" },
"tags": ["prod"],
"children": ["spn_llm_1", "spn_tool_1"]
},
{
"span_id": "spn_llm_1",
"parent_span_id": "spn_root",
"name": "openai.chat.completions",
"model": "gpt-4o-mini",
"outcome": "success",
"duration_ms": 920,
"input_tokens": 1240,
"output_tokens": 180,
"cost_usd": 0.0009,
"prompt": "You are a checkout assistant...",
"response": "Confirmed — order #ord_abc is on its way.",
"started_at": "2026-06-19T10:30:00.100Z"
}
]
}
}

The tree is bounded to 1000 spans by default. Larger traces use POST /v1/traces/{trace_id}/export to get the full dataset.

GET /v1/traces/{trace_id}/timeline

Same data as /tree but flattened for the portal's Gantt view:

{
"data": {
"trace_id": "trc_abc123",
"tracks": [
{
"label": "LLM calls",
"events": [
{
"span_id": "spn_llm_1",
"name": "openai.chat.completions",
"start_ms": 100,
"end_ms": 1020,
"model": "gpt-4o-mini"
}
]
},
{
"label": "Tool calls",
"events": [
{
"span_id": "spn_tool_1",
"name": "stripe.create_charge",
"start_ms": 1100,
"end_ms": 1750,
"outcome": "success"
}
]
}
]
}
}

POST /v1/traces/{trace_id}/export

Export a trace (and all its spans) as a single JSON or NDJSON document. Used by the portal's Export button and by the golden-dataset pipeline.

Request

{
"format": "ndjson", // "json" | "ndjson"
"include_prompts": true,
"include_responses": true,
"anonymize_pii": false // apply the org's PII policy before exporting
}

Response

200 OK with the file as application/x-ndjson (or application/json).

GET /v1/spans/search

Full-text + structured search across all spans (not just root spans). Use this when you want to find a specific prompt or response across traces.

Query parameters

ParamTypeNotes
qstringBM25 search over prompt + response
modelstringFilter by model
outcomestringsuccess | error | timeout
min_cost_usdfloat
max_cost_usdfloat
sinceISO-8601
limitintDefault 50

Response

{
"data": [
{
"span_id": "spn_...",
"trace_id": "trc_...",
"prompt": "...",
"response": "...",
"model": "gpt-4o-mini",
"score": 0.87
}
],
"meta": { "...": "..." }
}

POST /v1/traces/compare

Compare two traces side-by-side (used by the portal's regression review workflow):

{
"baseline_trace_id": "trc_abc",
"candidate_trace_id": "trc_def",
"fields": ["duration_ms", "cost_usd", "outcome", "judge_score"]
}

Response highlights any field where the candidate differs from baseline by more than the configured threshold.

Replay

POST /v1/traces/{trace_id}/replay re-runs the trace against the current prompt registry (dry-run by default, unless you pass commit: true). See Time-Travel Debug for the full replay semantics.

Errors

StatusCodeCause
404trace_not_foundUnknown trace id
403cross_org_accessTrace belongs to a different org
422replay_failedThe replay diverged (e.g. upstream model is gone)