# Authentication

Every `/v1` request (except `GET /v1/openapi.json`) needs a secret key:

```
Authorization: Bearer sk-live-…
```

A missing, malformed, unknown, revoked or expired key returns `401 invalid_api_key`.

## Live and test keys

| | Live key `sk-live-…` | Test key `sk-test-…` |
|---|---|---|
| Calls the AI engine | Yes | Never |
| Billed | Yes, from your USD wallet | Never |
| Response | Real result | Deterministic sample + header `Talksign-Test-Mode: true` |
| Rate limit | Your per-key limit (default 60/min) | 10 requests/min |
| Usage analytics | Live usage | Separate test usage |
| Needs | Accepted Developer API terms | Nothing |

Create keys in the developer portal under **API keys**. The full key is shown
**once**, at creation; Talksign stores only a hash and shows the prefix afterwards.
Lost a key? Rotate or revoke it and create a new one.

New live keys require the current Developer API terms to be accepted. When the
terms change you are asked to accept them again before creating more live keys;
existing keys keep working.

## Rotation with a grace window

Rotate a key in the portal (**API keys → Rotate**). You choose a grace window of
0 to 24 hours:

- **0 hours**: the old key is revoked immediately.
- **1–24 hours**: the old key keeps working until the window ends, so you can roll
  the new key out to every server without downtime. After that it stops (401).

The new key has the same mode (live/test) and name. Revoking a key takes effect
within seconds on every server.

Recommended routine: rotate with a short grace window (e.g. 1 hour), deploy the new
key, check that traffic on the old key has stopped in **Usage**, then let it expire.

## Scopes and IP allow-lists

A key can be limited to **scopes** and to an **IP allow-list** (portal **API keys → Edit**,
or when you create the key). Keys created without scopes have every scope.

| Scope | Allows |
|---|---|
| `sign:write` | Speech-to-sign (realtime, studio, gloss) and speech-to-speech. |
| `avatars:write` | Creating and deleting custom avatars. |
| `jobs:read` | Listing and reading jobs. |
| `jobs:write` | Creating and canceling jobs, creating uploads. |
| `meetings:write` | Creating, reading and stopping meetings. |
| `voice:write` | Text to speech. |
| `usage:read` | `GET /v1/usage` and `GET /v1/balance`. |

A call the key's scopes do not cover answers `403 insufficient_scope`. With an allow-list
(exact IPv4/IPv6 addresses or IPv4 ranges like `203.0.113.0/24`), calls from other
addresses answer `403 ip_not_allowed`. Changes apply on the next call.

An account can have up to **20 active test keys**. Key format is unchanged (`sk-live-…`,
`sk-test-…`); every existing key keeps working.

## Versioning

Send an optional dated `Talksign-Version` header to pin the behaviour you built against:

```
Talksign-Version: 2026-11-22
```

Every response carries `Talksign-Version` with the version that served it (the current
version when you send none). Supported: `2026-06-01`, `2026-11-22`. An unknown value
answers `400 invalid_version`. Breaking changes ship under a new date; the changelog says
what changed.

## Keep keys on your server

- **Never put a key in a browser, mobile app, browser extension or public repository.**
  Anyone who sees it can spend your wallet.
- Browsers are blocked on purpose: a `/v1` call with an `Origin` header other than the
  developer portal gets `403 cors_origin_not_allowed`. Call the API from your backend
  and pass the result (clip URLs, gloss, text) to your front end.
- Store keys in a secret manager or environment variables, one key per environment
  (production, staging, CI), so you can rotate one without touching the others.
- Use test keys in CI and local development.
- Set spend limits in the portal (see "Pricing and billing") as a safety net.
- If a key leaks: rotate with 0 hours grace right away.
