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

# API Keys

> Key roles (ADMIN and API), the optional restrictions you can set on each key (expiration, spend limit and IP allowlist), and managing keys via the API.

Every request is authenticated with an API key sent in the `Authorization: Bearer <API_KEY>` header. Create and manage keys in **Dashboard → Settings → API Keys**. Give each project, teammate or end customer its own key, scoped to exactly what it needs: what it may do, for how long, how much it may spend, and where it may be called from.

A key looks like `sk-dp-<id>-<secret>`. Use it as is everywhere: the native API, the [OpenAI-compatible endpoint](https://docs.deapi.ai/openai-compatibility.md), the [MCP server](https://docs.deapi.ai/execution-modes-and-integrations/mcp-server.md) and WebSockets. Keys created before this format look like `<id>|<secret>` and keep working unchanged.

## Key roles

Every key has one of two roles, chosen when the key is created. The role cannot be changed later — to change it, create a new key.

* **API key** — runs inference (images, video, audio, …). It has no access to account billing or to other keys: for example, [Check Balance](https://docs.deapi.ai/api/v2/utilities/balance.md) returns `403` `insufficient_permissions`. Use it for applications, integrations and keys you hand out per project or per end customer.
* **ADMIN key** — full access to the account: inference, account billing and key management.

> [!WARNING]
>
> Keys created before roles were introduced are **ADMIN** keys, so existing integrations keep working unchanged. If a key only needs to run inference, replace it with a new API key and delete the old one.

> [!TIP]
>
> Treat an ADMIN key like a password: keep it server-side and never ship it in client apps. Use API keys everywhere else.

## Key restrictions

Each key can carry any combination of the restrictions below — set them when creating the key or change them later. Changes apply from the next request; there is no need to recreate the key.

| Restriction | What it does | Default |
| - | - | - |
| **Expiration date** | The key stops working after this date. Presets: 1 hour, 1 day, 7, 30, 90 or 180 days, 1 year, or a custom date. Extending the date brings an expired key back. | No expiration |
| **Spend limit (USD)** | Hard cap on what the key may spend. Once reached, the key rejects new jobs until the limit resets or is raised. | No limit |
| **Reset window** | How often the spend counter returns to zero: never, daily, weekly or monthly. Windows run in UTC and are anchored to the moment the key was created. | Never |
| **IP allowlist** | The key works only from the listed IPv4/IPv6 addresses or CIDR ranges (up to 20 entries). | Any IP |

Good to know about the spend limit:

* **Changing the limit does not reset the counter.** Raising a limit from \$50 to \$100 after spending \$50 leaves \$50 of headroom. Lowering it below the amount already spent blocks the key until the window resets.
* **A limit is a ceiling, not a budget.** A key never spends more than the account balance, and the limits of all keys together may exceed it.
* A refunded (failed) job gives its cost back to the key's limit.

Rejected requests — expired, disabled, outside the allowlist or over the limit — do not create a job and are not charged.

## Number of keys

An account can have up to **100 active keys**. Expired, disabled and deleted keys do not count — disabling a key frees its slot immediately.

## Managing keys via the API

Everything you can do with keys in the Dashboard can also be done over the API, using the same `Authorization: Bearer <API_KEY>` header. All paths below are relative to `https://api.deapi.ai`.

### Any key: inspect itself

Both roles can read their own state and usage:

| Endpoint | What it returns |
| - | - |
| [`GET /api/v2/key`](https://docs.deapi.ai/api/v2/keys/get-current-key) | The calling key: name, preview, role, status (`active`, `revoked` — disabled — or `expired`), creation and expiration dates, spend limit and reset window, spend in the current window, remaining amount, next reset, and whether an IP allowlist is on and how many entries it has. The secret is never returned. |
| [`GET /api/v2/key/usage`](https://docs.deapi.ai/api/v2/keys/get-current-key-usage) | The calling key's usage over a time window: cost, number of requests and number of errors. Takes `from`, `to` and `group_by` (`day`, `hour`, `type` or `model`). It shows nothing about other keys or the account balance. |

```bash theme={null}
curl https://api.deapi.ai/api/v2/key \
  -H "Authorization: Bearer $DEAPI_KEY"
```

This lets an application check how much of its limit is left, or when the limit resets, before it sends a job.

### ADMIN key: manage all keys

An ADMIN key can also manage every key on the account. An API key gets `403` `insufficient_permissions` on all of these endpoints.

| Endpoint | What it does |
| - | - |
| [`GET /api/v2/keys`](https://docs.deapi.ai/api/v2/keys/list-keys) | Lists the account's keys: id, name, preview, role, status, spend limit and window, spend in the current window, expiration date, number of allowlist entries and last use. Secrets are never returned. |
| [`POST /api/v2/keys`](https://docs.deapi.ai/api/v2/keys/create-key) | Creates an **API** key. Takes a name, expiration date, spend limit, reset window and IP allowlist. Creating an ADMIN key this way is rejected with `403`. |
| [`GET /api/v2/keys/{id}`](https://docs.deapi.ai/api/v2/keys/get-key) | Details of one key: the same fields as `GET /api/v2/key`. |
| [`PATCH /api/v2/keys/{id}`](https://docs.deapi.ai/api/v2/keys/update-key) | Changes the spend limit, reset window, expiration date or IP allowlist, or disables / re-enables the key. The role cannot be changed. |
| [`DELETE /api/v2/keys/{id}`](https://docs.deapi.ai/api/v2/keys/delete-key) | Deletes the key permanently. Its past usage stays in usage reports. |
| [`GET /api/v2/keys/{id}/usage`](https://docs.deapi.ai/api/v2/keys/get-key-usage) | Usage of one key, with the same parameters as `GET /api/v2/key/usage`. |

> [!WARNING]
>
> The secret of a new key is returned **only once**, in the response to `POST /api/v2/keys`. No other endpoint returns it. Store it straight away; if it is lost, create a new key and delete the old one.

Creating keys is rate-limited. Too many in a short time returns `429` `rate_limited`.

### ADMIN key: account billing and usage

| Endpoint | What it returns |
| - | - |
| [`GET /api/v2/account`](https://docs.deapi.ai/api/v2/account/get-account) | Account billing: balance, currency, auto top-up status, top-up threshold and top-up amount. |
| [`GET /api/v2/account/usage`](https://docs.deapi.ai/api/v2/account/usage) | Usage of the whole account over a time window — the same data as the Usage screen in the Dashboard. Takes `from`, `to` and `group_by` (`day`, `hour`, `key`, `type` or `model`). |
| [`GET /api/v2/account/payments`](https://docs.deapi.ai/api/v2/account/payments) | History of payments and top-ups. |

With `group_by=key`, each group's `key` is one of:

* **a number** — the id of an existing key,
* `panel` — jobs started from the Dashboard itself, such as the Playground (`name: "Panel"`),
* `deleted` — all keys that have since been deleted, combined (`name: "Deleted keys"`),
* `null` — requests with no usage log, where the source is unknown.

## Error codes

Key-related rejections carry a machine-readable `code` field next to `message`:

| HTTP | `code` | When |
| - | - | - |
| `401` | `missing_key` | The request has no `Authorization` header. |
| `401` | `invalid_key` | The key does not exist or is malformed. |
| `401` | `key_expired` | The key's expiration date has passed. |
| `401` | `key_revoked` | The key was disabled in the Dashboard or via the API. |
| `402` | `key_limit_exceeded` | The key's spend limit is used up. The response also carries `limit`, `used`, `remaining` and `resets_at` (the next reset, or `null` if the limit never resets). |
| `403` | `ip_not_allowed` | The request came from an address outside the key's IP allowlist. |
| `403` | `insufficient_permissions` | An API key called an endpoint that requires an ADMIN key, such as the account balance or key management. |
| `422` | `active_key_limit_reached` | Creating or re-enabling a key over the API would exceed the limit of 100 active keys. |
| `422` | `insufficient_balance` | The account balance is too low. Top up and retry the same request. |
| `429` | `rate_limited` | Too many requests, or too many keys created in a short time. |


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