Skip to main content
POST
https://api.keywordsai.co
/
api
/
traces
/
ingest
[
  {
    "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"
  }
]
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 for complete specifications and the Create Log documentation for all field details.

Authentication

All endpoints require API key authentication:
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.
[
  {
    "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"
  }
]

Examples

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())

Response

200 OK
{
  "success": true,
  "ingested_count": 1
}