Skip to main content
Glama

Track Agent Spend

ledger_track

Record a spend entry for an AI agent on any payment rail, with optional token counts.

Claiming a brand-new agent_id requires your workspace_key (get one via x402 at POST /v1/billing/x402 — no human, no login — or at /start). That first call mints an agent_secret and returns it in the response — save it, every later call for that same agent_id must pass it back (no workspace_key needed again) or the write is rejected. Amounts are capped at $100,000/entry and must be >= 0. If a budget is set for this agent, an entry that would cross the monthly/daily cap is blocked, not just logged. Caps here bind the AMOUNT YOU REPORT — a caller that lies to amount_cents lies to the cap. The only enforcement against real spend is routing the provider call through the /proxy/{provider} rail, which prices from the provider's own usage block. Include tokens_in/tokens_out + model on every LLM call so token burn shows up in the /v1/tokens report.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
railYespayment rail used — one of "mpp", "x402", "api_key", "manual"
modelNomodel name (e.g. "gpt-4o") — token burn is reported per model
serviceYeswhat was purchased (e.g. "search_query", "data_export")
agent_idYesunique agent identifier (e.g. "research-agent-v2")
tokens_inNoprompt tokens consumed (0 if unknown)
tokens_outNocompletion tokens consumed (0 if unknown)
agent_secretNorequired for every call after the first for this agent_id
amount_centsYesspend amount in cents (100 = $1.00), 0-10000000
workspace_keyNorequired when claiming a brand-new agent_id; not needed once the agent_id has been claimed

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed1 schema field changed
    • addedInput schema / properties / workspace_key
      Added value: +{
      +  "default": "",
      +  "description": "required when claiming a brand-new agent_id; not\n           needed once the agent_id has been claimed",
      +  "type": "string"
      +}
  2. Changed2 schema fields changed
    • addedInput schema / properties / agent_secret
      Added value: +{
      +  "default": "",
      +  "description": "required for every call after the first for this agent_id",
      +  "type": "string"
      +}
    • changedInput schema / properties / amount_cents / description
      Previous value: -"spend amount in cents (100 = $1.00)"New value: +"spend amount in cents (100 = $1.00), 0-10000000"
  3. Changed3 schema fields changed
    • addedInput schema / properties / model
      Added value: +{
      +  "default": "",
      +  "description": "model name (e.g. \"gpt-4o\") — token burn is reported per model",
      +  "type": "string"
      +}
    • addedInput schema / properties / tokens_in
      Added value: +{
      +  "default": 0,
      +  "description": "prompt tokens consumed (0 if unknown)",
      +  "type": "integer"
      +}
    • addedInput schema / properties / tokens_out
      Added value: +{
      +  "default": 0,
      +  "description": "completion tokens consumed (0 if unknown)",
      +  "type": "integer"
      +}
  4. Changed2 schema fields changed
    • changedInput schema / properties / agent_id / description
      Previous value: -"unique agent identifier"New value: +"unique agent identifier (e.g. \"research-agent-v2\")"
    • changedInput schema / properties / rail / description
      Previous value: -"payment rail used (\"mpp\", \"x402\", \"api_key\", \"manual\")"New value: +"payment rail used — one of \"mpp\", \"x402\", \"api_key\", \"manual\""
  5. First observed

TDQS

A4.6/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations only say write, non-idempotent, non-destructive; the description goes far beyond by disclosing the agent_secret minting/auth flow, the $100,000/entry cap, that over-cap entries are blocked rather than logged, and the critical caveat that caps bind the reported amount while only /proxy/{provider} enforces real spend. This is exactly the behavioral context annotations cannot carry.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The core action is front-loaded in the first sentence, then the auth and cap mechanics follow in tight paragraphs with no filler. It is dense and long for a single tool, and a few clauses (e.g. the /start aside) could be trimmed, so a 4 rather than 5.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a 9-parameter authenticated write tool with an output schema present, the description covers the full call lifecycle: claiming, subsequent auth, caps, blocking behavior, and trust limitations. Nothing an agent needs to invoke it correctly is missing; return values are legitimately left to the output schema.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so baseline is 3, but the description adds meaning on top: why agent_secret/workspace_key exist, the conditional requirement per call, and the reporting purpose of tokens_in/tokens_out + model. That genuine added value over the schema justifies a 4 rather than the baseline 3.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

States a specific verb and resource ('Record a spend entry for an AI agent') plus the scope of rails accepted and optional token counts. An agent can immediately distinguish this write-oriented tracking tool from read-side siblings like ledger_check_spend and ledger_report.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Gives concrete conditions: workspace_key is needed only for claiming a brand-new agent_id, agent_secret is needed for every later call, and tokens/model should be included on every LLM call. It also routes real-enforcement users toward /proxy/{provider}. It stops short of explicitly contrasting this tool against the closest siblings (e.g. ledger_check_spend, ledger_report), which keeps it off a 5.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Try in Browser

Glama MCP Gateway

Add one secure layer between your agents and this server.