# Model API keys

Language models are paid for at their provider through an **API key**. draften
keeps keys on three levels, and the assistant takes the nearest one.

## Three levels

| Level | Where | Who manages it |
|---|---|---|
| mailbox | the mailbox's page → API keys of the mailbox | the mailbox owner |
| organisation | Organisation → API keys of the organisation | the organisation's owners and managers |
| operator (default) | Installation → Default API keys | the draften operator |

An assistant without its own choice uses the **inherited key**: the nearest
active key of the default API — the mailbox's first, then the organisation's,
then the operator's. In the assistant's Settings → **Models and keys** a
specific key and model can be chosen per task (triage, drafting, learning).

## Providers

- **Anthropic** (default) — console.anthropic.com → API Keys.
- **OpenAI** — the instructions were tuned on Claude models; before switching
  to OpenAI, try it on the trial set. With sensitive data, check OpenAI's data
  retention terms.
- **OpenAI-compatible (local model)** — Ollama, LM Studio, llama.cpp, vLLM and
  the like. Mail then never leaves your server. Only the operator may enter
  such a key (it carries the server address); organisations and mailboxes
  inherit it.

## Adding a key

Choose the API, enter a **name** ("company Anthropic account", say) and the
**key** (the whole one, `sk-…`). The key is stored encrypted and never shown
again — the list shows only its ending. A key can be **switched off**,
**switched on** and **deleted**; a key that an assistant names in its settings
cannot be deleted (change it there first, or just switch the key off).

Storing keys requires the server to have `MASTER_KEY` set.

## Costs

We recommend setting a monthly spend limit right at the provider (in the
console for Anthropic) in case something loops. In draften, each assistant also
has a daily cost cap — see [Cost and caps](/en/admin/cost-and-caps).
