Check Before Spending
ledger_check_spendAsk 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.
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 | |||