Track LLM token usage and cost per agent run
To track token usage and cost per agent run without routing your LLM calls through a proxy, record usage explicitly with run.usage.record(). Tidebase stores the records with the run, emits usage.recorded events, and summarizes them in Studio.
await run.usage.record({
kind: 'llm',
provider: 'openai',
model: 'gpt-4.1-mini',
label: 'draft-response',
inputTokens: 1200,
outputTokens: 420,
costUsd: 0.012
})
Tidebase is an open-source checkpoint layer for AI agents: wrap your steps, and failed runs resume from the last safe point — in your own Postgres, without moving execution into a new runtime.
Not just LLM tokens
The same ledger tracks any metered resource:
await run.usage.record({
kind: 'tool',
provider: 'internal-search',
quantity: 8,
unit: 'queries',
costUsd: 0.004
})
Why explicit recording instead of a proxy?
Tidebase deliberately does not sit between you and your model provider — no LLM gateway, no latency tax, no secrets custody, no provider lock-in to a proxy’s supported APIs. The tradeoff is one line of code per call you want metered. In exchange, usage lives in the same Postgres row as the run’s checkpoints, steps, and gates, so “what did this failed run cost before it died?” is one query — and a resumed run doesn’t re-pay for checkpointed steps, which you can verify in the ledger.
See also: Checkpointing in Postgres · Quickstart