Check Before Spending
ledger_check_spendChecks whether an agent may spend a given amount or token budget right now, returning allowed or denied with a reason code, cost estimate and remaining budget before any spend occurs.
Instructions
Ask BEFORE you spend: may this agent spend this much right now?
Returns allowed (true/false), a stable reason code (within_budget, over_monthly_cap, over_daily_cap, over_monthly_token_cap, over_daily_token_cap, no_budget_set, unpriced_model), a one-line message, the cost estimate, the price used (with its source and as_of date) and every budget window with cap, spent and remaining.
Same decision the /proxy/{provider} gate enforces. Read-only: nothing is recorded or reserved, so record the spend with ledger_track afterwards.
Give exactly one spend shape: amount_cents (any rail, e.g. an x402 purchase), OR model with tokens_in/tokens_out.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"agent_id": "<agent_id>"
},
"name": "ledger_check_spend"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| model | No | model id to price from tokens (instead of amount_cents) | |
| agent_id | Yes | the agent that would spend | |
| tokens_in | No | expected input tokens (with model) | |
| tokens_out | No | expected output tokens, e.g. your max_tokens (with model) | |
| agent_secret | No | the agent's own secret (either this or workspace_key) | |
| amount_cents | No | the spend in cents, if you already know it | |
| workspace_key | No | the owning workspace's key (either this or agent_secret) |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||