Skip to content

Authentication

Send an API key as a bearer token on every request. The key names the project, its scopes decide which endpoints it may call, and a bad key answers 401.

Every request to the API carries an API key in the Authorization header, as a bearer token. The key proves who is calling, names the project the request acts on, and carries the scopes that decide which endpoints it may call.

curl https://api.useinfrared.com/v1/usage \
  -H "Authorization: Bearer $INFRARED_KEY"

You create and revoke keys in the dashboard, under Settings, API keys. The API has no endpoint for it, so a key can never make another key. API keys walks through creating one.

The header

Every requestHTTP
Authorization: Bearer ir_live_...
  • The word is Bearer, with a capital B, then a space, then the key. A lowercase bearer, another scheme, or a key in the query string counts as no key at all.
  • A key is ir_live_ or ir_test_ followed by 32 letters and digits, 40 characters in all.
  • Infrared stores a hash of the key, never the key. It is shown once, when you create it.

What a key can reach

A key belongs to one project. Lists, lookups and writes are all scoped to it, and no path carries a project id. A resource of another project answers 404, as if it did not exist.

A test key authenticates the same way and reaches the same project. Only the creation of a moderation treats it differently: no checks are used, usage is counted apart and author history is left alone. Every other call made with a test key changes real data.

Scopes

A key has one or more of three scopes. Each endpoint asks for exactly one, and scopes do not include one another.

ScopeEndpoints
moderatePOST /v1/moderations, POST /v1/moderations/batch, POST /v1/moderations/{id}/remoderate and POST /v1/templates/{slug}/test.
readEvery GET: moderations, templates, policies, guidelines, wordlists and their terms, authors, the queue, actions, webhook endpoints with their events and deliveries, and usage.
writeAuthors: create or update, block, suspend, enable. Queue: resolve, reopen. Actions: execute. Guidelines, wordlists and their terms: create, update, delete. Webhooks: create, update and delete an endpoint, rotate its secret, replay a delivery.

Two consequences to plan for:

  • Polling needs read. A key with moderate alone can start a queued moderation and cannot fetch its result with GET /v1/moderations/{id}.
  • Scopes are fixed. A key's scopes cannot be changed after it is created. Create a new key and revoke the old one.
The API keys of a project: two active keys, a live one named Backend and a test one named CI tests, each with its scopes and when it was last used.
Dashboard, Settings, API keysEach key with its environment and its scopes.

When a key is refused

401 UnauthorizedJSON
{
  "error": {
    "code": "missing_api_key",
    "message": "Missing or invalid Authorization header",
    "details": [],
    "request_id": "req_63717b6414df41308492b50dba455cc4"
  }
}
StatusCodeWhen
401missing_api_keyThere is no Authorization header, or it does not start with Bearer.
401invalid_api_keyThe key is malformed, unknown, revoked or expired. The answer is the same for all four.
403insufficient_scopeThe key lacks the scope the endpoint asks for. The message names it: This API key does not have the write scope.

A revoked key stops working at once, and an expired one at its expiry time. Neither comes back: create a new key.

A request refused with 401 does not count against the rate limit. One refused with 403 does.

Next

Something missing or unclear on this page? Write to support@useinfrared.com.