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. 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 cover write/safety hints; the description adds rich behavioral context beyond that: secret-minting on first claim, rejection of unauthenticated later writes, the $100,000 cap and >=0 constraint, and the crucial fact that budget-crossing entries are blocked, not just logged. This is exactly the extra context annotations can't 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?

Front-loaded with the core action, then groups auth, limits, and token guidance. There's some line-wrap noise and the x402/start detail is dense, but every sentence carries operational meaning.

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-param, 4-required mutation tool with an output schema, the description covers the auth lifecycle, limits, and blocking behavior that an agent must know before calling. Return-value shape is correctly 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 coverage is 100%, so baseline is 3, but the description adds cross-parameter workflow semantics the schema can't express: when workspace_key applies vs agent_secret, and the mandate to send tokens_in/tokens_out+model together. Enum values for rail are only in the schema, not the description.

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 (record a spend entry) and resource (agent spend on any payment rail), with the optional token dimension called out. It's clearly distinct from siblings like ledger_report or ledger_set_budget.

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 clear conditional guidance for when to pass workspace_key vs agent_secret, and instructs to include token counts on every LLM call. It doesn't explicitly name sibling alternatives (e.g., ledger_set_budget for caps), but the in-tool branching is well explained.

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.