Query traces
Changed onReturns a paginated list of traces (root runs) for a single tracing project. Each item carries the trace's root run plus optional trace-wide aggregates (total_tokens, total_cost, first_token_time) under trace_aggregates, so clients never have to merge by trace_id.
Traces are scanned within a start_time window: min_start_time defaults to 24 hours before the request, max_start_time defaults to the request time. Set either explicitly to widen or narrow the window.
Supports filters (trace_filter, tree_filter), cursor pagination (cursor), and field projection (selects).
When ai_search is set, Accept: text/event-stream is required; requests without it return 406. AI search is unavailable on deployments that route queries to the v1 backend and returns 501 there.
Self-hosted deployments require LangSmith v0.16 or later.
Request
- Base URLhttps://api.smith.langchain.com
- URLhttps://api.smith.langchain.com/api/v2/traces/query
- Auth
- API key in header X-API-Key and API key in header X-Tenant-Id
- or HTTP bearer and API key in header X-Tenant-Id
Headers
application/json, or text/event-stream (required when ai_search is set)
application/json (required for JSON body)
Request body
Example request
{
"ai_search": "A run that contains a billing dispute",
"max_feedback_modified_at": "2024-12-31T23:59:59Z",
"max_start_time": "2024-12-31T23:59:59Z",
"min_feedback_modified_at": "2024-01-01T00:00:00Z",
"min_start_time": "2024-01-01T00:00:00Z",
"page_size": 20,
"project_id": "018e4c7e-a9fb-7ef0-a5b6-6ea3a82e9327",
"selects": [
"ID",
"NAME",
"START_TIME",
"STATUS",
"TOTAL_TOKENS",
"TOTAL_COST",
"FIRST_TOKEN_TIME"
],
"trace_filter": "eq(status, \"error\")",
"tree_filter": "has(tags, \"production\")"
}Response
OK
Example response
{
"items": [
{
"root_run": {
"app_path": "/app/chains/chat.py:invoke",
"completion_cost": 0.0003,
"completion_tokens": 150,
"dotted_order": "20240115T103000000000Z018e4c7ea9fb7ef0a5b66ea3a82e9327.",
"end_time": "2024-01-15T10:30:01.500Z",
"error": "context deadline exceeded",
"events": [
{
"name": "new_token",
"time": "2024-01-15T10:30:00.312Z"
}
],
"first_token_time": "2024-01-15T10:30:00.312Z",
"id": "018e4c7e-a9fb-7ef0-a5b6-6ea3a82e9327",
"is_in_dataset": true,
"is_root": true,
"last_queued_at": "2024-01-15T10:31:00Z",
"latency_seconds": 1.523,
"ls_user_id": "f6a7b8c9-d0e1-4f2a-3b4c-5d6e7f8a9b0c",
"name": "ChatOpenAI",
"parent_run_ids": [
"018e4c7e-a9fb-7ef0-a5b6-6ea3a82e9327",
"a1b2c3d4-e5f6-4a5b-8c9d-0e1f2a3b4c5d"
],
"price_model_id": "e5f6a7b8-c9d0-4e1f-2a3b-4c5d6e7f8a9b",
"project_id": "018e4c7e-a9fb-7ef0-a5b6-6ea3a82e9327",
"prompt_cost": 0.0002,
"prompt_tokens": 200,
"reference_dataset_id": "c3d4e5f6-a7b8-4c5d-0e1f-2a3b4c5d6e7f",
"reference_example_id": "b2c3d4e5-f6a7-4b5c-9d0e-1f2a3b4c5d6e",
"share_url": "https://smith.langchain.com/public/4f7a1b2c-8d9e-4a0b-9c1d-2e3f4a5b6c7d/r",
"start_time": "2024-01-15T10:30:00.000Z",
"tags": [
"production",
"gpt-4"
],
"thread_id": "d4e5f6a7-b8c9-4d5e-1f2a-3b4c5d6e7f8a",
"total_cost": 0.000525,
"total_tokens": 350,
"trace_id": "018e4c7e-a9fb-7ef0-a5b6-6ea3a82e9327"
}
}
]
}Changes
- info
added the new optional request property
- info
added the new optional request property
- info
- info
endpoint added
- info