Skip to navigation

Spend limits

A Meadow API key can carry a limit in US dollars, called limit. It covers the model calls and the sandboxes made with that key and with every key created from it. When the limit is spent, new model calls and new sandboxes are rejected with a 402 until the limit resets or you raise it.

Next step: set limit on the key you hand to a job or a customer, send an output token limit on every model request that key makes, and route its calls to providers Meadow has prices for.

On the hosted beta since 2026-11-28. A key with a limit was created and read back on the hosted beta that day: Authentication shows the key object. Nothing else on this page was run against the hosted beta: the rest is read from the server’s code and its tests, so no other output is shown.

Set a limit

limit is a number of US dollars. Set it when you create a key, or later with PATCH /v1/keys/{key_id}. Both need an admin key.

curl -sS -X POST "$MEADOW_BASE_URL/v1/keys" \
-H "Authorization: Bearer $MEADOW_API_KEY" \
-H "Content-Type: application/json" \
-d '{"project_id": "'"$PROJECT_ID"'", "name": "batch-job", "scopes": ["models"], "limit": 25, "limit_reset": "monthly"}'
curl -sS -X PATCH "$MEADOW_BASE_URL/v1/keys/$KEY_ID" \
-H "Authorization: Bearer $MEADOW_API_KEY" \
-H "Content-Type: application/json" \
-d '{"limit": 50}'

Things to know before you rely on it:

  • Write limit as a plain JSON number, at least 0 and below 10^12, with at most 12 decimal places. Meadow reads the digits as you wrote them, so 0.1 is one tenth exactly. A value with more decimal places, a negative number or a string returns 400.
  • "limit": null removes the limit.
  • limit_reset (daily, weekly, monthly) sets when the dollars go back to zero. It is the same field, with the same UTC clock, that resets max_requests and max_tokens. See Token and request limits. Without it the limit covers the key’s whole life.
  • The names limit, usage, limit_remaining and limit_reset are the ones OpenRouter uses on its keys.

Read what is spent

GET /v1/key returns the calling key. Any key can call it. Three fields are about dollars:

FieldMeaning
limitThe key’s own limit, or null.
usageDollars charged to the key in its current period, the keys created from it included. Null when neither the key nor a key above it has a limit.
limit_remainingWhat the key can still spend: the least of limit minus usage over the key and every key above it, never below 0. Null when none of them has a limit.

Dollars held by calls that are still running are not subtracted from limit_remaining, so a call can be rejected while it is above 0.

Meadow counts dollars against a key only while a limit applies to it. A key that was in use before you set a limit starts at usage 0. For what any key has spent, with or without a limit, read Usage and cost.

How a model call is checked

Meadow cannot know what a call costs until the provider answers. So it holds an amount before the call and charges the real cost after it.

  1. Before the call, Meadow works out the most the call can cost: its estimated tokens (the request size plus your output token limit) at the highest price the model has. That amount is held against the limit of the key and of every key above it.
  2. If a limit in that chain is already spent, or the held amount does not fit in what is left, the call is rejected with a 402. No provider is called and nothing is charged.
  3. When the call ends, Meadow charges what it cost, from the tokens the provider reported, and gives back the rest of the held amount. The charge is the cost of the call’s usage record.
  4. A streamed call keeps its amount held until the stream ends.

Because of step 1, a key with a limit, or under a key with one, must send an output token limit on every model request: max_completion_tokens or max_tokens on Chat Completions, max_output_tokens on Responses, max_tokens on Messages, generationConfig.maxOutputTokens on the Gemini route. A request without one returns 400.

The limit can be passed by one call

The held amount is a ceiling on the tokens of the call. The real cost can still be higher, for example when the provider bills a web search. That call is served in full and charged in full, so usage can end above limit. Every call after it is rejected. Leave headroom if you must never pass the amount.

When the real cost cannot be worked out, the whole held amount is charged. That happens when the provider reported no token counts, when a stream was cut, when you left before the response, when the provider answered with a model Meadow has no price for, when the call ran on a paid service tier Meadow has no price for, or when it asked for one and the provider did not say which tier served it. A request that asks for a service_tier Meadow has no price for is rejected before any provider is called (403 key_spend_price_unknown). The usage record of such a call has no cost, or an estimated one (cost_status price_estimated). The limit is charged the held amount in both cases, which is never less than that estimate. So usage on the key can be higher than the sum of the costs in Usage and cost. A budget with hard_limit counts the same way.

Providers without a price

A spend limit only works where Meadow knows the price before the call. Meadow holds prices for models served by anthropic, openai, google and xai, for the listed Claude models on bedrock, for the listed OpenAI models on an azure deployment stored as GlobalStandard, and for three fireworks models (accounts/fireworks/models/kimi-k3, glm-5p3 and glm-5p3-flash, at the Standard rate). It holds none for openrouter, vertex and deepseek, nor for other Azure deployment types. DeepSeek’s pricing page gives a peak and an off-peak price by the hour (UTC, weekdays, apart from Chinese public holidays), which Meadow does not price.

A key with a limit, or under a key with one, is rejected with 403 key_spend_price_unknown when the route of its call includes a model and provider with no price. The whole call is rejected, also when the provider without a price is only a fallback, and no provider is called. Send provider.only with providers that have prices, or set the project’s routing that way. On the Gemini route, which has no provider field, pin the provider in the path (google/<model>). See Routing and fallbacks.

Sandboxes

One limit covers model calls and sandboxes.

  • A sandbox create is rejected with the same 402 when a limit in the key’s chain is spent.
  • While a sandbox runs, its cost is charged to the key that created it and to every key above it, about once a minute.
  • That charge uses Meadow’s clock, which runs longer than the vendor’s. When Meadow reads the time the vendor billed, usually within minutes of the end, the difference is given back to the keys and budgets. It is not given back to a key or budget whose period reset since the charge.
  • When the limit is spent, sandboxes that are already running keep running. They end at their own timeout_seconds, or when you delete them.
  • To have Meadow stop them, set "limit_action": "stop_sandboxes" on the key that holds the limit. Within about a minute of the limit being spent, Meadow deletes every running sandbox made with that key or with a key created from it. It is the same delete as DELETE /v1/sandboxes/{sandbox_id}: the sandbox ends as terminated, its sandbox.terminated webhook event is sent, and work in it is lost. It is off unless you set it, and it acts only on the limit of the key it is set on.
  • A sandbox of a size or GPU class Meadow has no price for is not charged to the limit.

Child keys

A key created from a key with a limit does not need a limit of its own. Its spend is charged to it and to every key above it, so it can never spend more than the keys above it have left, and its limit_remaining shows that amount. When you do give it a limit, it cannot be higher than the parent key’s.

A rejection does not say which key in the chain ran out, unless it is the key you called with.

The rejection

A spent limit is a 402 with error.type insufficient_quota and error.code key_spend_limit_exceeded. On /v1/messages the body is in Anthropic’s envelope and the type is billing_error; the code is the same. There is no retry-after header. Do not retry it: raise the limit, wait for limit_reset_at, or lower the output token limit of the request.

It is a 402 and not a 429 so that a client that retries a 429 does not resend a call the key can never make. See Errors.

API reference

Operations on this page: createKey, updateKey, getCurrentKey, createChatCompletion, createSandbox.