Skip to navigation

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.

curl -sS -X PUT "$MEADOW_BASE_URL/v1/budget" \
-H "Authorization: Bearer $MEADOW_API_KEY" \
-H "Content-Type: application/json" \
-d '{"limit_usd": 500, "reset_interval": "monthly", "alert_thresholds": [50, 75, 100], "notification_channel": {"type": "email", "recipients": ["ops@example.com"]}}'
curl -sS -X PUT "$MEADOW_BASE_URL/v1/projects/$PROJECT_ID/budget" \
-H "Authorization: Bearer $MEADOW_API_KEY" \
-H "Content-Type: application/json" \
-d '{"limit_usd": 50, "reset_interval": "daily"}'
FieldMeaning
limit_usdThe amount to watch in one window. A plain JSON number above 0, with at most 12 decimal places.
reset_intervaldaily, weekly or monthly. Windows start at midnight UTC, on Monday at midnight UTC, or on the first of the month at midnight UTC.
alert_thresholdsPercentages of limit_usd, whole numbers from 1 to 100. Left out, they are 50, 75 and 100. An empty list sends no alerts.
notification_channel{"type": "email", "recipients": [...]} with up to 20 addresses. Left out or null, no email is sent.

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’s webhook_url. The account’s budget sends it to the webhook_url of every project that has one. A project with no webhook_url gets 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:

{
"id": "evt_000059aa",
"type": "budget.threshold_crossed",
"created_at": "2026-11-28T09:15:00Z",
"threshold": 75,
"budget": {
"id": "bud_000029c9",
"object": "budget",
"scope": "account",
"project_id": null,
"limit_usd": 500,
"reset_interval": "monthly",
"alert_thresholds": [50, 75, 100],
"spend_usd": 376.12,
"remaining_usd": 123.88,
"resets_at": "2026-12-01T00:00:00Z",
"unknown_cost_records": 0
}
}

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.

curl -sS -X PUT "$MEADOW_BASE_URL/v1/projects/$PROJECT_ID/budget" \
-H "Authorization: Bearer $MEADOW_API_KEY" \
-H "Content-Type: application/json" \
-d '{"limit_usd": 500, "reset_interval": "monthly", "hard_limit": true}'

Once the dollars counted for the budget reach limit_usd:

  • Model calls in its scope are rejected with 402 and error.code budget_exceeded. The type is insufficient_quota on OpenAI-format routes and billing_error on /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/sandboxes is 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, switch hard_limit off, or wait for resets_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, or generationConfig.maxOutputTokens on 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 403 key_spend_price_unknown. Send provider.only with priced providers, or on the Gemini route pin the provider in the path.

How it counts:

  • enforced_spend_usd on the budget is the number the 402 is decided on. It is null on a budget without hard_limit.
  • When you switch hard_limit on, the count starts at the window’s spend_usd so 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_usd can be above spend_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 before resets_at and 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 GET on the budget.
  • A PUT replaces the whole budget. Leave hard_limit out and it is false again.
  • Calls that were in flight at the moment you switched hard_limit on 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_limit does not stop anything. Spend can pass limit_usd, and remaining_usd then 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_records counts them. When it is above 0, you were billed more than spend_usd. See Usage and cost.
  • spend_usd is the sum of the usage records. usage on a key with a limit is 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.