> ## Documentation Index
> Fetch the complete documentation index at: https://docs.keywordsai.co/llms.txt
> Use this file to discover all available pages before exploring further.

# Ingest Logs from traces

Ingest trace data as logs. This endpoint allows you to convert trace data into log format for storage and analysis using the **universal input/output design**.

## Universal input/output support

This endpoint accepts logs 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 [log types](/get-started/observability_data_model#log-types) for complete specifications and the [Create Log documentation](/api-endpoints/observe/logs/request-logging-endpoint) for all field details.

## Authentication

All endpoints require API key authentication:

```bash theme={"system"}
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.

<RequestExample>
  ```json Chat Log theme={"system"}
  [
    {
      "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 theme={"system"}
  [
    {
      "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 theme={"system"}
  [
    {
      "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"
    }
  ]
  ```
</RequestExample>

## Examples

<CodeGroup>
  ```python Python - Chat Log theme={"system"}
  import requests

  url = "https://api.keywordsai.co/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 theme={"system"}
  import requests

  url = "https://api.keywordsai.co/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 theme={"system"}
  curl -X POST "https://api.keywordsai.co/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 theme={"system"}
  curl -X POST "https://api.keywordsai.co/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
    }]'
  ```
</CodeGroup>

## Response

```json 200 OK theme={"system"}
{
  "success": true,
  "ingested_count": 1
}
```
