> For clean Markdown of any page, append .md to the page URL. > For a complete documentation index, see https://respan.ai/docs/apis/traces/get-trace/llms.txt. > For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://respan.ai/_mcp/server. # Get a trace GET https://api.respan.ai/api/traces/{trace_unique_id}/ Returns aggregate metrics and the full span tree. Metadata keys beginning with `_` are reserved for platform use and omitted from span and trace read responses. Reference: https://respan.ai/docs/apis/traces/get-trace ## Authentication - `Authorization` header (bearer token, required) — Use your Respan API key for Respan API authentication. Enter only the Respan API key value; clients send Authorization: Bearer \. For /api/responses, provider credentials such as Perplexity, OpenAI, or Azure OpenAI go in Settings -> Providers or respan\_params.credential\_override in the request body, not in this authentication field. - `Authorization` header (bearer token, required) — Use a dashboard JWT only for dashboard-authenticated endpoints. Respan API-key endpoints use the respanApiKey auth field instead. ## Request ### Path parameters - `trace_unique_id` (string, required) — Unique trace identifier. ## Response ### 200 Trace detail with span tree. - `id` (string, optional) — Trace identifier. - `trace_unique_id` (string, optional) — Unique trace identifier. - `root_span_unique_id` (string, optional) — Root span ID for the trace. - `unique_organization_id` (string, optional) — Organization unique ID. - `organization_id` (string, optional) — Alias of `unique_organization_id`. - `organization_name` (string, optional) — Organization name when available. - `organization_key_id` (string, optional) — API key identifier used to create the trace. - `environment` (string, optional) — Environment for the trace. - `customer_identifier` (string, optional) — Customer or user identifier. - `start_time` (datetime, optional) — When the trace started. - `end_time` (datetime, optional) — When the trace ended. - `duration` (double, optional) — Total duration in seconds. - `span_count` (integer, optional) — Total spans in the trace. - `llm_call_count` (integer, optional) — Number of LLM-call spans. - `total_cost` (double, optional) — Total cost in USD. - `total_prompt_tokens` (integer, optional) — Sum of prompt tokens. - `total_completion_tokens` (integer, optional) — Sum of completion tokens. - `total_tokens` (integer, optional) — Sum of all tokens. - `error_count` (integer, optional) — Number of error spans. - `name` (string, optional) — Root span name. - `input` (string, optional, nullable) — Root span input. API key responses may include full storage-enriched content. - `output` (string, optional, nullable) — Root span output. API key responses may include full storage-enriched content. - `metadata` (ApiTracesTraceUniqueIdGetResponsesContentApplicationJsonSchemaMetadata, optional) — Customer metadata. Keys beginning with `_` are reserved and omitted from customer-facing responses. - `trace_group_identifier` (string, optional) — Workflow or trace-group identifier. - `session_identifier` (string, optional) — Session identifier when present. - `model` (string, optional) — Primary/root model used. - `storage_object_key` (string, optional) — Storage object key for the root span payload when present. - `span_tree` (list of ApiTracesTraceUniqueIdGetResponsesContentApplicationJsonSchemaSpanTreeItems, optional) — Hierarchical span tree for the trace. ## Errors ### 403 Forbidden Error The API key is missing, invalid or expired. - `detail` (string, required) ### 404 Not Found Error Not Found - `detail` (string, optional) ### 429 Too Many Requests Error Rate Limited - `detail` (string, optional) ### 500 Internal Server Error Internal Server Error - `detail` (string, optional) ## Types ### ApiTracesTraceUniqueIdGetResponsesContentApplicationJsonSchemaMetadata Customer metadata. Keys beginning with `_` are reserved and omitted from customer-facing responses. ### ApiTracesTraceUniqueIdGetResponsesContentApplicationJsonSchemaSpanTreeItems - `id` (string, optional) — Span identifier. - `unique_id` (string, optional) — Underlying log unique ID. - `span_unique_id` (string, optional) — Unique span identifier within the trace. - `span_name` (string, optional) — Span name. - `span_parent_id` (string, optional, nullable) — Parent span ID. - `trace_unique_id` (string, optional) — Trace ID. - `customer_identifier` (string, optional) — Customer identifier. - `thread_identifier` (string, optional) — Thread identifier when present. - `session_identifier` (string, optional) — Session identifier when present. - `organization_key_id` (string, optional) — API key identifier. - `organization_id` (string, optional) — Organization unique ID. - `environment` (string, optional) — Environment. - `log_type` (string, optional) — Span/log type. - `timestamp` (datetime, optional) — Span end time. - `start_time` (datetime, optional) — Span start time. - `end_time` (datetime, optional) — Alias of `timestamp`. - `prompt_tokens` (integer, optional) — Prompt tokens for this span. - `completion_tokens` (integer, optional) — Completion tokens for this span. - `total_request_tokens` (integer, optional) — Total tokens for this span. - `cost` (double, optional) — Span cost in USD. - `model` (string, optional) — Model used by the span. - `latency` (double, optional) — Span duration in seconds. - `status_code` (integer, optional) — Status code recorded for the span. - `status` (string, optional) — Span status. - `input` (string, optional, nullable) — Span input. - `output` (string, optional, nullable) — Span output. - `metadata` (ApiTracesTraceUniqueIdGetResponsesContentApplicationJsonSchemaSpanTreeItemsMetadata, optional) — Customer metadata. Keys beginning with `_` are reserved and omitted from customer-facing responses. - `span_links` (string, optional) — Serialized OTEL span links when present. - `storage_object_key` (string, optional) — Backing storage object key when present. - `span_workflow_name` (string, optional) — Workflow name when present. - `children` (list of ApiTracesTraceUniqueIdGetResponsesContentApplicationJsonSchemaSpanTreeItemsChildrenItems, optional) — Nested child spans. ### ApiTracesTraceUniqueIdGetResponsesContentApplicationJsonSchemaSpanTreeItemsMetadata Customer metadata. Keys beginning with `_` are reserved and omitted from customer-facing responses. ### ApiTracesTraceUniqueIdGetResponsesContentApplicationJsonSchemaSpanTreeItemsChildrenItems ## Examples **Response** ```json { "id": "trace_abc123", "trace_unique_id": "trace_abc123", "root_span_unique_id": "span_root_123", "unique_organization_id": "org_xyz789", "organization_id": "org_xyz789", "organization_name": "Acme Inc", "environment": "prod", "customer_identifier": "user@example.com", "start_time": "2024-01-15T10:30:00Z", "end_time": "2024-01-15T10:30:02.500000Z", "duration": 2.5, "span_count": 3, "llm_call_count": 2, "total_cost": 0.00345, "total_prompt_tokens": 150, "total_completion_tokens": 75, "total_tokens": 225, "error_count": 0, "name": "chat_completion", "input": "[{\"role\": \"user\", \"content\": \"Explain quantum computing\"}]", "output": "{\"role\": \"assistant\", \"content\": \"Quantum computing is a revolutionary technology...\"}", "metadata": { "user_id": "user123" }, "trace_group_identifier": "workflow_v1", "session_identifier": "session456", "model": "gpt-4", "span_tree": [ { "id": "log_root_1", "unique_id": "log_root_1", "span_unique_id": "span_root_123", "span_name": "chat_completion", "span_parent_id": null, "trace_unique_id": "trace_abc123", "log_type": "chat", "timestamp": "2024-01-15T10:30:02Z", "start_time": "2024-01-15T10:30:00Z", "prompt_tokens": 50, "completion_tokens": 75, "cost": 0.00345, "model": "gpt-4", "latency": 2, "status_code": 200, "status": "success", "input": "[{\"role\": \"user\", \"content\": \"Explain quantum computing\"}]", "output": "{\"role\": \"assistant\", \"content\": \"Quantum computing is a revolutionary technology...\"}", "children": [] } ] } ``` **SDK Code** ```python Traces_retrieveTrace_example import requests url = "https://api.respan.ai/api/traces/trace_unique_id/" headers = {"Authorization": "Bearer "} response = requests.get(url, headers=headers) print(response.json()) ``` ```javascript Traces_retrieveTrace_example const url = 'https://api.respan.ai/api/traces/trace_unique_id/'; const options = {method: 'GET', headers: {Authorization: 'Bearer '}}; try { const response = await fetch(url, options); const data = await response.json(); console.log(data); } catch (error) { console.error(error); } ``` ```go Traces_retrieveTrace_example package main import ( "fmt" "net/http" "io" ) func main() { url := "https://api.respan.ai/api/traces/trace_unique_id/" req, _ := http.NewRequest("GET", url, nil) req.Header.Add("Authorization", "Bearer ") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` ```ruby Traces_retrieveTrace_example require 'uri' require 'net/http' url = URI("https://api.respan.ai/api/traces/trace_unique_id/") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Get.new(url) request["Authorization"] = 'Bearer ' response = http.request(request) puts response.read_body ``` ```java Traces_retrieveTrace_example import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.Unirest; HttpResponse response = Unirest.get("https://api.respan.ai/api/traces/trace_unique_id/") .header("Authorization", "Bearer ") .asString(); ``` ```php Traces_retrieveTrace_example request('GET', 'https://api.respan.ai/api/traces/trace_unique_id/', [ 'headers' => [ 'Authorization' => 'Bearer ', ], ]); echo $response->getBody(); ``` ```csharp Traces_retrieveTrace_example using RestSharp; var client = new RestClient("https://api.respan.ai/api/traces/trace_unique_id/"); var request = new RestRequest(Method.GET); request.AddHeader("Authorization", "Bearer "); IRestResponse response = client.Execute(request); ``` ```swift Traces_retrieveTrace_example import Foundation let headers = ["Authorization": "Bearer "] let request = NSMutableURLRequest(url: NSURL(string: "https://api.respan.ai/api/traces/trace_unique_id/")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "GET" request.allHTTPHeaderFields = headers let session = URLSession.shared let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error as Any) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } }) dataTask.resume() ```