API authentication

Every request carries one credential: an API key in the Authorization header. This page covers how keys are created, scoped and revoked, and how to diagnose the failures around them.

The header

Send the key as a bearer token. There is no second signature, no timestamp and no request signing to implement - one header is the whole protocol.

  • Header name: Authorization
  • Value: Bearer followed by the key
  • Missing or malformed header: 401
  • One key works on every endpoint and every model on the account

One token per device, not one token per account

Create a separate token for each machine, editor or project. A token can carry its own quota, so a runaway script on one machine cannot drain the balance that the rest of the team depends on.

When a laptop is lost or a key is pasted into a public repository, revoke that token only. The other tokens keep working, and you do not have to rotate everything.

Keep the key out of the repository

Put the key in an environment variable and read it from there. A key committed to git stays in the history even after you delete the line, and bots scan public repositories for exactly this pattern.

In shell profiles use the export form, in CI use the secret store, and in editors use the environment field rather than the config file when the tool supports it.

Why a request returns 401

The key is wrong, revoked, or not being sent. The three causes in practice, in order of frequency: the variable is empty in the shell that runs the request; the key was rotated in the panel and the old one is still in the config; the header was sent twice, once by the SDK and once by hand.

Check the variable first. A key that prints as an empty string after export is the single most common support case, and it looks identical to a revoked key from the client side.

Related pages