Skip to main content

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.

MethodPathSummary
GET/run_ledger/{run_id}Read the ledger of one run, request, trace or session
GET/run_ledger/{run_id}/exportDownload 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:

NameInTypeRequiredDescription
run_idpathstringYes

Example request:

curl -X GET "http://localhost:4000/run_ledger/run_id-123" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200The ledger in time order with totals.application/json RunLedger
401No valid key or Admin UI session was presentedapplication/json ProxyError
403The 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
404No run, request, trace or session has this id.application/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500The gateway has no database, so there are no rows to read.application/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
idstringYesId
kindenum: "workflow_run", "agent_run", "trace", "session"YesKind
session_idsarray of stringYesSession Ids
workflow_runWorkflowRunSummary or nullYes
lensenum: "included", "not_found", "unavailable"YesLens
truncatedbooleanYesTruncated
totalsRunLedgerTotalsYes
entriesarray of LedgerRequest or LedgerMcpCall or LedgerToolCall or LedgerGuardrail or LedgerAudit or LedgerWorkflowEvent or LedgerWorkflowAttempt or LedgerEvalScore or LedgerShadowVerdict or LedgerOnlineScore or LedgerTraceSpanYesEntries

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:

NameInTypeRequiredDescription
run_idpathstringYes

Example request:

curl -X GET "http://localhost:4000/run_ledger/run_id-123/export" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200The same ledger as a JSON file attachment named run-ledger-<run_id>.json.application/json RunLedger
401No valid key or Admin UI session was presentedapplication/json ProxyError
403The 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
404No run, request, trace or session has this id.application/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500The gateway has no database, so there are no rows to read.application/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
idstringYesId
kindenum: "workflow_run", "agent_run", "trace", "session"YesKind
session_idsarray of stringYesSession Ids
workflow_runWorkflowRunSummary or nullYes
lensenum: "included", "not_found", "unavailable"YesLens
truncatedbooleanYesTruncated
totalsRunLedgerTotalsYes
entriesarray of LedgerRequest or LedgerMcpCall or LedgerToolCall or LedgerGuardrail or LedgerAudit or LedgerWorkflowEvent or LedgerWorkflowAttempt or LedgerEvalScore or LedgerShadowVerdict or LedgerOnlineScore or LedgerTraceSpanYesEntries