Budgets and alerts
A budget tracks spend in US dollars for one project or the whole account. It sends webhook and email alerts when spend reaches a threshold. By default, a budget only sends alerts. Enable hard_limit to block spend at the budget amount. See Stop at the limit for enforcement and exceptions.
To limit spend on one key, set its limit field. See Spend limits.
Next step: set a budget on the account with the thresholds you want, and point a project’s webhook_url at a receiver.
On the hosted beta since 2026-11-28. Nothing on this page was run against the hosted beta: the behavior is read from the server’s code and its tests, so no output is shown. Email is off on the hosted beta until a sender is set up there.
Set a budget
There is one budget per project and one for the account. PUT sets or replaces it. All six calls need an admin key.
GET returns the budget with spend_usd, remaining_usd, resets_at and unknown_cost_records. DELETE removes it. Both return 404 budget_not_found when none is set.
What an alert is
When spend in the current window first reaches a threshold, Meadow sends:
- One webhook event,
budget.threshold_crossed. A project’s budget sends it to that project’swebhook_url. The account’s budget sends it to thewebhook_urlof every project that has one. A project with nowebhook_urlgets nothing. - One email to the budget’s recipients, when it has any.
Each threshold alerts once per window. In the next window it can alert again.
The webhook body:
This body is written from the API contract, not captured from a delivery. It is signed and retried like a sandbox event: see Webhooks. Your receiver should branch on type, because sandbox events arrive at the same address.
Stop at the limit
Send "hard_limit": true and limit_usd becomes a ceiling for the window, for the project or for the whole account.
Once the dollars counted for the budget reach limit_usd:
- Model calls in its scope are rejected with 402 and
error.codebudget_exceeded. The type isinsufficient_quotaon OpenAI-format routes andbilling_erroron/v1/messages. No provider is called. - A model call is also rejected when the estimate Meadow holds for it does not fit what is left. Lower its output token limit.
POST /v1/sandboxesis rejected with the same 402. Sandboxes that are running keep running and keep costing. A hard budget does not stop them.- Do not retry a 402. Raise
limit_usd, switchhard_limitoff, or wait forresets_at.
A hard budget works like a dollar limit on every key in its scope, so the same two rules apply to those keys:
- A model call must send an output token limit (
max_tokens,max_completion_tokens,max_output_tokens, orgenerationConfig.maxOutputTokenson the Gemini route). - A route that includes a provider with no listed price (OpenRouter, Vertex, an Azure deployment not stored as
GlobalStandard, DeepSeek, a Bedrock model Meadow does not list, or a Fireworks model other than the three priced ones) is rejected with 403key_spend_price_unknown. Sendprovider.onlywith priced providers, or on the Gemini route pin the provider in the path.
How it counts:
enforced_spend_usdon the budget is the number the 402 is decided on. It is null on a budget withouthard_limit.- When you switch
hard_limiton, the count starts at the window’sspend_usdso far. A budget made hard on the 20th counts the month from the 1st. - Each model call adds what the key path charged for it: the cost in its usage record, or the held estimate when the cost could not be measured. So
enforced_spend_usdcan be abovespend_usd. - A running sandbox is added about once a minute, for the time since the last count.
- One call may end above the limit: a call is admitted when its estimate fits, and it is charged what it cost. Calls after it are rejected.
- The count goes back to 0 at
resets_at. A streamed call that began beforeresets_atand ended after it can be left out of the new window’s count. - The 402 names the budget (project or account) and not its totals. Read them with
GETon the budget. - A
PUTreplaces the whole budget. Leavehard_limitout and it is false again. - Calls that were in flight at the moment you switched
hard_limiton are counted only if their key already had a spend limit above it.
An account budget and a project budget can both be hard. A call must fit both.
Things to know
- A budget without
hard_limitdoes not stop anything. Spend can passlimit_usd, andremaining_usdthen goes below 0. - Spend is read from the usage records about once a minute, so an alert can be about a minute late.
- Records with no cost are left out of
spend_usd: calls through a provider Meadow has no price for, calls whose tokens were estimated, and sandboxes with no price.unknown_cost_recordscounts them. When it is above 0, you were billed more thanspend_usd. See Usage and cost. spend_usdis the sum of the usage records.usageon a key with alimitis a different counter and can be higher.- Replacing a budget does not repeat alerts for thresholds already crossed in the current window. Deleting it and setting it again does.
- An alert sent while email was not set up on the server is not emailed later.
API reference
Operations on this page: getAccountBudget, putAccountBudget, deleteAccountBudget, getProjectBudget, putProjectBudget, deleteProjectBudget.