Org provisioning keys
An org provisioning key (lr_org_…) authenticates the /v1/org management
API — the machine-facing twin of the dashboard’s member and key pages. It exists
so an organization can run its own membership without a browser: create service
users and people, mint and revoke their API keys, set per-user concurrency caps,
manage model policy.
Only an owner or admin of the organization can mint one, and only from a
browser session: the three /v1/org/provisioning-keys routes take a session and
nothing else, so no key can mint, widen, list or revoke another. There is no CLI
verb and no dashboard page for them yet — the mint call in the worked example is
the whole surface.
A key is bound to one organization and to the human who minted it. Every request re-resolves that human’s live role, so the key works only while they are still an owner or admin. See Authentication for the three credential types side by side.
Authenticate
Section titled “Authenticate”Send the key as a bearer token, or in LUNAROUTE-API-KEY:
curl https://api.lunaroute.com/v1/org/users \ -H "Authorization: Bearer lr_org_<key>"The organization and the acting human are both properties of the key, so these
routes take no org_id parameter. (Only the three session routes need one, to
say which organization the browser session is acting on.)
An lr_org_ value is lr_-prefixed, so the gateway treats it as a LunaRoute
credential: it is stripped from the request headers before anything is forwarded
upstream and refused as INVALID_API_KEY. It can never authenticate an
inference request and never reaches a model provider. Inference keys (lr_) do
not work on /v1/org, and platform management keys (lr_platform_) do not
either.
Scopes
Section titled “Scopes”Every key carries <family>:read / <family>:write grants. GET and HEAD
need :read, every other method needs :write, and :write implies :read.
A request whose scope the key lacks is refused with 403 FORBIDDEN before any
work happens.
| Family | Routes it covers |
|---|---|
users |
POST /v1/org/users, GET /v1/org/users, DELETE /v1/org/users/:userId |
api-keys |
POST and GET /v1/org/users/:userId/keys, GET /v1/org/keys, DELETE /v1/org/keys/:keyId |
lanes |
PUT /v1/org/users/:userId/lanes/:field |
model-policy |
/v1/org/model-policy/* — see Model policy & spend caps |
provisioning-keys is not a scope and no key can carry it: minting, listing and
revoking provisioning keys stay session-only. Grant the least a job needs — a
deprovisioning worker wants users:write and api-keys:write, a reporting
script wants users:read and api-keys:read.
Worked example
Section titled “Worked example”Mint a key from a browser session, create a login-less service user, cap it, find its keys, rotate one, then remove it. Responses are shown as the API returns them.
1. Mint the key (session)
Section titled “1. Mint the key (session)”The session is the dashboard’s session token — the value of the
__Secure-authjs.session-token cookie — sent as a bearer token. This is the
only step that needs a browser.
SESSION=… # the __Secure-authjs.session-token cookie's valueORG_ID=… # the organization's UUID
curl -sS -X POST "https://api.lunaroute.com/v1/org/provisioning-keys?org_id=$ORG_ID" \ -H "Authorization: Bearer $SESSION" \ -H "Content-Type: application/json" \ -d '{"name":"deploy-bot CI","scopes":["users:write","api-keys:write","lanes:write"]}'{ "success": true, "key": { "id": "0192f7e2-6a1c-7d3e-9b4f-2c8a5e7d1b06", "org_id": "7f3a1c92-5b64-4d18-9e20-c8a4f6b1d573", "name": "deploy-bot CI", "key_prefix": "lr_org_1e6df317c", "scopes": ["users:write", "api-keys:write", "lanes:write"], "created_at": "2026-11-11T09:14:02Z" }, "full_key": "lr_org_1e6df317cabacbb849d89be2de47aff2166a2be3f8dfa4a78d98864e2d33750c", "message": "Provisioning key created. Save the full key — it won't be shown again."}The raw key is in full_key and nowhere else — only its hash is stored — so
save it now. key_prefix is the first 16 characters, for display in
GET /v1/org/provisioning-keys.
2. Create a service user and capture its key
Section titled “2. Create a service user and capture its key”A create requires an Idempotency-Key header (1–255 characters). Repeating the
same key with the same body replays the original result instead of creating a
second user.
LR_ORG_KEY=lr_org_1e6df317cabacbb849d89be2de47aff2166a2be3f8dfa4a78d98864e2d33750c
curl -sS -X POST https://api.lunaroute.com/v1/org/users \ -H "Authorization: Bearer $LR_ORG_KEY" \ -H "Idempotency-Key: deploy-bot-2026-11" \ -H "Content-Type: application/json" \ -d '{"service":true,"name":"deploy-bot","interactive_lanes":1,"background_lanes":0}'{ "success": true, "data": { "user_id": "0192f7e3-4c5a-7b21-8f60-3d9e2a4c7b15", "email": "svc-01J9Z6K4M3Q8R2T7V5W9X1Y2Z3@users.invalid", "lanes": { "interactive_lanes": 1, "background_lanes": 0 }, "api_key": "lr_7d895aec524af89d82acfa513a7dd20d60f4c587a285c445cbadcbe8f1435ea3", "key_id": "0192f7e3-58d2-7c04-9a1e-6b3f8d5c2a71" }}service: true creates a login-less account: a synthetic
svc-<ulid>@users.invalid address, no password, and the lr_ key returned here
as its only credential. The …_lanes fields are optional; without them the user
inherits the organization’s allowance. A create consumes a seat — with none
free the answer is 409 SEATS_FULL.
Every create on this page — the user create, the key mint and the
provisioning-key mint — answers 201 on the first call; only a replayed user
create is 200, with "idempotent_replay": true and "api_key": null:
the plaintext is unrecoverable by design, so capture it on the first response.
Without "service": true the same route provisions a person instead — email
required, no key in the response, and the address gets a credential-claim email.
3. Cap the user’s concurrency
Section titled “3. Cap the user’s concurrency”One PUT per class; the body is exactly {"value": <number|null>}.
USER_ID=0192f7e3-4c5a-7b21-8f60-3d9e2a4c7b15
curl -sS -X PUT "https://api.lunaroute.com/v1/org/users/$USER_ID/lanes/interactive" \ -H "Authorization: Bearer $LR_ORG_KEY" \ -H "Content-Type: application/json" \ -d '{"value": 2}'{ "success": true, "data": { "limits": { "interactive_lanes": 2, "background_lanes": 0 }, "org_effective_lanes": { "interactive": 4, "background": 8 }, "effective_within_secs": 65 }}The semantics of these numbers are under Per-user concurrency caps.
4. List that user’s keys
Section titled “4. List that user’s keys”curl -sS "https://api.lunaroute.com/v1/org/users/$USER_ID/keys" \ -H "Authorization: Bearer $LR_ORG_KEY"{ "success": true, "data": { "api_keys": [ { "id": "0192f7e3-58d2-7c04-9a1e-6b3f8d5c2a71", "org_id": "7f3a1c92-5b64-4d18-9e20-c8a4f6b1d573", "name": "deploy-bot", "key_prefix": "lr_7d895aec5", "created_at": "2026-11-11T09:15:44Z", "is_active": true, "created_by_user_id": "0192f7e3-4c5a-7b21-8f60-3d9e2a4c7b15" } ], "count": 1 }}This lists every key attributed to the user, revoked ones included: a revoked
key stays in the list with is_active: false and still counts towards count.
Removal is narrower — it revokes only the user’s keys that are still active.
Both sides key on created_by_user_id. GET /v1/org/keys returns every key in
the organization in the same row shape, except the platform-managed chat
runtime service key: that one is provisioned and revoked only by the platform
admin chat toggle, so it appears on no org-facing surface.
5. Rotate
Section titled “5. Rotate”Mint a second key for the same user, deploy it, then revoke the old one by id:
curl -sS -X POST "https://api.lunaroute.com/v1/org/users/$USER_ID/keys" \ -H "Authorization: Bearer $LR_ORG_KEY" \ -H "Content-Type: application/json" \ -d '{"name":"deploy-bot 2026-11"}'{ "success": true, "data": { "api_key": "lr_b8338dc4564a43b7ace9484bda3a7c07e3f1c686ee3404eafa3a89083f017532", "key_id": "0192f7e4-1a7b-7e28-b3c5-9d0f2e6a8c47" }}curl -sS -X DELETE "https://api.lunaroute.com/v1/org/keys/0192f7e3-58d2-7c04-9a1e-6b3f8d5c2a71" \ -H "Authorization: Bearer $LR_ORG_KEY"{ "success": true, "data": { "revoked": true } }The revoke takes effect on the next request: the key stops routing as soon as the invalidation publish lands, and no later than the key cache TTL — the publish is best-effort, so the TTL is the outer bound.
6. Deprovision
Section titled “6. Deprovision”curl -sS -X DELETE "https://api.lunaroute.com/v1/org/users/$USER_ID" \ -H "Authorization: Bearer $LR_ORG_KEY"{ "success": true, "data": { "removed": true } }Removal deletes the membership, frees the seat and revokes every lr_ key that
user owns, in one transaction. An admin may remove members; removing an owner or
another admin takes an owner. The last owner cannot be removed (409 LAST_OWNER).
Finish by revoking the provisioning key itself, from the session:
KEY_ID=0192f7e2-6a1c-7d3e-9b4f-2c8a5e7d1b06
curl -sS -X DELETE "https://api.lunaroute.com/v1/org/provisioning-keys/$KEY_ID?org_id=$ORG_ID" \ -H "Authorization: Bearer $SESSION"{ "success": true, "data": { "revoked": true } }Endpoints
Section titled “Endpoints”| Route | Auth | Scope |
|---|---|---|
POST /v1/org/provisioning-keys?org_id=<uuid> |
browser session | — |
GET /v1/org/provisioning-keys?org_id=<uuid> |
browser session | — |
DELETE /v1/org/provisioning-keys/:id?org_id=<uuid> |
browser session | — |
POST /v1/org/users |
lr_org_ key |
users:write |
GET /v1/org/users |
lr_org_ key |
users:read |
DELETE /v1/org/users/:userId |
lr_org_ key |
users:write |
POST /v1/org/users/:userId/keys |
lr_org_ key |
api-keys:write |
GET /v1/org/users/:userId/keys |
lr_org_ key |
api-keys:read |
GET /v1/org/keys |
lr_org_ key |
api-keys:read |
DELETE /v1/org/keys/:keyId |
lr_org_ key |
api-keys:write |
PUT /v1/org/users/:userId/lanes/:field |
lr_org_ key |
lanes:write |
GET /v1/org/model-policy |
lr_org_ key |
model-policy:read |
PUT /v1/org/model-policy/org |
lr_org_ key |
model-policy:write |
PUT /v1/org/model-policy/members/:userId |
lr_org_ key |
model-policy:write |
PUT / DELETE /v1/org/model-policy/prices |
lr_org_ key |
model-policy:write |
PUT /v1/org/model-policy/caps |
lr_org_ key |
model-policy:write |
GET /v1/org/users returns the roster (members, invitations and the seat
picture) and, when per-user caps are enabled, each member’s caps plus the
organization’s effective allowance. Write routes are rate-limited per key —
one bucket for each provisioning key, not one per IP — so a busy key is refused
with 429 RATE_LIMITED rather than slowing the rest of your automation.
Two routes also pass a separate, shared gate in front of the model-policy scan:
GET /v1/org/model-policy and PUT /v1/org/model-policy/caps. While another
request holds its slot they answer a flat 429 —
{"error": "too many concurrent requests, try again shortly", "code": "rate_limited"},
with Retry-After: 1 and none of the success / error.code fields below —
so parse those two responses defensively and retry them.
Errors
Section titled “Errors”Errors use the same envelope as the rest of the account API, apart from the
model-policy scan gate’s flat 429 noted under Endpoints:
{ "success": false, "error": { "code": "NOT_FOUND", "message": "Organization not found" } }| Status | error.code |
When |
|---|---|---|
| 400 | INVALID_REQUEST |
A missing, empty or non-UUID org_id on a provisioning-key route; a missing Idempotency-Key or one over 255 characters; an unknown body field; service: true with an email or without a name; a person create without an email; an unknown scope at mint; a cap value that is not an integer ≥ 0 or null |
| 401 | MISSING_API_KEY |
No credential on the request. |
| 401 | INVALID_API_KEY |
The key is unknown or revoked. |
| 403 | FORBIDDEN |
The key lacks the scope this route needs; on DELETE /v1/org/users/:userId, only an owner may remove an owner or an admin. |
| 403 | ACCOUNT_DELETED |
The create’s address belongs to a deleted account; that person must sign up again. |
| 404 | NOT_FOUND |
The uniform answer, deliberately without distinguishing the cause: an organization the caller cannot manage, a non-member, a plain member, and a key whose owner was demoted or removed; an unknown member, key or provisioning-key id; a cap :field other than interactive or background; a provisioning-key id from another organization or already revoked. |
| 404 | NOT_ENABLED |
The per-user cap surface is switched off (the cap PUT answers this; a create carrying caps answers 409), or model policy is not enabled for the organization or its plan. |
| 404 | TARGET_GONE |
An Idempotency-Key replay whose user has since been deleted. A user who left the organization answers the same 404 as NOT_FOUND. |
| 409 | SEATS_FULL |
The organization has no free seat. |
| 409 | PLAN_NOT_ENTITLED |
Per-user caps were requested but the plan does not include can_assign_user_lanes. |
| 409 | NOT_ENABLED |
A create carried caps while per-user caps are switched off. |
| 409 | EMAIL_EXISTS |
The address already belongs to an account; use the invitation flow instead. |
| 409 | IDEMPOTENCY_CONFLICT |
The same Idempotency-Key was already used with a different request body. |
| 409 | LAST_OWNER |
Removing the organization’s last owner. |
| 410 | IDEMPOTENCY_KEY_EXPIRED |
The Idempotency-Key was consumed 30–90 days ago: no replay and no re-create. Rows older than 90 days are treated as new. |
| 429 | RATE_LIMITED |
Too many writes from this key in a minute; retry after the bucket refills. |
| 500 | DATABASE_ERROR |
A backing store failed; retry. |
| 500 | INTERNAL |
Key generation failed at mint; retry. |
Minting a key over /v1/org has no plan gate. The session POST /v1/api-keys
refuses with 402 on a plan without API access, but /v1/org key minting
always succeeds — the gateway, not the mint, is the authority on whether a key
can serve inference.
A backend failure is a 500, never a 401: a healthy key is never reported as
invalid because of an internal problem.
Per-user concurrency caps
Section titled “Per-user concurrency caps”Caps limit how much of the organization’s concurrency one member or service user consumes. The two classes cap independently: limiting overflow requests leaves priority concurrency untouched.
| Value | Meaning |
|---|---|
absent (null) |
Inherit the organization allowance — the default. |
0 |
Blocked from that pool: requests in that class are refused with 429. For the priority pool, with the org’s interactive-overflow switch on, eligible default-scheduled traffic may still run on background capacity (subject to the member’s background cap); a 0 on the background pool blocks background capacity outright. |
n |
A ceiling, not a reservation — at most n requests in flight for that member in that class; unused headroom stays available to the rest of the organization. |
A member at a positive cap parks like an organization at its allowance; a cap of 0 does not park (see the table above). A change applies to requests arriving within about a minute (effective_within_secs).
Three classes have no per-member caps at all: embedding, System One and
BYOK requests are organization-level only.
Two switches stand in front of the surface. ORG_USER_LANES_ENABLED turns the
endpoints on: while it is off, a create carrying cap fields answers
409 NOT_ENABLED and the cap PUT answers 404 NOT_ENABLED. The plan’s
can_assign_user_lanes entitlement does the same for organizations whose plan
does not include it (409 PLAN_NOT_ENTITLED). Both are on in production today,
for plans that carry the entitlement.
Lifecycle
Section titled “Lifecycle”Keys have no expiry. Revocation, the owner’s demotion or removal, and deletion of the organization or the owner’s account are the only ways a key stops working, and each takes effect on the next request.
- The plaintext is returned once at mint and never stored — revoking and re-minting is the only recovery for a lost key.
DELETE /v1/org/provisioning-keys/:id?org_id=<uuid>revokes a key. An unknown id, another organization’s id and an already-revoked id are one answer:404.- A revoked key disappears from
GET /v1/org/provisioning-keys, which returns{"success": true, "keys": [...], "count": n}—keys, notapi_keys, since these are a different credential from the inference keys above. - A key dies with its owner’s access: demote the owner to member, or remove them from the organization, and every key they minted is refused on its next request — no revocation step, no cache window. Deleting the organization (or the owner’s account) from the dashboard is a self-serve deletion: it leaves the key’s row in place but deletes the membership that authorizes it, so the key is refused on its next request all the same. Only a platform-admin purge deletes the rows.
last_used_atis best-effort and may lag; it is a hint, not an audit trail. Every key-driven write — create, member removal, cap update, key mint and revoke, model policy — is audited with the acting human as the actor and the provisioning key id that drove it.
Migrating from an lr_ key
Section titled “Migrating from an lr_ key”/v1/org used to accept lr_ inference keys; it no longer does, so an
lr_ key now answers 401 INVALID_API_KEY there. If a script of yours still
calls /v1/org, mint an lr_org_ key with the scopes that script needs (step 1
above) and swap the header — the inference key keeps working everywhere else it
did.