> For the list of every page, fetch /llms.txt. The API contract is the OpenAPI file linked from the API reference.

# Token and request limits

A Meadow API key can carry two limits: `max_requests` and `max_tokens`. Both are lifetime totals for that key unless you set `limit_reset`. When a key reaches a limit, raise that limit with `PATCH /v1/keys/{key_id}` or create a new one.

Next step: if you set `max_tokens` on a key, add an output token limit to every request that key makes. Without one the request is rejected.

A key can also carry a limit in US dollars, `limit`. See [Spend limits](/call-models/spend-limits).

Meadow also applies a maximum request size to every key. It sets no fixed number of requests in flight per key or per account: see [A busy server and retry-after](#the-in-flight-limit-and-retry-after).

## Set a limit

Limits are set when a key is created, with an admin key. [Authentication](/set-up-your-account/authentication#create-a-key) covers key creation in full.

```bash
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": "worker", "scopes": ["models"], "max_requests": 2, "max_tokens": 1000}'
```

```json
{"created_at":"2026-11-24T20:42:46.113Z","disabled":false,"expires_at":null,"id":"key_0000d5ee","last4":"-vBI","last_used_at":null,"limit_reset":null,"limit_reset_at":null,"max_requests":2,"max_tokens":1000,"name":"worker","parent_key_id":"key_0000b694","project_id":"prj_0000742b","requests_remaining":2,"requests_used":0,"revoked_at":null,"scopes":["models"],"secret":"mdw_...","tokens_remaining":1000,"tokens_used":0}
```

Things to know before you rely on a limit:

- Limits cover the key's whole life unless you set `limit_reset` to `daily`, `weekly` or `monthly`. Then both counters go back to zero at midnight UTC, on Monday at midnight UTC, or on the first of the month at midnight UTC.
- `GET /v1/key` returns the calling key with `requests_used`, `tokens_used`, `requests_remaining` and `tokens_remaining`. Any key can call it. See [Authentication](/set-up-your-account/authentication#read-a-key-and-its-usage).
- `PATCH /v1/keys/{key_id}` changes a limit or the reset period on a live key. The counters stay. See [Authentication](/set-up-your-account/authentication#update-or-switch-off-a-key).
- A key created by a limited key must state the same limit, at or below its parent's. Its use counts against itself and against every key above it. The rejection does not say which key in the chain ran out. See [Authentication](/set-up-your-account/authentication#child-keys).
- A rejection for a spent limit is a 403, not a 429. On the model routes `error.type` is the provider's: `invalid_request_error` in OpenAI's envelope, `permission_error` on `/v1/messages`. Do not retry it. `error.code` is `key_request_limit_exceeded` or `key_token_limit_exceeded`, so the code can tell a spent key from a missing scope. When the limit is on the key you called with, its message also says how much is used: `api key max_tokens limit reached: 1434 of 200 tokens used on this key; ...`. A rejected reservation lists tokens used of the limit, tokens held by calls in flight, and what the request reserves. When the limit that stopped the call belongs to a key above yours, the message carries no numbers and no key ID. Branch on `error.code`, not on the text.

## The request limit

`max_requests` counts calls that a provider served. The call after the last one allowed is rejected:

```bash
curl -sS "$MEADOW_BASE_URL/v1/chat/completions" \
  -H "Authorization: Bearer $LIMITED_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "gemini-3.1-flash-lite-preview", "messages": [{"role": "user", "content": "Say hello in five words."}], "max_tokens": 32}'
```

```json
{"error":{"message":"api key max_requests limit reached: 2 of 2 requests used on this key","type":"invalid_request_error","param":null,"code":"key_request_limit_exceeded"},"request_id":"req_0000c1de"}
```

After `PATCH /v1/keys/{key_id}` with `{"max_requests": 3}` the same call was served again.

Calls that fail are not counted. On a key with `max_requests: 1`, a request Meadow rejected (400), a request the provider rejected (400), and a route where every provider failed (502) left the limit untouched, and the next good call was served. The exception is an abandoned call, below.

## The token limit

`max_tokens` on a key limits the total input and output tokens across its calls.

### The reservation rule

Meadow cannot know what a call will use until the provider answers. So before it forwards a request on a token-limited key, it reserves an estimate:

```text
reservation = request body size in bytes / 3, rounded up
            + the output cap you sent (times n on Chat Completions)
```

The request is rejected with a 403 when tokens already used, plus reservations of calls still in flight, plus this reservation, would pass the limit. When the provider answers, Meadow charges the usage the provider reported and drops the reservation.

This key has `max_tokens: 1000`. The request is 124 bytes (42 tokens by the estimate) and asks for up to 1000 output tokens:

```bash
curl -sS "$MEADOW_BASE_URL/v1/chat/completions" \
  -H "Authorization: Bearer $LIMITED_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"gemini-3.1-flash-lite-preview","messages":[{"role":"user","content":"Say hello in five words."}],"max_tokens":1000}'
```

```json
{"error":{"message":"api key max_tokens limit would be exceeded: 0 of 1000 tokens used and 0 held by calls in flight on this key, and this request reserves 1042 tokens; lower its output token cap or shrink it","type":"invalid_request_error","param":null,"code":"key_token_limit_exceeded"},"request_id":"req_00001f8b"}
```

The same request with `"max_tokens": 100` reserves 141, fits, and is charged the 14 tokens the provider reported.

So a key can be rejected while its used tokens are still well under the limit. Do: keep output token limits close to what you need. A cap of 4096 on every call makes each call hold 4096 tokens of the budget while it runs.

Tools that set the cap for you can ask for far more than you expect. Claude Code reserved about 145,000 tokens per call until its cap was lowered. See [Claude Code on a key with a token limit](/call-models/use-your-existing-tools#claude-code-on-a-key-with-a-token-limit).

<a id="why-the-output-cap-is-required"></a>

### Why the output token limit is required

Meadow forwards your body unchanged. A request with no output token limit lets the provider generate up to the model's own maximum, and Meadow would have nothing to reserve. So on a key with `max_tokens`, its own or a parent's, every request must carry a cap the format honors:

| Format | Cap field |
| --- | --- |
| Chat Completions | `max_completion_tokens` or `max_tokens` |
| Responses | `max_output_tokens` |
| Messages | `max_tokens` |
| Gemini `generateContent` ([Gemini clients](/call-models/gemini-clients)) | `generationConfig.maxOutputTokens`, times `candidateCount` when set |

Without one:

```bash
curl -sS "$MEADOW_BASE_URL/v1/chat/completions" \
  -H "Authorization: Bearer $LIMITED_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "gemini-3.1-flash-lite-preview", "messages": [{"role": "user", "content": "Say hello in five words."}]}'
```

```json
{"error":{"message":"this api key has a token limit, so the request must set an output token cap: max_completion_tokens or max_tokens","type":"invalid_request_error","param":null,"code":"invalid_request"},"request_id":"req_00006c5c"}
```

That body was captured before a missing cap got its own code (see the 2026-11-24 section of the [changelog](/reference/changelog)). The same call now returns `"param":"max_completion_tokens"` and `"code":"parameter_missing"`, with the same message. Read from the server's code. Not run again on the hosted beta.

The cap must be a positive whole number. These are the refusals, all 400:

| Request | Message |
| --- | --- |
| No cap | `this api key has a token limit, so the request must set an output token cap: ...` |
| `"max_tokens": 0` | `max_tokens must be a positive integer on an api key with a token limit` |
| `"max_tokens": "32"` | `max_tokens must be a non-negative integer` |
| `max_tokens` on `/v1/responses`, which honors only `max_output_tokens` | `... must set an output token cap: max_output_tokens` |
| `"Max_Tokens": 32`, on any key, limited or not | `Max_Tokens must be written as max_tokens` |

A cap sent as `null` counts as absent.

### What is charged

| Outcome | Charged to the key |
| --- | --- |
| The provider answered and reported usage | The reported usage: input plus output, cached input included. |
| The provider answered with no usage Meadow can read | The reservation. |
| A stream you read to the end | The usage in the stream's final events. |
| A stream you dropped, or that broke | The reservation, or the tokens seen so far if that is more. |
| Meadow or the provider rejected the request, or every provider failed with an error status | Nothing. |
| An abandoned call (next section) | The reservation, and one request. |

On streamed Chat Completions calls Meadow asks the provider for the token count on every stream. You get a `usage` chunk only if you sent `stream_options: {"include_usage": true}`.

An open stream keeps its reservation until it ends. [Streaming](/call-models/streaming#what-a-dropped-stream-costs) shows a dropped stream being charged its full reservation of 848 tokens when 280 had been generated.

### The limit can be passed

The reservation is an estimate, and the charge is what the provider reports. When the provider counts more than the estimate, the key ends above its limit, and only the next request is rejected.

This happened in testing. A key had `max_tokens: 200`. One call to `grok-4.7` with `"max_tokens": 64` reserved about 100 tokens and was served. xAI reported 1,347 tokens: it counts about 1,250 prompt tokens of its own on every call, and its reasoning tokens are not held by the cap. The key was charged 1,347, almost seven times its limit. The next call was rejected:

```json
{"error":{"message":"api key max_tokens limit reached: 1347 of 200 tokens used on this key; one call may end above the limit, and later calls are refused until the limit resets or is raised","type":"invalid_request_error","param":null,"code":"key_token_limit_exceeded"},"request_id":"req_0000097e"}
```

The same happens when a request points at content the body does not contain: `previous_response_id`, or files and images by URL or ID.

This is by design: the budget is checked against an estimate before the call, the call that passes it is served in full, and every later call is rejected. There is no minimum budget: neither OpenRouter nor OpenAI has such a rule, so Meadow adds none. A key whose limit is smaller than one real call serves that one call.

Do: treat `max_tokens` as a brake that stops a key soon after its budget. It is no exact ceiling. Leave headroom, and try a model once to see what its provider reports for a small request. The overshoot is at most what the calls in flight at that moment use.

## What an abandoned call costs

A call is abandoned when a provider received the request and Meadow got no usable answer: a timeout or a lost connection after the request was sent, a 200 with the wrong content type, an invalid or oversized body, an empty stream, or you closing the connection.

The provider may bill you for such a call. Meadow cannot know, so on a limited key it charges one request and the reservation. If another provider then serves the call, the charge is the reservation or the reported usage, whichever is larger. The `x-meadow-abandoned-attempts` response header names the providers involved.

Three more rules for limited keys:

- All attempts together must produce the full answer, or the first stream event, within 8 minutes. After that the call gets a 502, and it is charged if a provider had the request. Stream long answers. This rule also holds on a key with a dollar `limit`.
- A stream that never settles is charged its reservation after 2 hours.
- A call the provider answered is always returned to you. If Meadow cannot write its charge at that moment, it retries for up to 2 minutes and charges the reported usage once. If no retry lands, the key is charged the reservation when its 10 minute lease ends.

Abandoned calls caused by a provider were not seen in testing. This section is read from the server's code, apart from the dropped stream.

## The in-flight limit and retry-after

Meadow sets no fixed number of requests in flight, per key or per account. Your provider's limits apply to your provider key, and a provider's 429 reaches you as described in [Routing and fallbacks](/call-models/routing-and-fallbacks). This is on the hosted beta since 2026-11-28. Before, the beta stopped one key at 16 model requests in flight on each server.

Meadow rejects a request for load only to keep one account from filling a server:

1. While a server has a free slot, every request is admitted, whatever your account already holds on it. One account alone can use the whole server.
2. On a full server a request waits up to 3 seconds for a slot.
3. A freed slot goes first to the waiting account with the fewest requests open, so a large account cannot keep a small one out.
4. If no slot comes free in time, the request gets a 429 with `error.code` `account_in_flight_limit_exceeded`.

```text
HTTP/2 429
content-type: application/json
retry-after: 1
x-should-retry: true

{"error":{"code":"account_in_flight_limit_exceeded","message":"this server has no free request slot for this account; retry","type":"rate_limited"},"request_id":"req_..."}
```

That is the body on a route outside the model API. A model route writes the same code and message in the provider's envelope, with the type `rate_limit_error`.

That response is read from the server's code and its tests. It was not captured on the hosted beta. Every kind of request counts on all the account's keys together: model calls, streams until they end, long polls, uploads. The first request of an account that has nothing open on a server is admitted ahead of the others. The hosted service runs several servers, each counts on its own, and it adds servers as load grows.

Every 429 carries `retry-after` in whole seconds. For this cause the value is `1`, and it is a floor: Meadow does not know when a slot will free up. [Errors](/reference/errors#retry-after) lists the value for each cause of a 429. This 429 also carries `x-should-retry: true`, as do the 429s for a full body budget and a busy limit check: no provider was called.

Do: wait at least the header's value, add jitter, and back off further on repeats. A 429 is not charged to a key's limits. The OpenAI and Anthropic SDKs retry a 429 on their own. See [Use your existing tools](/call-models/use-your-existing-tools#retries-and-errors).

## Request size

These apply to every key and are checked before any provider is called.

| Limit | Rejection |
| --- | --- |
| Request body over 16 MiB | 413 `request body too large`, with `error.code` `request_too_large`. Meadow answers before it has read the whole body, so a client that does not read the response while it uploads can see a closed connection in place of the 413. |
| JSON nested deeper than 64 levels | 400 `json nesting depth exceeded` |
| Estimated size over 8,000,000 tokens, by the reservation formula | 400, below |

```bash
curl -sS "$MEADOW_BASE_URL/v1/chat/completions" \
  -H "Authorization: Bearer $MEADOW_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"gemini-3.1-flash-lite-preview","messages":[{"role":"user","content":"Say hello in five words."}],"max_tokens":9000000}'
```

```json
{"error":{"message":"request is estimated at 9000043 tokens, above the limit of 8000000; lower its output token cap or shrink it","type":"invalid_request_error","param":null,"code":"invalid_request"},"request_id":"req_00006b9f"}
```

On a key with no token limit, a request with no output token limit is estimated with 4,096 output tokens for this check only.

A blocking answer larger than 32 MiB is dropped and treated as an abandoned call. Stream very large answers.

More in [Known limits](/reference/known-limits#key-limits).

## API reference

Operations on this page: [`createKey`](/reference/api-reference#createkey), [`createChatCompletion`](/reference/api-reference#createchatcompletion), [`createResponse`](/reference/api-reference#createresponse), [`createMessage`](/reference/api-reference#createmessage).

## A busy limit check

A model call on a key with `max_requests`, `max_tokens` or a dollar `limit`, its own or a parent's, is checked against those limits one call at a time per limited key. When many calls share one limited key, the checks queue. A check that waits more than 3 seconds for one limited key, or more than 4 seconds in all, returns 429 with `error.code` `key_limit_check_busy` and `retry-after`. No provider was called and nothing was charged, so retry. In a load test on 2026-11-24, calls under one limited key ran well up to about 120 a second. For more than that, give each worker its own key and put the limit on keys that carry less traffic.