Skip to content

Sign-In, Tokens and API Keys

  • A script, a pipeline or another system calls with a service account’s API key. A service account is a member of your organization that is not a person. It has roles of its own and needs no sign-in, password or authenticator code. This is the way for anything that runs unattended.
  • A person signs in and calls with the short-lived access token that signing in answers. The web application works this way.

Both are sent the same way, as Authorization: Bearer …. An API key begins nbf_; an access token never does.

An administrator of your organization makes service accounts and their keys on the Service Accounts screen: see Service Accounts. Before any key works, an administrator turns API keys on for the organization, under People, in its ways to sign in. Until then every key is refused.

A key:

  • is nbf_ followed by 38 letters and digits: 32 random characters and a 6-character checksum of the rest. It has no dot, so it is never mistaken for an access token;
  • is shown once, when it is made. Only a keyed hash of it and its last four characters are kept, so nobody can show it to you again;
  • lasts 90 days unless the administrator chooses otherwise, and never longer than 366 days, or than the shorter longest life the organization may set. There is no key without an end;
  • may be limited to the addresses it is used from;
  • acts as its service account, with its roles. It sees what a person with the same roles would see: a restricted model only when the service account is on its allowed list.
Terminal window
# The key is kept in your pipeline's secret store and given to the script as a variable.
curl -s -H "authorization: Bearer $FORGE_API_KEY" \
https://forge.example.com/api/models
# Who the key acts as: the service account, with "serviceAccount": true.
curl -s -H "authorization: Bearer $FORGE_API_KEY" \
https://forge.example.com/api/me

Send the key in the Authorization header only. A key in the address, as ?access_token=, is never read: addresses end up in logs.

A refused key answers 401 with a problem document whose reason says why, and a detail to show a person:

reason What happened What to do
malformed It is not a key of this product: it is cut short, or a character changed. It is refused before anything is looked up Copy the whole key again
unknown No key like it was made here Check the instance; ask an administrator for a key
expired Its life is over An administrator makes a new key
revoked An administrator revoked it An administrator makes a new key
deactivated Its service account is deactivated An administrator reactivates the account
organizationClosed The organization is suspended or archived Ask your organization’s administrators
switchedOff The organization has API keys turned off An administrator turns them on under People
outsideAllowlist The call came from an address the key does not list Call from a listed address, or ask an administrator to list it
unavailable The instance’s operators have not set up API keys Ask the instance’s operators

Each refusal of a key that exists is written to the organization’s activity log, at most once an hour for one key and one reason, so a script left running with a dead key does not fill the log.

Each key may make 600 calls a minute unless the instance’s operators set another number. Past it the answer is 429 with Retry-After and the reason apiKey. An address that sends many unknown keys is refused for a minute, as an address that fails many sign-ins is: see Errors and limits.

A service account has at most two live keys at once, so that one can replace the other:

  1. An administrator chooses Rotate the Key for the old key. The new key is shown once; the old one keeps working for the overlap chosen, up to 7 days.
  2. Put the new key in your secret store and run the script with it.
  3. The old key stops at the end of the overlap. To stop it sooner, the administrator revokes it.

A service account is not a person, so these answer 403 with personOnly for a key:

  • signing in and out, renewing a session, stepping up, and its own sign-in security (/api/auth/…, /api/me/factors, /api/me/passkeys, /api/me/accounts);
  • drafts with the assistant (/api/drafts), notifications (/api/me/notifications) and saved views (/api/views);
  • the live channel;
  • support access and the administration of service accounts.

A service account is never an administrator, so the administrators’ routes refuse it too. The API reference shows, for each route, whether it takes an API key: the apiKey scheme.

A key is a password for a machine. Keep it in a secret store, never in a repository. GitHub’s secret scanning does not report this product’s keys to us, so a key pushed somewhere public is not revoked by itself: revoke it as soon as you know.

POST /api/auth/sign-in with the person’s address and password:

{ "email": "someone@example.com", "password": "..." }

The answer is one of two:

  • A session: accessToken, expiresIn (seconds) and user. The answer also sets the refresh token in a cookie, HttpOnly and limited to /api/auth.

  • A challenge, for a person with a second step: secondFactor, challenge, expiresIn, and factors, which lists totp, passkey or both. With totp, send the challenge and a current code from the authenticator app to POST /api/auth/second-factor:

    { "challenge": "...", "code": "123456" }

    The answer is the session. The challenge lasts five minutes. The second step with a passkey needs a browser (below).

A wrong password or code answers 401. Repeated failures lock the account for a while, and sign-in is limited per address per minute; see Errors and limits.

An organization may turn passwords off. A right password then answers 409, with the reason in detail.

Send Authorization: Bearer <accessToken> with every call. An access token lasts a few minutes (10 unless the instance’s operator changed it).

POST /api/auth/refresh with the refresh cookie and the header X-Requested-With: forge answers a new access token and replaces the cookie. Without the header the answer is 403: the header is what tells the API the request is not a form posted from another site.

Each refresh token is used once. Using one twice ends the whole session, because it can mean the token was copied.

POST /api/auth/sign-out ends the session the cookie names and revokes the access token sent with it.

These are for the web application, not for scripts. Each ends in the same session as a password sign-in.

  • Passkeys. Each step has two calls. .../options answers a ceremony id and the options for the browser’s WebAuthn call. The second call sends back the ceremony and the browser’s credential. A ceremony lasts five minutes and serves once. A refused passkey answers 401 at sign-in and at the second step, and 409 at step-up, each with the reason in detail.

    Step Calls
    Sign in POST /api/auth/passkey/options, then POST /api/auth/passkey
    The second step POST /api/auth/passkey/second-factor/options and POST /api/auth/passkey/second-factor, each with the challenge
    Step-up POST /api/auth/step-up/passkey/options, then POST /api/auth/step-up/passkey, signed in
  • Microsoft, Google and Apple accounts. POST /api/auth/accounts/{provider}/start answers the provider’s address. The provider sends the browser back to /api/auth/accounts/callback. GET /api/auth/accounts says which providers the instance offers.

  • Single sign-on. POST /api/auth/discover with an address says which way the sign-in page sends it. OpenID Connect starts at /api/auth/sso/{slug}/start, and SAML at /api/auth/saml/{slug}/start.

  • Invitations. POST /api/invitations/describe and POST /api/invitations/accept take the token from the invitation link.

A person who signs in only through single sign-on, or only with a Microsoft, Google or Apple account, has no password, so a script cannot sign in as them. Use a service account instead.

Every route, with what it takes and answers, is in the API reference.