Docs /Get started /Authentication .md

Authentication

Every call carries an API key as a bearer token, from server-side code only. How to send it, what each refusal means, and how to keep keys safe.

The API knows who is calling from the API key, and bills the call to that key's Account. There are no sessions, OAuth or signed requests: one header does it.

Send the key as a bearer token

Put the key in the Authorization header as Bearer followed by the key. That is the only way to pass one: never in the URL or the body.

Every sample in these docs reads the key from CHESSDRIVE_API_KEY. Set it as the Quickstart shows, then any call works the same way.

curl https://api.chessdrive.io/v1/generate \
  -H "Authorization: Bearer $CHESSDRIVE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "knight",
    "messages": [{ "role": "user", "content": "In one sentence, what is a fork?" }]
  }'

What a key looks like

A key starts with ck_, then 43 random characters and a 6-character checksum. The prefix and the checksum make a key easy to recognise, so a scanner can find one pasted into logs or code.

The key is shown once, when you create it in API keys. After that the Dashboard shows only a hint of its last characters. If you lose a key, create a new one and revoke the old.

ck_••••••••••••••••••••••••••••••••••••••••7Qf2Lm

Server-side only

Call the API from your server, a backend function or a script, never from a browser or a mobile app. Anything shipped to a user's device can be read, and every call made with a key is billed to your Account. If your web app needs answers, call the API from your backend and pass the result on.

The Model list is one exception: GET /v1/models is public and needs no key, so a page can read it.

A Study key is the other. When your agent builds you a Study, a chess page of your own, it makes a key for that one page, so the page can call Engine and Generate when you ask. A Study key calls only those two, up to $1 a day, and expires after 7 days. Engine and Generate answer it from any web page, a file opened from your computer included. It can't read your usage or Balance, make another key or sign in to the Connector: those answer 403 key_not_allowed. Your agent makes it with the Connector's study_key tool, chessdrive study-key or POST /v1/study_keys, and API keys lists it under Study keys, by its Study's name, where you can revoke it. A copy of the page you download carries no key; it shows an "Add your key" line instead, and a key pasted there stays in that browser.

When a key is refused

A refused call is never billed. A 401 means the key itself was not accepted; a 403 means the key is fine but may not make this call.

StatusCodeMeaningNext step
401missing_api_keyNo Authorization: Bearer header.Send the header. Check the variable is set in the process that makes the call.
401invalid_api_keyNot a key we issued, or mistyped.Copy the key again, or create a new one.
401revoked_api_keyThe key was revoked.Create a new key. Revoking is permanent.
401expired_api_keyThe key passed its expiry date.Create a new key. Expiry is fixed when a key is made.
401disabled_api_keyThe key is disabled.Enable it again in API keys, or use another key.
403key_not_allowedThe key is restricted to other APIs, or to another Model, or it's a Study key off Engine and Generate.Use a key allowed for this API and Model, or change the call.
403account_suspendedThe Account is suspended.Contact us at contact@edgecaselabs.dev.

Every refusal carries a request-id. Quote it if you write to us. The Errors page lists every code the API can return.

Keeping keys safe

  • One key per app and environment. Name it after where it runs, like "Production: tournament app". When one leaks, you revoke only that one, and Usage shows spend per key.
  • Keep keys out of code. Read them from an environment variable or your platform's secret store, and keep .env files out of version control.
  • Set a Key limit. Customize, when you create a key, can cap what it may spend per day, week or month, or in total. A leaked or looping key then can't drain your Balance. Calls past it are refused with 402 key_limit_reached until the limit resets. Your Account's Spend limit applies too.
  • Restrict it. A key can be limited to some APIs, and to one Model, such as a Knight-only key. Calls outside that are refused with 403 key_not_allowed.
  • Let it expire. Keys last a year unless you choose otherwise. "Never" is offered, but a key that never expires stays dangerous if it leaks.
  • Rotate without downtime. Create the new key, deploy it, check its last use in API keys, then revoke the old one.
  • If a key leaks, revoke it. Revoking takes effect at once and can't be undone. To pause a key instead, disable it: calls are refused with disabled_api_key until you enable it again.