# Authentication, API keys and test mode

> How requests are authenticated: secret, restricted and publishable keys, scopes, rolling and revoking keys, API versions, and what test mode does differently from live mode.

Every request to the API carries an API key in the `Authorization` header:

```http
Authorization: Bearer mv_live_sk_…
```

The key says which organisation the request acts for, what it may do (its **scopes**) and whether it works on real calls (**live mode**) or simulated ones (**test mode**). Requests go over HTTPS only. The API doesn't accept the dashboard's session cookies: a request without a key answers `401` with the code [`api_key_missing`](https://docs.morevoice.ai/guides/errors-and-limits/#api-key-missing).

**cURL**

```sh
# Check the key: which organisation, which mode, which scopes.
curl https://api.morevoice.ai/v1/whoami \
  -H "Authorization: Bearer $MOREVOICE_API_KEY"
```

**Node.js**

```ts title="check-key.ts"
import MoreVoice from "@morevoice/sdk";

const mv = new MoreVoice(); // reads MOREVOICE_API_KEY

// Check the key: which organisation, which mode, which scopes.
const me = await mv.whoami.retrieve();
console.log(`${me.org_id} · ${me.livemode ? "live" : "test"} mode · API version ${me.api_version}`);
```

**Python**

```python title="check_key.py"
import os

import requests

API = "https://api.morevoice.ai/v1"
HEADERS = {"Authorization": f"Bearer {os.environ['MOREVOICE_API_KEY']}"}

# Check the key: which organisation, which mode, which scopes.
response = requests.get(f"{API}/whoami", headers=HEADERS, timeout=30)
response.raise_for_status()
me = response.json()
mode = "live" if me["livemode"] else "test"
print(f"{me['org_id']} · {mode} mode · API version {me['api_version']}")
```

`GET /v1/whoami` is the quickest check of a key: it answers with the organisation, the key's ID, its mode, its scopes and the API version.

## Key types

| Type | Looks like | For | Can do |
| --- | --- | --- | --- |
| **Secret** | `mv_live_sk_…` / `mv_test_sk_…` | Your own backend | Everything (scope `*`). |
| **Restricted** | `mv_live_sk_…` / `mv_test_sk_…` | Integrations and third parties | Only the scopes you pick. |
| **Publishable** | `mv_live_pk_…` / `mv_test_pk_…` | A web page | Only start web calls (`web_calls:write`), only from the websites you list. |

After the prefix comes a 32-character random body (letters and digits). The format is fixed, so you can look for leaked keys by pattern: `mv_(live|test)_(sk|pk)_[0-9A-Za-z]{32}`.

> **Secret and restricted keys belong on a server**
>
> Never put one in a web page, a mobile app or a repository: anyone who sees it can act for your organisation. The SDK refuses a secret key in a browser. If a key leaks, [roll it](#rolling-a-key) at once.

> **Publishable keys start web calls**
>
> A web page uses a publishable key to start a call to a public assistant with `POST /v1/web_calls`, and gets a single-use client token for the browser: see the [web widget](https://docs.morevoice.ai/guides/web-widget/). A publishable key works only from the websites you list for it.

## Create a key

Keys are created in the dashboard by an administrator or the owner of the organisation:

1. Open **Developers › API keys** and choose the mode: **Live** or **Test**.
2. Select **Create key** (or **Create test key**), name it after where it will be used (for example "Production backend"), and pick the **Key type**.
3. For a restricted key, pick its **Permissions**: start from a preset and adjust. You can't grant permissions your own role doesn't have.
4. Optionally, under **Advanced: IP allow-list and expiry**, limit the IP addresses or ranges (CIDR) the key works from, and set an expiry date (up to 3 years).
5. Copy the key. **It is shown once**: MoreVoice stores only a hash of it. **Copy as .env line** gives you `MOREVOICE_API_KEY=…` ready to paste.

Creating and rolling a key asks you to confirm your password. Every new, rolled or revoked key is announced to the organisation's administrators in the dashboard, and new and rolled keys by email too. The key list shows when each key was last used and from which IP address.

## Scopes

A restricted key can do only what its scopes allow. A `:write` scope includes the matching `:read` one, and a secret key holds `*`, every scope. A request without the scope it needs answers `403` with the code [`missing_scope`](https://docs.morevoice.ai/guides/errors-and-limits/#missing-scope), and `details.required_scope` names the scope.

| In the dashboard | Scopes | Note |
| --- | --- | --- |
| Assistants | `assistants:read`, `assistants:write` |  |
| Voices | `voices:read` |  |
| Custom tools | `tools:write` |  |
| Flows | `flows:read`, `flows:write` |  |
| Calls | `calls:read`, `calls:write` |  |
| Recordings | `recordings:read` |  |
| Transcripts | `transcripts:read` |  |
| Web calls | `web_calls:write` |  |
| SIP connections | `connections:read`, `connections:write` |  |
| Phone numbers | `phone_numbers:read`, `phone_numbers:write` |  |
| Inbound routes | `inbound_routes:read`, `inbound_routes:write` |  |
| Campaigns | `campaigns:read`, `campaigns:write` |  |
| Contacts | `contacts:read`, `contacts:write` |  |
| Queues | `queues:read`, `queues:write` |  |
| Users | `users:read`, `users:write` |  |
| Teams | `teams:read`, `teams:write` |  |
| Agent status | `agents:read` |  |
| Knowledge base | `kb:read`, `kb:write` |  |
| Copilot profiles | `copilot:read`, `copilot:write` |  |
| Quality scores | `qa:read`, `qa:write` |  |
| Insights | `insights:read` |  |
| Callbacks | `callbacks:read`, `callbacks:write` |  |
| Conference rooms | `conference:read`, `conference:write` |  |
| Audio files | `audio_assets:read`, `audio_assets:write` |  |
| Secrets | `secrets:read`, `secrets:write` | Organisation administration |
| Do-not-call list | `dnc:read`, `dnc:write` |  |
| Consents | `consents:read`, `consents:write` |  |
| Webhooks | `webhooks:read`, `webhooks:write` |  |
| Events | `events:read` |  |
| Usage | `usage:read` |  |
| Billing | `billing:read`, `billing:write` | Organisation administration |
| Organization settings | `org:read`, `org:write` | Organisation administration |
| Members | `members:read`, `members:write` | Organisation administration |
| API keys | `api_keys:read`, `api_keys:write` | Organisation administration |
| Audit log | `audit:read` | Organisation administration |
| Security settings | `security:write` | Organisation administration |
| Client organizations | `children:read`, `children:write` | Organisation administration |
| Agent sign-in sessions | `agent_sessions:read`, `agent_sessions:write` | Organisation administration |
| Faxes | `faxes:read`, `faxes:write` |  |
| Speech (transcription, voice notes) | `speech:write` |  |
| Verified caller IDs | `caller_ids:read`, `caller_ids:write` |  |
| Number porting | `ports:read`, `ports:write` |  |
| Uploaded documents | `files:read`, `files:write` |  |
| Live supervision (listen, whisper, barge) | `supervision:write` |  |

The dashboard offers presets to start from:

| Preset | For | Scopes |
| --- | --- | --- |
| Read only | Reads everything except organisation administration. | Every `:read` scope above but organisation administration (31) |
| Campaigns integration | Pushes contacts into campaigns, follows their results and keeps consent and the do-not-call list in sync. | `assistants:read`, `calls:read`, `recordings:read`, `transcripts:read`, `campaigns:write`, `contacts:write`, `dnc:write`, `consents:write`, `webhooks:write`, `events:read` |
| CRM integration | A CRM that places and logs calls: click-to-call, call history, callbacks and contacts. | `assistants:read`, `calls:write`, `recordings:read`, `transcripts:read`, `contacts:write`, `queues:read`, `users:read`, `callbacks:write`, `webhooks:write`, `events:read` |

The scope list is fixed for the life of the API, so a restricted key you create today keeps working as the API grows.

## Rolling a key

**Roll key** replaces a key with a new one that has the same name, scopes and allow-lists. Choose how long the old key keeps working, so you can deploy the new one first: **Stop it now**, **1 hour**, **24 hours** or **7 days**. After that the old key answers `401` with the code [`key_expired`](https://docs.morevoice.ai/guides/errors-and-limits/#key-expired).

## Revoking a key

**Revoke** stops a key immediately and for good: its requests answer `401` with the code [`key_revoked`](https://docs.morevoice.ai/guides/errors-and-limits/#key-revoked). To change a restricted key's scopes, create a new key and revoke the old one.

## When a key is refused

| HTTP | Code | Why |
| --- | --- | --- |
| 401 | [`api_key_missing`](https://docs.morevoice.ai/guides/errors-and-limits/#api-key-missing) | No `Authorization: Bearer` header. |
| 401 | [`invalid_api_key`](https://docs.morevoice.ai/guides/errors-and-limits/#invalid-api-key) | The key is malformed or doesn't exist. |
| 401 | [`key_revoked`](https://docs.morevoice.ai/guides/errors-and-limits/#key-revoked) / [`key_expired`](https://docs.morevoice.ai/guides/errors-and-limits/#key-expired) | The key was revoked, expired, or replaced by a roll. |
| 401 | [`ip_not_allowed`](https://docs.morevoice.ai/guides/errors-and-limits/#ip-not-allowed) | The request came from outside the key's IP allow-list. |
| 403 | [`missing_scope`](https://docs.morevoice.ai/guides/errors-and-limits/#missing-scope) | The key lacks the scope this endpoint needs. |
| 403 | [`test_mode_disabled`](https://docs.morevoice.ai/guides/errors-and-limits/#test-mode-disabled) | A test key, but test mode isn't on for the organisation yet. |
| 403 | [`livemode_mismatch`](https://docs.morevoice.ai/guides/errors-and-limits/#livemode-mismatch) | A test key used on a live object, or the other way round. |
| 403 | [`publishable_key_not_allowed`](https://docs.morevoice.ai/guides/errors-and-limits/#publishable-key-not-allowed) | A publishable key on an endpoint meant for servers. |

Every error has the same shape; see [errors, rate limits and concurrency](https://docs.morevoice.ai/guides/errors-and-limits/).

## Test mode and live mode

Test keys (`mv_test_…`) run the same API on simulated calls: a virtual carrier instead of the phone network, simulated speech and AI, and no billing. Calls, campaigns, contacts, events and webhook endpoints are separate in each mode (every object has a `livemode` field), while assistants, flows and inbound routes are shared. [Test mode](https://docs.morevoice.ai/get-started/test-mode/) explains what is simulated, the test numbers and the limits.

## API versions

The API changes in dated versions, like `2026-11-01`. A key is pinned to the version that was current when you created it (the key's details show it), so new versions never change the answers your code gets. To try a newer version, send it in the `MoreVoice-Version` header, one request at a time:

**cURL**

```sh
# Answer this request in a given API version, whatever the key is pinned to.
curl https://api.morevoice.ai/v1/whoami \
  -H "Authorization: Bearer $MOREVOICE_API_KEY" \
  -H "MoreVoice-Version: 2026-11-01"
```

**Node.js**

```ts title="api-version.ts"
import MoreVoice from "@morevoice/sdk";

// The SDK sends the API version its types describe on every request. Pass `version` to choose
// another one, or `version: null` to use the version the key is pinned to.
const mv = new MoreVoice({ version: "2026-11-01" });

// Or for one request only:
const me = await mv.whoami.retrieve({ headers: { "MoreVoice-Version": "2026-11-01" } });
console.log(me.api_version);
```

**Python**

```python title="api_version.py"
import os

import requests

API = "https://api.morevoice.ai/v1"
HEADERS = {"Authorization": f"Bearer {os.environ['MOREVOICE_API_KEY']}"}

# Answer this request in a given API version, whatever the key is pinned to.
response = requests.get(
    f"{API}/whoami",
    headers={**HEADERS, "MoreVoice-Version": "2026-11-01"},
    timeout=30,
)
response.raise_for_status()
print(response.json()["api_version"])
```

Every response carries the `MoreVoice-Version` it was answered in. A date that isn't a version answers `400` with the code [`unknown_version`](https://docs.morevoice.ai/guides/errors-and-limits/#unknown-version). Changes that don't break your code (new endpoints, new optional fields, new event types, new values of an enumeration) come in every version; see the [versioning policy](https://docs.morevoice.ai/changelog/versioning/).

## Request IDs

Every response has an `X-Request-Id` header (`req_…`), and every error repeats it as `request_id`. Log it with your own request: it is the fastest way for us to find a request when you contact support.
