Give a key a new secret
Replaces the key’s secret and returns the new one. Shown once. The key id, its
project, scopes, limits, counters, expires_at and every key minted from it
stay as they are, and usage records keep the same key_id.
grace_period_seconds keeps the old secret working for that long, so you can
deploy the new one first. Left out or 0, the old secret stops at once. The
most is 604800 (7 days). The grace period never runs past the key’s
expires_at. While it runs, previous_secret_expires_at on the key says when
the old secret stops.
A key keeps one old secret. Rotating again inside a grace period ends the earlier old secret at once. Both secrets are the same key: a revoked, disabled or expired key is refused through either one, and both count against the same limits.
This route does not take Idempotency-Key. Send it once. If the response is
lost, rotate again: with a grace period, the secret you still hold keeps
working until you have the new one.
Scope: admin. An admin key may rotate itself.
Authentication
A Meadow API key, sent as Authorization: Bearer mdw_.... The header
x-api-key: mdw_... is accepted in its place.
Path parameters
The key id (key_...). The secret does not work here.
Request
Response headers
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.
Response
Rotated. secret is the new secret and is shown only here.
The key id (key_...). Use it to read, update or revoke the key. It is not the secret.
The new secret, starting with mdw_. Shown once.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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 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.
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.
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.
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.
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.
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.
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.
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.
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.
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.