# Create API key

> Creates a key. The `token` is returned only in this response, so store it securely.

Source: https://mailvina.com/docs/api-reference/api-keys/create-api-key · Base URL: https://api.mailvina.com · Guide: https://mailvina.com/docs/api-keys

`POST /api-keys`

**Body parameters**

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `name` | `string` | yes | A name to recognise the key, e.g. `Production`. |
| `permission` | `'full' \| 'sending_access'` | no | Default `full`. |
| `domain_id` | `string` | no | Limit the key to one sending domain. |

**Request**

```bash
curl -X POST 'https://api.mailvina.com/api-keys' \
  -H 'Authorization: Bearer mv_xxxxxxxxx' \
  -H 'Content-Type: application/json' \
  -d '{
  "name": "Production",
  "permission": "sending_access"
}'
```

```js
const res = await fetch('https://api.mailvina.com/api-keys', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.MAILVINA_API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    "name": "Production",
    "permission": "sending_access"
  }),
});
const data = await res.json();
```

```python
import os, requests

res = requests.post(
    "https://api.mailvina.com/api-keys",
    headers={"Authorization": f"Bearer {os.environ['MAILVINA_API_KEY']}"},
    json={
        "name": "Production",
        "permission": "sending_access"
    },
)
print(res.json())
```

**Response**

```json
{
  "id": "b6d24b8e-af0b-4c3c-be0c-359bbd97381e",
  "token": "mv_123456789_abcdefghijklmnop"
}
```

### The API key object

A key for the API and SMTP relay. Its token is only shown when it’s created.

**Fields**

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | `string` | no | Unique ID of the API key. |
| `name` | `string` | no | The name you gave it. |
| `permission` | `string` | no | `full` (every endpoint) or `sending_access` (only sending email). |
| `created_at` | `string` | no | When it was created (ISO 8601, UTC). |
| `last_used_at` | `string \| null` | no | When it was last used, to the minute. |
| `token` | `string` | no | Only in the create response: the secret key, starting with `mv_`. |
