Skip to main content
This page is for anyone wiring an OpenType API key into code, and for anyone debugging a request that came back 401, 403 or an auth-related 503. It covers the one header every protected route reads, the two kinds of credential that header can carry, how a key is checked, and each auth error with its fix.

The header

Every protected /v1 route takes one header:
  • The scheme name is compared case-insensitively, so Bearer, bearer and BEARER all work.
  • The scheme and the credential are split on the first whitespace, and the credential is trimmed.
  • An empty credential counts as no credential.
  • There is no other auth header and no cookie auth.

Two kinds of credential

The server decides what a credential is from its prefix. Your code uses API keys. The console holds its own session when you sign in, and you never need to copy a session into code. Create keys in the console under API keys or with POST /v1/keys.
A key id such as key_d12af855ae0f45b9925223d65562fd0e and a display prefix such as otsk_fde66231 are not credentials. Only the full 69-character secret authenticates.

Send an authenticated request

Keep the secret in an environment variable, never in source code. This call lists your most recent run and needs a key with runs_read, which the console’s Send requests set includes. It is a quick way to confirm a new key works.
A working key returns 200:
An organization with no runs yet gets "runs": [], which still proves the key works.

How a key is checked

For a credential that starts with otsk_, the server runs these steps in order:
  1. Shape. Anything other than otsk_ followed by exactly 64 hex characters is refused with 401 invalid_credential before any lookup.
  2. Lookup. The server computes the SHA-256 of the secret and looks for an active key with that digest. It never stores or compares the plaintext.
  3. State. A revoked key does not match, so it gets the same 401 invalid_credential as an unknown key. It does not get key_revoked, which only appears when you try to rotate a revoked key.
  4. Identity. A verified key acts in the organization it was created in, with exactly the scopes it was created with. See Scopes and roles.
After authentication, each route checks its own scope and answers 403 scope_denied when the credential lacks it.

Auth errors

Every auth error uses the standard JSON envelope. Branch on error.code, and quote error.request_id when you report a problem. Responses carry no WWW-Authenticate header. The scope_denied message says “session” even when the credential is an API key. The code is what matters.

Retry rules

  • 401 and 403: something about the credential must change. Retrying the same request returns the same error.
  • 503 auth_not_configured and trust_keys_unavailable: retry with exponential backoff and jitter. Do not revoke or replace the key because of these.
  • Treat a 401 as a signal to alert a person, not to loop. A key that suddenly returns invalid_credential was usually revoked or rotated by someone in your organization.

Common mistakes