Skip to navigation

Mint an API key

Creates a key in the project named by project_id. The secret is returned once. Store it: Meadow keeps only a hash and cannot show it again.

A key can only mint keys that are equal or narrower. The new key’s scopes, allowed_models, limits, and expiry cannot exceed those of the key that makes this call, or the call returns 403. The new key’s requests and tokens also count against the key that minted it and every key above that, so size a parent’s limits for all of its children together.

Rules:

  • Left out, scopes gives the new key the minting key’s scopes among models and sandboxes. A key gets admin only when scopes names it. An empty scopes list returns 400.
  • expires_at must be in the future. Set it for a key that should end on its own, such as one passed into a sandbox in env.
  • max_requests and max_tokens are totals for the life of the key unless you set limit_reset. With limit_reset (daily, weekly or monthly) both counters go back to zero at the start of each period in UTC. Neither limit may be negative. A new key does not inherit limit_reset from the key that mints it.
  • A key with max_tokens changes what a model request must contain. See the Models section.
  • max_sandboxes caps how many sandboxes made by this key, and by keys minted from it, may be alive at once. It may not be negative, and a minted key’s cap cannot be above the minting key’s. A create past it returns 403 key_sandbox_limit_exceeded. It is not reset by limit_reset.
  • Unknown fields return 400.
  • Revoking a key later revokes every key minted from it, at any depth. A revoked or disabled key cannot mint.
  • Send Idempotency-Key so a retry cannot mint a second key. A retry by the same API key with the same Idempotency-Key and body returns the first response with Idempotent-Replayed: true and without secret: Meadow keeps only a hash of a key and cannot show the secret again. If you lost the first response, revoke that key by its id and mint a new one with a new Idempotency-Key. The minting rules are checked again before a replay, so a key that may no longer mint this key gets 403 and no replay.

Scope: admin.

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","sandboxes"]}'

Authentication

AuthorizationBearer

A Meadow API key, sent as Authorization: Bearer mdw_.... The header x-api-key: mdw_... is accepted in its place.

Headers

Idempotency-KeystringOptionalformat: "^[ -~]+$"1-255 characters

Makes a retry safe. A repeat with the same key and the same body returns the result of the first call instead of starting again. The same key with a different body returns 409. On POST /v1/keys, POST /v1/projects and POST /v1/images a value is scoped to the API key that sent it: another key that sends the same value starts its own request. The sandbox and exec routes scope it to the API key too. On the exec route the header only has an effect with background: true. See Idempotency in the introduction for how long a value is kept.

The key is 1 to 255 bytes of printable ASCII. A blank, longer, or non-ASCII key, or the header sent twice, returns 400. A UUID works well.

Request

At most 1 MiB.
project_idstringRequired
The project the key belongs to. It can be any project of the account.
namestringOptional
A label for people. Absent from responses when not given.
scopeslist of enumsOptional

What the key may do. models covers model calls. sandboxes covers sandboxes, images, and build contexts. admin covers projects, keys, and provider keys. When left out, the new key gets the minting key’s scopes among models and sandboxes. It gets admin only when this names it. Must not be empty.

Allowed values:
allowed_modelslist of stringsOptional

Model ids the key may call. Left out, the key may call any model. An empty list returns 400: leave the field out instead. Absent from responses when not set.

Matching is exact and case-sensitive, after Meadow reads the id the way a request’s model is read. A plain id such as claude-haiku-5-5 allows that model on every provider that serves it. A vendor alias counts as the model it names (claude-haiku-4-5 and claude-haiku-4-5-20251001 are one model), and a leading meadow/ is dropped. A prefixed id such as anthropic/claude-haiku-5-5 allows the model on that provider only. A prefix Meadow does not know returns 400.

The list is checked against the model the request names, before any vendor is called. When the vendor answers with another snapshot or reroutes the model, the call is served and the usage record’s served_model shows what answered.

A key minted by a key with allowed_models must name models from that list. A key is also held by the allowed_models of every key above it, at the moment of each call.

allowed_providerslist of enumsOptional

The model providers the key’s calls may be routed to. Left out, any. An empty list returns 400. Absent from responses when not set. OpenRouter guardrails use the same name.

It applies to every attempt of a call: the default route, provider.order, provider.only, a prefixed model id, the fallback models in models and each fallback to the next provider. A call whose route keeps no provider on the list returns 403 key_provider_access_denied before any vendor is called. GET /v1/models lists only these providers. The name is the Meadow provider whose stored key pays for the call: with openrouter on the list, OpenRouter still picks its own upstream.

A key minted by a key with allowed_providers must name providers from the minting key’s list. A key is also held by the allowed_providers of every key above it, at the moment of each call.

allowed_sandbox_providerslist of enumsOptional

The sandbox providers the key may create sandboxes and build images on. Left out, any. An empty list returns 400. Absent from responses when not set. It applies to the create, its failover to the next provider, and build_on. A create whose route keeps no provider on the list returns 403 key_provider_access_denied. A sandbox already running stays reachable after its provider leaves the list.

A key minted by a key with allowed_sandbox_providers must name providers from the minting key’s list. A key is also held by the list of every key above it. A key made for a sandbox with model_access or sandbox_access gets the creating key’s three lists.

Allowed values:
expires_atdatetime or nullOptional
When the key stops working. Must be in the future. Null or left out means it does not expire.
max_requestsinteger or nullOptional

The most model requests the key may make in one period: its whole life, or each day, week or month when limit_reset is set. Null or left out means no limit.

max_tokensinteger or nullOptional
The most model tokens, input plus output, the key may use in one period. Null or left out means no limit. A key with this limit must send an output cap on every model request. The check uses an estimate, so one call can pass the limit before later calls are refused.
limitdouble or nullOptional>=0

The most US dollars the key may spend in one period: its whole life, or each day, week or month when limit_reset is set. The name and the unit are OpenRouter’s limit. Null or left out means no dollar limit.

Send a plain JSON number, at least 0 and below 10^12, with at most 12 decimal places. Meadow reads the digits as written and never through a binary float, so 0.1 is one tenth exactly. A value with more decimal places returns 400.

It covers model calls and sandboxes made with this key and with every key minted from it. Before a model call Meadow reserves the most the call can cost (its estimated tokens at the model’s highest price) and refuses the call with 402 key_spend_limit_exceeded when that does not fit. After the call it charges what the call cost. One call can end above the limit, and every later call is refused until the limit resets or is raised.

A key with this limit, or under a key with one, must send an output cap on every model request. It can only call models Meadow holds a price for at the provider that serves them: a route that includes any other provider returns 403 key_spend_price_unknown. See the Spend limits guide.

A minted key does not need a limit of its own. It spends from what the keys above it have left. When it has one, it cannot be higher than the minting key’s.

limit_actionenumOptional

What happens to running sandboxes when this key’s limit is spent. Null or left out, the default, leaves them running: only new sandboxes and model calls are refused. stop_sandboxes also deletes every running sandbox made with this key or with a key minted from it, within about a minute of the limit being spent. 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 acts only on the limit of the key it is set on. No reference product stops running compute at a budget, so the name is Meadow’s, in the limit_ family.

Allowed values:
max_sandboxesinteger or nullOptional>=0

The most sandboxes that may be alive at once among those made by this key and by every key minted from it. Null or left out means no cap. A sandbox counts while it is creating, running or terminating, and while it is failed with a vendor sandbox Meadow has not yet confirmed deleted. The count and the create are one database transaction, so two creates sent together cannot both take the last place. A create past the cap returns 403 key_sandbox_limit_exceeded. It counts sandboxes, not dollars.

limit_resetenumOptional

When the key’s max_requests, max_tokens and limit counters go back to zero. The name, the values and the clock are OpenRouter’s limit_reset: daily resets at midnight UTC, weekly on Monday at midnight UTC (weeks run Monday to Sunday), monthly on the first of the month at midnight UTC. Null or left out means no reset: the limits cover the key’s whole life. One value covers every limit of the key.

A minted key does not inherit limit_reset. It gets the value sent when it is minted, or none. Its max_requests and max_tokens still cannot be larger numbers than the minting key’s, whatever the two reset periods are. Its usage counts against the minting key and every key above it, each in that key’s own period, so a child’s reset never lifts a limit above it.

A call reserved before a boundary and finished after it is charged to the new period.

Allowed values:

Response headers

x-request-idstringOptional

Meadow’s id for this request, req_ and 24 hex characters. Every response carries it, including errors, streams and unknown routes. Every error in the Error schema repeats it as request_id. Quote it when you report a problem.

Idempotent-ReplayedenumOptional

true when this response is the saved result of an earlier request with the same Idempotency-Key. Absent on a first response. Sent by POST /v1/keys, POST /v1/projects, POST /v1/images, POST /v1/sandboxes and a background POST /v1/sandboxes/{sandbox_id}/exec. On the two sandbox routes the body is the sandbox or the command as it is now.

Allowed values:

Response

Created. secret is shown only here. A replay of this response (Idempotent-Replayed: true) does not carry secret.

project_idstring
The project the key belongs to. It can be any project of the account.
idstring

The key id (key_...). Use it to read, update or revoke the key. It is not the secret.

created_atdatetime
When the key was minted.
namestringOptional
A label for people. Absent from responses when not given.
scopeslist of enumsOptional

What the key may do. models covers model calls. sandboxes covers sandboxes, images, and build contexts. admin covers projects, keys, and provider keys. When left out, the new key gets the minting key’s scopes among models and sandboxes. It gets admin only when this names it. Must not be empty.

Allowed values:
allowed_modelslist of stringsOptional

Model ids the key may call. Left out, the key may call any model. An empty list returns 400: leave the field out instead. Absent from responses when not set.

Matching is exact and case-sensitive, after Meadow reads the id the way a request’s model is read. A plain id such as claude-haiku-5-5 allows that model on every provider that serves it. A vendor alias counts as the model it names (claude-haiku-4-5 and claude-haiku-4-5-20251001 are one model), and a leading meadow/ is dropped. A prefixed id such as anthropic/claude-haiku-5-5 allows the model on that provider only. A prefix Meadow does not know returns 400.

The list is checked against the model the request names, before any vendor is called. When the vendor answers with another snapshot or reroutes the model, the call is served and the usage record’s served_model shows what answered.

A key minted by a key with allowed_models must name models from that list. A key is also held by the allowed_models of every key above it, at the moment of each call.

allowed_providerslist of enumsOptional

The model providers the key’s calls may be routed to. Left out, any. An empty list returns 400. Absent from responses when not set. OpenRouter guardrails use the same name.

It applies to every attempt of a call: the default route, provider.order, provider.only, a prefixed model id, the fallback models in models and each fallback to the next provider. A call whose route keeps no provider on the list returns 403 key_provider_access_denied before any vendor is called. GET /v1/models lists only these providers. The name is the Meadow provider whose stored key pays for the call: with openrouter on the list, OpenRouter still picks its own upstream.

A key minted by a key with allowed_providers must name providers from the minting key’s list. A key is also held by the allowed_providers of every key above it, at the moment of each call.

allowed_sandbox_providerslist of enumsOptional

The sandbox providers the key may create sandboxes and build images on. Left out, any. An empty list returns 400. Absent from responses when not set. It applies to the create, its failover to the next provider, and build_on. A create whose route keeps no provider on the list returns 403 key_provider_access_denied. A sandbox already running stays reachable after its provider leaves the list.

A key minted by a key with allowed_sandbox_providers must name providers from the minting key’s list. A key is also held by the list of every key above it. A key made for a sandbox with model_access or sandbox_access gets the creating key’s three lists.

Allowed values:
expires_atdatetime or nullOptional
When the key stops working. Must be in the future. Null or left out means it does not expire.
max_requestsinteger or nullOptional

The most model requests the key may make in one period: its whole life, or each day, week or month when limit_reset is set. Null or left out means no limit.

max_tokensinteger or nullOptional
The most model tokens, input plus output, the key may use in one period. Null or left out means no limit. A key with this limit must send an output cap on every model request. The check uses an estimate, so one call can pass the limit before later calls are refused.
limitdouble or nullOptional>=0

The most US dollars the key may spend in one period: its whole life, or each day, week or month when limit_reset is set. The name and the unit are OpenRouter’s limit. Null or left out means no dollar limit.

Send a plain JSON number, at least 0 and below 10^12, with at most 12 decimal places. Meadow reads the digits as written and never through a binary float, so 0.1 is one tenth exactly. A value with more decimal places returns 400.

It covers model calls and sandboxes made with this key and with every key minted from it. Before a model call Meadow reserves the most the call can cost (its estimated tokens at the model’s highest price) and refuses the call with 402 key_spend_limit_exceeded when that does not fit. After the call it charges what the call cost. One call can end above the limit, and every later call is refused until the limit resets or is raised.

A key with this limit, or under a key with one, must send an output cap on every model request. It can only call models Meadow holds a price for at the provider that serves them: a route that includes any other provider returns 403 key_spend_price_unknown. See the Spend limits guide.

A minted key does not need a limit of its own. It spends from what the keys above it have left. When it has one, it cannot be higher than the minting key’s.

limit_actionenumOptional

What happens to running sandboxes when this key’s limit is spent. Null or left out, the default, leaves them running: only new sandboxes and model calls are refused. stop_sandboxes also deletes every running sandbox made with this key or with a key minted from it, within about a minute of the limit being spent. 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 acts only on the limit of the key it is set on. No reference product stops running compute at a budget, so the name is Meadow’s, in the limit_ family.

Allowed values:
max_sandboxesinteger or nullOptional>=0

The most sandboxes that may be alive at once among those made by this key and by every key minted from it. Null or left out means no cap. A sandbox counts while it is creating, running or terminating, and while it is failed with a vendor sandbox Meadow has not yet confirmed deleted. The count and the create are one database transaction, so two creates sent together cannot both take the last place. A create past the cap returns 403 key_sandbox_limit_exceeded. It counts sandboxes, not dollars.

limit_resetenumOptional

When the key’s max_requests, max_tokens and limit counters go back to zero. The name, the values and the clock are OpenRouter’s limit_reset: daily resets at midnight UTC, weekly on Monday at midnight UTC (weeks run Monday to Sunday), monthly on the first of the month at midnight UTC. Null or left out means no reset: the limits cover the key’s whole life. One value covers every limit of the key.

A minted key does not inherit limit_reset. It gets the value sent when it is minted, or none. Its max_requests and max_tokens still cannot be larger numbers than the minting key’s, whatever the two reset periods are. Its usage counts against the minting key and every key above it, each in that key’s own period, so a child’s reset never lifts a limit above it.

A call reserved before a boundary and finished after it is charged to the new period.

Allowed values:
last4stringOptional
The last four characters of the secret.
disabledbooleanOptional

True when the key was switched off with PATCH /v1/keys/{key_id}. A disabled key and the keys minted from it are refused with 401.

requests_usedintegerOptional

Model requests counted against this key in its current period (its whole life when limit_reset is null). It includes the requests of every key minted from this one, at any depth.

A key with a max_requests or max_tokens, on itself or on a key above it, is counted as each call is admitted. A key with no limit anywhere in its chain is counted from the usage records instead (GET /v1/usage): calls that were served. Today and yesterday (UTC) are read from the single records, a few seconds behind. Earlier days are read from the daily totals Meadow keeps.

tokens_usedintegerOptional

Tokens charged to this key in its current period, counted like requests_used. For a key with no limit in its chain it is the input plus output tokens of the usage records, estimates included.

usagedouble or nullOptional

US dollars charged to this key in its current period, the keys minted from it included. The name is OpenRouter’s usage. Null when neither this key nor a key above it has a limit: Meadow counts dollars against a key only while a limit applies to it, and GET /v1/usage has the spend of any key.

It is the number the limit is checked against. A call whose cost could not be computed is charged its reserved estimate here and has no cost in GET /v1/usage, so this can be higher than the sum of the usage records.

limit_remainingdouble or nullOptional

What the key can still spend: the least of limit minus usage over this key and every key above it, never below 0. The name is OpenRouter’s limit_remaining. Null when none of them has a limit. Dollars held by calls in flight are not subtracted, so a call can be refused while this is above 0.

requests_remaininginteger or nullOptional

max_requests minus requests_used, never below 0. Null when the key has no max_requests. It does not look at the keys above this one, whose own limits can stop a call first.

tokens_remaininginteger or nullOptional

max_tokens minus tokens_used, never below 0. Null when the key has no max_tokens. Tokens held by calls in flight are not subtracted, so a call can be refused while this is above 0.

last_used_atdatetime or nullOptional

When this key last authenticated a call of any kind (a model call, a sandbox call, a key or project call), or when a model call was last counted against it or a key below it, whichever is later. It is written at most once a minute for each key, so it can be up to a minute behind. The write runs beside the call and lands up to 2 seconds after it. Null for a key that was never used. Reading a key with itself (GET /v1/key) is a use of that key, and that same call can still show the earlier value.

limit_reset_atdatetime or nullOptional

The next time the counters reset, in UTC. Null when limit_reset is null. OpenRouter returns no such field. It is here so that you need not compute the boundary.

parent_key_idstring or nullOptional

The key that minted this one. Null for a key no other key minted, such as the first admin key. Follow it upward to see the tree: revoking a key revokes every key below it.

revoked_atdatetime or nullOptional
When the key was revoked. Null while it is live.
previous_secret_expires_atdatetime or nullOptional

When the secret replaced by POST /v1/keys/{key_id}/rotate stops working. Null when the key has one secret: it was never rotated, it was rotated with no grace period, or the grace period is over.

created_by_user_idstring or nullOptional

The signed-in person who minted this key in the dashboard. Null for a key another key minted. A person with the member role sees only the keys they minted.

secretstringOptional

The key itself, starting with mdw_. Shown once.

Errors

400
Bad Request Error
401
Unauthorized Error
403
Forbidden Error
404
Not Found Error
409
Conflict Error
413
Content Too Large Error
429
Too Many Requests Error
500
Internal Server Error