Auth

POST /v1/account/anonymous mints a free key. Later calls send that key in the Authorization header.

Paths are the gateway's own paths. This page does not name a public host and does not print a real key. Refusal bodies are on Errors.

Anonymous key

This route runs before the setup-key gate. It does not read Authorization, an email, or a card. An empty body is {}. A body that is not JSON is 400 bad_json and does not mint a key. A request that enters the mint creates a new account. HTTP 500 does not return the key.

POST /v1/account/anonymous
POST /v1/account/anonymous

Success is HTTP 200. The stored account is plan free with credits_face_usd 0.0. The response does not include the account hash. <api_key> below is a placeholder, not a key. The store keeps a hash of the raw key. A later key list returns that hash truncated to 12 characters plus ..., not the raw key. This route does not write the meter. The response does not include shown_once.

200
{
  "api_key": "<api_key>",
  "daily_cap_usd": 1.0
}

daily_cap_usd is the number 1.0. If that cap is not stored, or any other exception is raised, the HTTP status is 500 and the body is {"error":{"code":"anonymous_failed"}}. The internal reason is not in the body.

POST /v1/account/create is a different route. It is mounted only with the UI API object, and it refuses unless the JSON field setup_key matches. That refusal is 403 bad_setup_key. Anonymous does not use setup_key.

Bearer header

The handler reads the header named Authorization. The value must start with the seven characters Bearer (capital B, then a space). The key is the remainder, with surrounding whitespace removed. A missing header, a lowercase bearer, or a value with no space after Bearer is treated as no key. The key is accepted only when account_for_key finds a row whose hash matches and revoked is 0.

Authorization
Authorization: Bearer <api_key>

A missing, unknown, or revoked key on a route that requires it is HTTP 401 with {"error":{"code":"bad_key","message":"unknown or revoked key"}}. CORS allows the request header Authorization. An OPTIONS preflight is 204 and does not check the key.

Calls that require it

These GET paths return 401 before any other body. /v1/account, /v1/logs, /v1/logs/{id}, /v1/statement, /v1/statement/export, /v1/settings, /v1/export, and /v1/export/full exist only when the UI API object is mounted. Without it, a valid bearer still gets 404 not_found for those paths.

After webhooks, anonymous, and account create, every other POST requires the bearer. That includes POST /v1/chat/completions, POST /v1/meter/ingest, POST /v1/keys/issue, POST /v1/keys/revoke, POST /v1/keys/rotate, POST /v1/keys/cap, POST /v1/settings/{key}, POST /v1/credits/purchase, and POST /v1/founding/purchase. An unknown POST with no valid account is 401, not 404. With a valid account, an unknown POST is 404 not_found. Key, settings, credit, and founding POSTs also require the UI API object; otherwise a valid bearer gets 404.

Chat checks the key in the handler first. A non-stream call that fails inside chat can still return 401. A call with stream true has already been answered HTTP 200 before chat_stream runs, so a failed re-check is an SSE line with the same bad_key object, not HTTP 401. See Errors.

Calls that do not use it

An unknown GET is 404 not_found and does not check the bearer.