Traceway
API Reference

Spans

REST API endpoints for managing spans.

Create a span

POST /api/spans
{
  "trace_id": "01J...",
  "parent_id": null,
  "name": "gpt-4o",
  "kind": {
    "type": "llm_call",
    "model": "gpt-4o",
    "provider": "openai"
  },
  "input": [
    { "role": "user", "content": "What is 2+2?" }
  ]
}

trace_id and name are required. kind determines the span type. parent_id nests this span under another.

Response:

{
  "id": "01J...",
  "trace_id": "01J..."
}

The span starts in running status.

Complete a span

POST /api/spans/:span_id/complete
{
  "output": {
    "text": "4",
    "finish_reason": "stop"
  },
  "kind": {
    "type": "llm_call",
    "model": "gpt-4o",
    "provider": "openai",
    "input_tokens": 12,
    "output_tokens": 1
  }
}

Both fields are optional. Passing kind updates the span kind (useful to fill in token counts after the LLM responds). Returns 200 on success. Returns 409 if the span is already completed or failed.

Fail a span

POST /api/spans/:span_id/fail
{
  "error": "API returned HTTP 500"
}

Marks the span as failed with the given error message. Returns 200.

List spans

GET /api/spans

Supports extensive filtering via query parameters:

ParamTypeDescription
trace_idstringFilter to a specific trace
kindstringFilter by kind type (llm_call, custom, etc.)
modelstringFilter by model name
providerstringFilter by provider
statusstringrunning, completed, or failed
sinceISO 8601Spans started after this time
untilISO 8601Spans started before this time
name_containsstringSubstring match on span name
text_containsstringFull-text search across input and output
input_containsstringSearch within input only
output_containsstringSearch within output only
duration_minnumberMinimum duration in ms
duration_maxnumberMaximum duration in ms
tokens_minnumberMinimum total tokens
cost_minnumberMinimum cost in dollars
sort_bystringstarted_at, duration, tokens, cost, name
sort_orderstringasc or desc (default: desc)
limitnumberMax results (default 50, max 1000)
cursorstringPagination cursor

Example:

curl "https://api.traceway.ai/api/spans?model=gpt-4o&status=completed&sort_by=cost&sort_order=desc&limit=10" \
  -H "Authorization: Bearer tw_sk_..."

Get a span

GET /api/spans/:span_id

Returns the full span object.

Delete a span

DELETE /api/spans/:span_id

Returns 200 on success, 404 if not found.

On this page