# Authentication

> Authenticate to the Duty API with a workspace API key, choose its scopes and keep it safe.

Every call carries an API key in the `Authorization` header:

```http
Authorization: Bearer gm_sd_…
```

A call without a key, or with a key that is unknown, revoked or expired, answers `401`. See [Errors](/en/api/errors/).

## API keys

Administrators create keys in the Duty portal under **Integrations → Keys and webhooks**. A key:

- **belongs to one workspace** and only reads and changes requests there;
- **is shown once**, when it is created. Duty stores only a digest, so a lost key cannot be recovered: create a new one and revoke the old;
- **can expire** on a date you choose, and **can be revoked** at any moment, which takes effect on the next call;
- shows its prefix (`gm_sd_ab12…`) and when it was last used, so you can tell keys apart without exposing them.

Create one key per integration. If one leaks, you revoke only that one.

## Scopes

A key has one or more scopes. A call that needs a scope the key lacks answers `403` with `API_KEY_SCOPE_MISSING`.

| Scope | Allows |
| --- | --- |
| `read` | Read catalogs, requests, comments and attachments. Every key has it. |
| `write` | Open requests, change their status or priority, comment and upload attachments. |
| `webhooks` | Create, change and delete webhooks, and read their deliveries. |

Each endpoint in the reference shows the scope it needs.

## What else is checked

On every call the API also checks the workspace, not only the key:

- the organization must be **active**;
- its plan must include **API access** (`API_ACCESS_NOT_INCLUDED` otherwise);
- with a payment **more than 7 days overdue**, the API keeps answering reads but refuses changes with `SUBSCRIPTION_READ_ONLY`.

## Keep keys safe

<Aside type="caution">Never put a key in a browser app, a mobile app or a public repository. Anyone who has it acts on your workspace.</Aside>

- Call the API from your servers, and read the key from an environment variable or a secret manager.
- Give each key only the scopes it needs: a reporting job needs `read` only.
- Set an expiry date for temporary integrations.
- Revoke keys you no longer use. The portal shows when each key was last used.

<Aside type="note">The **API key** button of this site keeps your key in your browser only (for this tab, or on this device if you choose so). Playground calls go straight from your browser to the API.</Aside>
