# POST /v1/keys

> Create an API key. No key needed to call this.

Source: https://docs.invariant-ai.com/api/keys

`POST https://api.invariant-ai.com/v1/keys`

Creates a key for an email address and returns it once. We keep only its SHA-256 hash, so store the key when you get it.

```bash
curl -s -X POST https://api.invariant-ai.com/v1/keys \
  -H "Content-Type: application/json" \
  -d '{"email": "you@company.com", "name": "laptop"}'
```

```python
import requests

r = requests.post("https://api.invariant-ai.com/v1/keys",
                  json={"email": "you@company.com", "name": "laptop"}, timeout=30)
print(r.json()["key"])
```

Response 201:

```json
{
  "key": "ief_8cd6a1201bee09fc72e3053651b33f876feea6273de5fbd5",
  "key_id": "key_3f9a1c2b7d41",
  "key_prefix": "ief_8cd6a120",
  "email": "you@company.com",
  "name": "laptop",
  "created_at": "2026-11-22T04:10:00.000000+00:00"
}
```

Response 409:

```json
{
  "detail": {
    "error": "too_many_keys",
    "message": "you@company.com already has 5 active keys. Revoke one with DELETE /v1/keys/me first."
  }
}
```

Response 429:

```json
{
  "detail": {
    "error": "rate_limited",
    "message": "Too many keys created from this network. Try again later."
  }
}
```

## Body

| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| `email` | string | Yes | A valid email address. Stored lower-cased. |
| `name` | string | No | A label for the key, up to 64 characters. |

## Response

`201 Created`

| Key | Meaning |
| --- | --- |
| `key` | The API key. Shown only in this response. |
| `key_id` | Stable id for the key, safe to log. |
| `key_prefix` | First 12 characters of the key, safe to display. |
| `email`, `name`, `created_at` | What you sent, and when the key was made. |

> Shown once. We cannot show key again. If you lose it, create a new key and revoke the old one.

## Errors

| HTTP | `error` | When |
| --- | --- | --- |
| 400 | `invalid_request` | Missing or invalid email, or an unknown body key. |
| 409 | `too_many_keys` | The email already has 5 active keys. |
| 429 | `rate_limited` | 5 keys per hour from one network. See the `Retry-After` header. |
