Ingest spans from traces

Ingest trace data as spans. This endpoint allows you to convert trace data into span format for storage and analysis using the **universal input/output design**. ## Universal input/output support This endpoint accepts spans with: - **`input`**: Any JSON-serializable structure (string, object, array) - **`output`**: Any JSON-serializable structure (string, object, array) - **`log_type`**: Determines how input/output are interpreted (`"chat"`, `"embedding"`, `"workflow"`, `"task"`, etc.) The system automatically extracts type-specific fields based on the `log_type`. See [span types](/documentation/resources/reference/data-model#log-types) for complete specifications and the [Create span documentation](/api-reference/observe/logs/create-span) for all field details. ## Authentication All endpoints require API key authentication: ```bash Authorization: Bearer YOUR_API_KEY ``` ## Request body The request body should be an array of log objects. Each log object should contain trace and span information. ```json Chat Log [ { "id": "log_id_123", "log_type": "chat", "trace_unique_id": "trace_abc123", "span_unique_id": "span_xyz789", "span_name": "llm_call", "span_parent_id": null, "span_workflow_name": "customer_support", "input": "[{\"role\":\"user\",\"content\":\"Hello\"}]", "output": "{\"role\":\"assistant\",\"content\":\"Hi! How can I help?\"}", "model": "gpt-4o-mini", "usage": { "prompt_tokens": 10, "completion_tokens": 8, "total_tokens": 18 }, "timestamp": "2024-01-15T10:30:00Z", "start_time": "2024-01-15T10:29:50Z", "latency": 1.2, "status": "success" } ] ``` ```json Workflow Log [ { "id": "workflow_log_456", "log_type": "workflow", "trace_unique_id": "trace_abc123", "span_unique_id": "span_workflow_001", "span_name": "customer_support_workflow", "span_parent_id": null, "span_workflow_name": "customer_support", "input": "{\"customer_query\":\"Order status?\",\"customer_id\":\"cust_123\"}", "output": "{\"status\":\"resolved\",\"result\":\"Order shipped\",\"steps\":5}", "timestamp": "2024-01-15T10:30:00Z", "start_time": "2024-01-15T10:29:50Z", "latency": 3.5, "status": "success" } ] ``` ```json Task Log [ { "id": "task_log_789", "log_type": "task", "trace_unique_id": "trace_abc123", "span_unique_id": "span_task_002", "span_name": "fetch_order_details", "span_parent_id": "span_workflow_001", "span_workflow_name": "customer_support", "input": "{\"order_id\":\"order_12345\"}", "output": "{\"order_id\":\"order_12345\",\"status\":\"shipped\",\"tracking\":\"TRACK123\"}", "timestamp": "2024-01-15T10:29:55Z", "start_time": "2024-01-15T10:29:54Z", "latency": 0.8, "status": "success" } ] ``` ## Examples ```python Python - Chat Log url = "https://api.respan.ai/api/traces/ingest/" headers = { "Authorization": "Bearer YOUR_API_KEY", "Content-Type": "application/json" } logs = [ { "id": "log_id_123", "log_type": "chat", "trace_unique_id": "trace_abc123", "span_unique_id": "span_xyz789", "span_name": "llm_call", "span_workflow_name": "customer_support", "input": '[{"role":"user","content":"Hello"}]', "output": '{"role":"assistant","content":"Hi! How can I help?"}', "model": "gpt-4o-mini", "usage": { "prompt_tokens": 10, "completion_tokens": 8, "total_tokens": 18 }, "timestamp": "2024-01-15T10:30:00Z", "start_time": "2024-01-15T10:29:50Z", "latency": 1.2 } ] response = requests.post(url, headers=headers, json=logs) print(response.json()) ``` ```python Python - Workflow with Tasks url = "https://api.respan.ai/api/traces/ingest/" headers = { "Authorization": "Bearer YOUR_API_KEY", "Content-Type": "application/json" } # Ingest a workflow with child tasks logs = [ # Parent workflow { "id": "workflow_log_001", "log_type": "workflow", "trace_unique_id": "trace_abc123", "span_unique_id": "span_workflow_001", "span_name": "customer_support_workflow", "span_parent_id": None, "span_workflow_name": "customer_support", "input": '{"customer_query":"Order status?","customer_id":"cust_123"}', "output": '{"status":"resolved","result":"Order shipped","steps":5}', "timestamp": "2024-01-15T10:30:00Z", "start_time": "2024-01-15T10:29:50Z", "latency": 3.5 }, # Child task { "id": "task_log_002", "log_type": "task", "trace_unique_id": "trace_abc123", "span_unique_id": "span_task_002", "span_name": "fetch_order_details", "span_parent_id": "span_workflow_001", "span_workflow_name": "customer_support", "input": '{"order_id":"order_12345"}', "output": '{"order_id":"order_12345","status":"shipped","tracking":"TRACK123"}', "timestamp": "2024-01-15T10:29:55Z", "start_time": "2024-01-15T10:29:54Z", "latency": 0.8 } ] response = requests.post(url, headers=headers, json=logs) print(response.json()) ``` ```bash cURL - Chat Log curl -X POST "https://api.respan.ai/api/traces/ingest/" \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '[{ "id": "log_id_123", "log_type": "chat", "trace_unique_id": "trace_abc123", "span_unique_id": "span_xyz789", "span_name": "llm_call", "span_workflow_name": "customer_support", "input": "[{\"role\":\"user\",\"content\":\"Hello\"}]", "output": "{\"role\":\"assistant\",\"content\":\"Hi! How can I help?\"}", "model": "gpt-4o-mini", "usage": { "prompt_tokens": 10, "completion_tokens": 8, "total_tokens": 18 }, "timestamp": "2024-01-15T10:30:00Z", "start_time": "2024-01-15T10:29:50Z", "latency": 1.2 }]' ``` ```bash cURL - Workflow Log curl -X POST "https://api.respan.ai/api/traces/ingest/" \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '[{ "id": "workflow_log_001", "log_type": "workflow", "trace_unique_id": "trace_abc123", "span_unique_id": "span_workflow_001", "span_name": "customer_support_workflow", "span_workflow_name": "customer_support", "input": "{\"customer_query\":\"Order status?\",\"customer_id\":\"cust_123\"}", "output": "{\"status\":\"resolved\",\"result\":\"Order shipped\",\"steps\":5}", "timestamp": "2024-01-15T10:30:00Z", "start_time": "2024-01-15T10:29:50Z", "latency": 3.5 }]' ``` ## Response ```json 200 OK { "success": true, "ingested_count": 1 } ```

Authentication

AuthorizationBearer
API key authentication. Get your API key from https://platform.respan.ai/platform/api-keys

Request

This endpoint expects an object.

Response

Successful response for Ingest spans from traces

Errors

401
Unauthorized Error