Documentation
API Reference

API: Logs & Tracing

Flapjack REST API endpoints for viewing execution traces, span trees, and evaluations.

Query execution traces for agents and runners. Every agent turn and runner run produces a trace — a tree of spans capturing LLM calls, tool invocations, webhooks, and other operations.

List Traces

GET /api/logs

Returns a paginated list of traces for the caller's organization.

ParameterTypeDefaultDescription
limitinteger50Results per page (max 200)
cursorstringComposite cursor (<startedAt>|<traceId>) from a previous response's nextCursor
agent_iduuidFilter by agent
runner_iduuidFilter by runner
thread_iduuidFilter by thread
run_iduuidFilter by runner run
statusstringrunning, ok, or error
qstringSubstring search on trace name

Response:

{
  "traces": [
    {
      "id": "trace-uuid",
      "org_id": "org-uuid",
      "agent_id": "agent-uuid",
      "runner_id": null,
      "thread_id": "thread-uuid",
      "run_id": null,
      "session_id": "sess_abc",
      "user_id": "user_123",
      "name": "chat-turn",
      "status": "ok",
      "started_at": "2026-05-01T12:00:00Z",
      "ended_at": "2026-05-01T12:00:03Z",
      "duration_ms": 3000,
      "total_input_tokens": 1250,
      "total_output_tokens": 480,
      "total_cost_usd": 0.0234,
      "tags": ["production"],
      "span_count": 5,
      "error_count": 0,
      "llm_call_count": 1,
      "tool_call_count": 3
    }
  ],
  "nextCursor": "2026-05-01T12:00:00Z|trace-uuid"
}
# List recent traces for an agent
curl https://api.flapjack.dev/api/logs?agent_id=AGENT_ID&limit=20 \
  -H "Authorization: Bearer fj_live_..."

Get Trace Detail

GET /api/logs/{traceId}

Returns the full trace with its span tree and evaluations.

Response:

{
  "trace": {
    "id": "trace-uuid",
    "name": "chat-turn",
    "status": "ok",
    "started_at": "2026-05-01T12:00:00Z",
    "ended_at": "2026-05-01T12:00:03Z",
    "duration_ms": 3000,
    "total_input_tokens": 1250,
    "total_output_tokens": 480,
    "total_cost_usd": 0.0234,
    "tags": [],
    "metadata": {}
  },
  "spans": [
    {
      "id": "span-uuid",
      "trace_id": "trace-uuid",
      "parent_span_id": null,
      "kind": "agent",
      "name": "agent-turn",
      "status": "ok",
      "started_at": "2026-05-01T12:00:00Z",
      "ended_at": "2026-05-01T12:00:03Z",
      "duration_ms": 3000,
      "provider": "anthropic",
      "model": "claude-opus-4-7-20250430",
      "input_tokens": 1250,
      "output_tokens": 480,
      "cached_input_tokens": 800,
      "cost_usd": 0.0234,
      "input": { "messages": ["..."] },
      "output": { "content": "..." },
      "error": null,
      "attributes": {},
      "dotted_order": "1714564800000-span-uuid"
    }
  ],
  "evaluations": [
    {
      "id": "eval-uuid",
      "span_id": "span-uuid",
      "trace_id": "trace-uuid",
      "evaluator": "heuristic.regex",
      "evaluator_version": "1.0",
      "name": "contains_code",
      "score": 1.0,
      "label": "pass",
      "reason": "Response included a code block",
      "metadata": {},
      "created_at": "2026-05-01T12:00:04Z"
    }
  ]
}

Concepts

Traces

A trace is the root execution record — one per agent turn or runner run. It carries rollup fields (total_input_tokens, total_output_tokens, total_cost_usd) so list views render without aggregating spans.

Spans

Each operation within a trace is recorded as a span. Spans form a tree via parent_span_id. The dotted_order field (LangSmith-style) enables efficient tree sorting.

Span KindDescription
agentTop-level agent execution
runner_stepA single step in a runner pipeline
llmLLM inference call
toolCustom tool invocation
mcpMCP server tool call
webhookOutbound HTTP call
conditionConditional flow evaluation
embeddingEmbedding generation
guardrailGuardrail check
chainGrouped chain of operations

LLM spans include token counts (input_tokens, output_tokens, cached_input_tokens) and cost_usd. Payloads (input, output, error) are truncated to ~256 KB.

Evaluations

Evaluations are scores attached to spans — from heuristics, LLM judges, or human reviewers. Each evaluation has an evaluator identifier, a name, and an optional normalized score (0–1).

Retention

Traces are retained per org plan. The purge_logs_older_than() function handles cleanup (default: 30 days free, 90 days paid).


Next Steps

Docs last updated June 29, 2026