Skip to main content

Authentication headers reference

Reference for the key headers the gateway accepts, which header wins when a request carries several, and the exact 401 replies for a missing or rejected key.

Last updated

The gateway reads your memtrunk key from a request header. Send the key in one header on each request to the paths in the endpoints reference. GET /health needs no key.

Accepted headers#

The gateway accepts the key in any of these headers.

HeaderFormExample value
AuthorizationBearer schemeBearer <your-memtrunk-key>
x-api-keyThe key alone<your-memtrunk-key>
x-goog-api-keyThe key alone<your-memtrunk-key>

The paths in the endpoints reference use the same rule. A path does not accept some of these headers and refuse the others.

The gateway strips spaces around the key. It matches the Bearer scheme without regard to letter case.

Examples#

Each request below sends the same key in a different header.

bash
curl https://<your-memtrunk-address>/v1/models \
  -H "Authorization: Bearer <your-memtrunk-key>"
bash
curl https://<your-memtrunk-address>/v1/models \
  -H "x-api-key: <your-memtrunk-key>"
bash
curl https://<your-memtrunk-address>/v1/models \
  -H "x-goog-api-key: <your-memtrunk-key>"

Which header wins#

The gateway checks the headers in this order and uses the first one that holds a key.

  1. Authorization, when the scheme is Bearer and the token is not blank.
  2. x-api-key, when the value is not blank.
  3. x-goog-api-key.

An Authorization header with another scheme, such as Basic, does not count. The gateway then moves on to x-api-key.

The gateway does not try the next header when the first key fails. Suppose a request carries a wrong Authorization key and a valid x-api-key key. The request fails with 401. Send the key in one header only.

Replies when the key check fails#

The 401 replies use the FastAPI body shape, {"detail": "..."}. They do not use the Anthropic error shape.

CaseStatusBody
No key in the accepted headers401{"detail": "API key required"}
The key does not exist, was revoked, is disabled or has expired401{"detail": "Invalid API key"}
The owner of the key is disabled401{"detail": "Account is disabled"}

A revoked key, an expired key and an unknown key get the same message. The reply does not tell you which case applies.

json
{"detail": "Invalid API key"}

Value that is not a key#

The 401 reply can add a note when a client sends a value that is not a key. When the value looks like a different kind of token, the 401 reply says so. The Invalid API key reply carries this note. The other two replies do not.

Other replies after a valid key#

A valid key can still fail a later check. For the limits and provider rules, see errors and status codes.

  • A spend limit on the key returns 429 when no account or private provider key of the owner can serve the request.
  • A key that cannot use the provider for the request returns 403 on some paths.

For the key itself, see credentials. For the settings that carry the key in Claude Code, Codex CLI and Antigravity CLI, see client variables.