Run ledger API
This page documents the 2 gateway endpoints tagged run ledger in the gateway's OpenAPI document. Every example targets a gateway on http://localhost:4000 and authenticates with the SPANWAY_API_KEY environment variable, which holds the master key or a virtual key that has access to the route. Request and response fields are taken from the schema the running gateway publishes at /openapi.json, and the same document is bundled with this site as openapi.json.
| Method | Path | Summary |
|---|---|---|
| GET | /run_ledger/{run_id} | Read the ledger of one run, request, trace or session |
| GET | /run_ledger/{run_id}/export | Download the ledger as a JSON file |
Endpoints
GET /run_ledger/{run_id}
Read the ledger of one run, request, trace or session
Shows everything one run did, in time order with totals, so an operator can answer "what happened and what did it cost" in one place: every request, MCP and tool call, guardrail decision, audit row, eval score and shadow verdict recorded for a workflow run id or session id, an agent run (A2A request) id, a request id or a trace or session id. Any key with a user may call it; admins see every row and other callers only their own and their teams' rows. Read only, nothing changes.
kind says what the id resolved to, lens says whether agent trace spans were included, and truncated
is true when the ledger was cut at its row cap.
Docs (https://docs.spanway.ai/docs/proxy/run_ledger)
Parameters:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
run_id | path | string | Yes |
Example request:
curl -X GET "http://localhost:4000/run_ledger/run_id-123" \
-H "Authorization: Bearer $SPANWAY_API_KEY"
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | The ledger in time order with totals. | application/json RunLedger |
| 401 | No valid key or Admin UI session was presented | application/json ProxyError |
| 403 | The key has no user, so it may not read ledgers, or the ledger holds agent calls and the gateway has no license for agent_governance, which answers an error object instead of text. | application/json ErrorDetail |
| 404 | No run, request, trace or session has this id. | application/json ErrorDetail |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | The gateway has no database, so there are no rows to read. | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
id | string | Yes | Id |
kind | enum: "workflow_run", "agent_run", "trace", "session" | Yes | Kind |
session_ids | array of string | Yes | Session Ids |
workflow_run | WorkflowRunSummary or null | Yes | |
lens | enum: "included", "not_found", "unavailable" | Yes | Lens |
truncated | boolean | Yes | Truncated |
totals | RunLedgerTotals | Yes | |
entries | array of LedgerRequest or LedgerMcpCall or LedgerToolCall or LedgerGuardrail or LedgerAudit or LedgerWorkflowEvent or LedgerWorkflowAttempt or LedgerEvalScore or LedgerShadowVerdict or LedgerOnlineScore or LedgerTraceSpan | Yes | Entries |
GET /run_ledger/{run_id}/export
Download the ledger as a JSON file
Downloads the same ledger that GET /run_ledger/{run_id} returns as a JSON file attachment, for example to
attach to an incident ticket, with the same access rules. The file is named after the run id with unsafe
characters replaced by _. Read only, nothing changes.
Docs (https://docs.spanway.ai/docs/proxy/run_ledger)
Parameters:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
run_id | path | string | Yes |
Example request:
curl -X GET "http://localhost:4000/run_ledger/run_id-123/export" \
-H "Authorization: Bearer $SPANWAY_API_KEY"
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | The same ledger as a JSON file attachment named run-ledger-<run_id>.json. | application/json RunLedger |
| 401 | No valid key or Admin UI session was presented | application/json ProxyError |
| 403 | The key has no user, so it may not read ledgers, or the ledger holds agent calls and the gateway has no license for agent_governance, which answers an error object instead of text. | application/json ErrorDetail |
| 404 | No run, request, trace or session has this id. | application/json ErrorDetail |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | The gateway has no database, so there are no rows to read. | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
id | string | Yes | Id |
kind | enum: "workflow_run", "agent_run", "trace", "session" | Yes | Kind |
session_ids | array of string | Yes | Session Ids |
workflow_run | WorkflowRunSummary or null | Yes | |
lens | enum: "included", "not_found", "unavailable" | Yes | Lens |
truncated | boolean | Yes | Truncated |
totals | RunLedgerTotals | Yes | |
entries | array of LedgerRequest or LedgerMcpCall or LedgerToolCall or LedgerGuardrail or LedgerAudit or LedgerWorkflowEvent or LedgerWorkflowAttempt or LedgerEvalScore or LedgerShadowVerdict or LedgerOnlineScore or LedgerTraceSpan | Yes | Entries |