> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.divert.ly/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.divert.ly/_mcp/server.

# Authentication

> Authenticate to the Divertly API with an API key or session token. Credential format, roles, and a working curl example.

The API accepts two kinds of credentials, depending on who — or what — is making the request.

| Credential    | Sent as                                               | Used by                                   | Rate limited?            |
| ------------- | ----------------------------------------------------- | ----------------------------------------- | ------------------------ |
| Session token | `Authorization: Bearer <token>` (or a session cookie) | The Divertly dashboard, after you sign in | Yes, 60 calls per minute |
| API key       | `Authorization: Key <base64(keyId:secret)>`           | Your own code, scripts, and integrations  | Yes, by plan             |

A session token is issued when you sign in to the dashboard, and the dashboard manages it for you — you never need to construct one yourself. If you're calling the API from your own code, use an API key instead. See [Rate Limits & Errors](/docs/developers/rate-limits-errors) for current limits.

## Authenticate with an API key

An API key has two parts: a **key ID**, which identifies the key, and a **secret**, which proves you hold it. To authenticate a request, join the two with a colon, base64-encode the result, and send it in the `Authorization` header with the `Key` scheme:

```
Authorization: Key <base64("keyId:secret")>
```

> **Warning**
>
> The secret is shown once, at the moment you create the key, and can't be retrieved afterward. Store it somewhere safe before you close the dialog. If you lose it, delete the key and create a new one.

For instructions on creating and managing keys, see [Managing API Keys](/docs/organization/managing-api-keys).

Here's a complete example. Given a key ID of `k_9f2a` and a secret of `s3cr3t-value`:

```bash
CREDENTIAL=$(printf '%s' "k_9f2a:s3cr3t-value" | base64)

curl https://api.divert.ly/v1/domains \
  -H "Authorization: Key $CREDENTIAL"
```

## Confirm your credential works

Call `GET /v1/whoami` to resolve a credential to the organization (and, for a session token, the user) it belongs to:

```bash
curl https://api.divert.ly/v1/whoami \
  -H "Authorization: Key $CREDENTIAL"
```

An API key resolves to its organization only — there's no user attached to it, since a key represents an integration rather than a person.

If the credential is missing, malformed, or invalid, every endpoint returns the same error shape, described in [Rate Limits & Errors](/docs/developers/rate-limits-errors).

## Roles

Every API key and user is assigned a role — Super Admin, User, Billing Admin, or Read Only. Roles are enforced for both users and API keys: a request whose role doesn't permit the action is refused with `403 Forbidden`. A key can't be issued with a role higher than the role of whoever creates it. See [Managing Users](/docs/organization/managing-users#roles) for the role names, and [Managing API Keys](/docs/organization/managing-api-keys) for how to assign one when you create a key.

To see which role names your organization can assign, call:

```bash
curl https://api.divert.ly/v1/organizations/{org_id}/roles \
  -H "Authorization: Key $CREDENTIAL"
```