> ## Documentation Index
> Fetch the complete documentation index at: https://docs.relettr.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Authentication and test mode

> API keys, scopes, spend limits, and building for free with test keys.

## API keys

Send your key as a bearer token on every request:

```bash theme={null}
curl https://api.relettr.com/v1/balance \
  -H "Authorization: Bearer $RELETTR_API_KEY"
```

Keys look like `rl_live_…` (real work, real credits) or `rl_test_…` (test mode). Each key ends in a short checksum, so a mistyped key is rejected straight away with `401 api_key_invalid`.

**Who can create keys.** Anyone signed in to Relettr who has credits can create API keys, on the site under **API keys**. Keys can't be created through the API. A key is shown **once**, when you create it; we store only a hash of it.

> [!NOTE]
>
> Welcome credits are for the website. Live API usage needs purchased credits. Test keys are always free.

**Revoking.** Revoke a key on the site. Revocation takes effect within 60 seconds; after that the key gets `401 api_key_revoked`.

> [!WARNING]
>
> Never put an API key in browser or mobile app code. Live keys sent from a browser (with an `Origin` header) are refused. Call the API from your server.

## Scopes

Each key has a set of scopes. A request without the right scope gets `403 scope_missing`.

| Scope | Allows |
| - | - |
| `chapters:read` | Read chapters, results, regions and events |
| `chapters:write` | Everything in `chapters:read`, plus create, upload, start, cancel, delete, edit. **The only scope that spends credits.** |
| `series:read` / `series:write` | Read / manage series and glossaries |
| `webhooks:read` / `webhooks:write` | Read / manage webhook endpoints |
| `billing:read` | Balance, usage and ledger |

New keys get `chapters:write`, `series:write`, `webhooks:write` and `billing:read` by default. `POST /v1/estimate` works with any valid key.

## Spend limits

You can give each key an optional **monthly credit limit** on the site, and set one for the whole account. Limits are checked when a chapter starts, against credits charged plus credits held this calendar month (UTC).

* At the limit, new starts return `402 spend_limit_reached` with `scope` (`key` or `account`), `limit` and `used_this_month`.
* The `api_key.spend_limit_reached` event fires once.
* Chapters already running always finish.

Nothing is parked or delayed silently: an over-limit start fails immediately so your code can decide what to do.

## Test mode

Test keys (`rl_test_…`) let you build and test your integration for free.

* **Separate data.** Test keys see only test objects and live keys only live objects. Using one with the other's id returns `404`, or `403 test_key_live_object` / `live_key_test_object` when it's clearly a mix-up. Webhook endpoints, events and ledgers are separate too.
* **Test balance.** Each account has 10,000 test credits. Set it with `POST /v1/test_helpers/balance`, for example to `0` to test a `402`.
* **Real validation, fake processing.** Uploads, image checks, part cutting and quotes work exactly as in live mode, so integration bugs show up. Processing then runs a fake pipeline (no GPU, no translator) that goes `queued → processing → succeeded` in about 20 seconds. Results are your own images with a "TEST MODE" band, and regions contain placeholder text such as `[test] line 3`.
* **Real events.** Ledger entries, events and webhook deliveries are real and signed.
* Test data may be cleared at any time.

### Test scenarios

Pass `test_scenario` when creating a chapter with a test key to exercise failure paths. Live keys reject the field with `400`.

| `test_scenario` | What happens |
| - | - |
| `succeed` (default) | Normal success |
| `needs_review` | Ends in `needs_review` with two zones to accept |
| `fail_read` | Fails at the read step; full refund |
| `fail_render_partial` | Two parts fail; the chapter succeeds with warnings and a partial refund |
| `slow_queue` | Stays `queued` for about 2 minutes with a position and an ETA |
| `capacity_unavailable` | `start` returns `503 capacity_unavailable` |

```bash theme={null}
curl https://api.relettr.com/v1/test_helpers/balance \
  -H "Authorization: Bearer $RELETTR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"credits": 0}'
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.