Before you start

Authentication: API keys and scopes

Keys belong to a person. A tenant API key is made by a person in your organisation and acts inside that person's own organisation. It is not an account of its own. There is no OAuth sign-in for the API.

Choose a name, scopes and an expiry.

Three fields, all required.

  1. Key name. 1 to 80 characters. Name it for the system that will hold it, not for yourself.

  2. Scopes. Tick boxes. customer:read is ticked by default. Pick the fewest you need. The full list is on the scopes reference.

  3. Expires after. 1 to 366 days. The default is 90 days. There is no key that never expires.

  4. Not available. IP restrictions are refused: "IP restrictions are not available for API keys yet." (Not built.) A key can hold at most 64 scope entries, and duplicates are removed.

Shown once. Not recoverable.

The screen says: "Copy the key now. It will not be shown again, and nobody can recover it for you." Terania stores only a digest of the key, never the key. If you lose it, make a new key and revoke the old one.

  1. Put it in a secret store or an environment variable on the server that will call the API.

  2. Never put it in a web page, a mobile app, a repository or a support message.

  3. The key looks like qk_, your organisation's ID, a full stop, then a secret.

One header, every call.

Send Authorization: Bearer <key>. The word Bearer is not case-sensitive. A key in the query string (key, api_key or token) is refused with 401 before anything else happens.

bash
curl -s "https://app.terania.ai/api/v1/customers?limit=1" \
  -H "Authorization: Bearer $TERANIA_KEY"

A scope is a filter, not a grant.

A scope can only reduce what the person who made the key can do. It never adds to it.

  1. At creation. Every scope you tick must be inside what your role holds right now.

  2. At every request. The key's scopes are checked again against the maker's current permissions. Demote the person and every key they made narrows on the next request.

  3. If the maker leaves. A key whose maker is suspended answers 401 and shows "Paused". When the maker has left it shows "Stopped". Removing a member revokes their keys.

  4. Read-only keys. There is no separate flag. A key whose scopes all end in :read can only read. Write scopes are a closed list of 16 (for example customer:create, case:update, mission:assign).

  5. Spending scopes. mission:assign and automation:run spend your AI allowance. Give them only to keys that need them.

Rotate means replace.

"Rotate key" makes a new key with the same name, scopes and lifetime, and revokes the old key with the reason rotated, in the same step. There is never a second live key, so the old one stops working at once.

  1. Make the rotation when you can update the system holding the key straight away.

  2. Copy the new key. It is shown once, like any key.

  3. Update the system. Calls that still carry the old key answer 401 from the moment you rotate.

Cut it off at once.

Revoking asks for a short reason in lowercase letters and hyphens, such as no-longer-needed (2 to 32 characters, starting with a letter). It takes effect at once and stops every system using that key. The list shows Name, Access, Expires, Last used and State: Revoked, Expired, Paused or Stopped. "Last used" is updated at most once a minute.

Three checks.

  1. A call with the key answers 200 and carries API-Version: 1.

  2. A call with a scope the key does not hold answers 403 write_forbidden for writes or forbidden for a collection read.

  3. After a revoke or a rotate, a call with the old key answers 401.

If a key stops working.

  1. 401 on a key that worked. It expired, was revoked or rotated, or its maker was suspended or removed. Check the state in the keys list.

  2. 403 after a role change. The maker lost a permission. Ask an owner to make a new key from a role that holds it.

  3. 429. Per key 100 requests a minute. See rate limits.

  4. You cannot see the API keys screen. Your role is member. Ask an owner or admin.

Then.