# Create API key

`opensend.apiKeys.create(input)`

Creates an API key. The token is in this answer and is never shown again, so store it now. A key with sending access can be limited to one domain: it then sends from that domain only. With `mode: test` the key belongs to the sandbox: what it sends is simulated and reaches nobody.

Needs the scope: `api_keys:write`

## Input

- `name` (string, required): A name to recognise the key by, such as the app that uses it. Up to 120 characters.
- `access` (string): What the key may do: `full` for everything, `sending` for sending email and nothing else. Without it the key gets `sending`. One of: `full`, `sending`.
- `domainId` (string): The id of the one domain the key may send from. Only for a key with `sending` access. Up to 64 characters.
- `mode` (string): `live` for a key that sends real email. `test` for a key of the sandbox: every email it sends is simulated, reaches nobody and needs no verified domain. A test key always has `sending` access. Without it the key is `live`. One of: `live`, `test`.

## Returns

The call resolves to the answer, already parsed. A call the API refuses throws `OpenSendError` with the code and the message of the answer. [SDK](https://opensend.sh/docs/sdk) lists the errors of the client itself.

- `object` ("api_key"): Always `api_key`.
- `id` (string): The id of the key.
- `name` (string): The name you gave the key.
- `access` (string): What the key may do: `full` for everything, `sending` for sending email and nothing else. One of: `full`, `sending`.
- `mode` (string): `live` for a key that sends real email, `test` for a key whose emails are simulated and reach nobody. One of: `live`, `test`.
- `preview` (string): The start of the key, enough to recognise it.
- `domainId` (string | null): The id of the one domain a sending key may send from, or `null` when it may send from any.
- `domain` (string | null): The name of that domain, or `null`.
- `lastUsedAt` (string | null): When the key last made a request, or `null` if it never has.
- `createdAt` (string): When the key was made.
- `token` (string): The key itself. It is shown this once and cannot be read again.

## Example

TypeScript:

```ts
await opensend.apiKeys.create({
  name: 'Marketing site',
  access: 'sending',
})
```

CLI:

```bash
opensend api-keys create --name 'Marketing site' --access sending
```

Answer:

```json
{
  "object": "api_key",
  "id": "key_05",
  "name": "Marketing site",
  "access": "sending",
  "mode": "live",
  "preview": "os_...9b10",
  "domainId": null,
  "domain": null,
  "lastUsedAt": null,
  "createdAt": "2026-11-27T09:30:00.000Z",
  "token": "os_08d12dfda708a7ae4540215fe3779b10"
}
```
