# API keys

List, create, rotate and revoke the API keys on your account.

> **Session required for changes**
>
> Listing keys works with an API key. Creating, rotating or revoking keys requires a signed-in dashboard session (cookie plus CSRF token), so a leaked key can never mint replacements for itself. Calls from an API key receive `403 key_management_requires_session`.

## The key object

```json
{
  "id": "5d1c4c2e-...",
  "object": "api_key",
  "name": "production backend",
  "prefix": "sk-vh7vSQ",
  "status": "active",
  "created_at": "2026-09-15T17:30:00.000Z",
  "expires_at": null,
  "last_used_at": "2026-09-15T17:39:33.071Z",
  "revoked_at": null,
  "total_requests": 12840
}
```

- `prefix` (string): The first characters of the key, for telling keys apart. The full key is only ever returned once, on creation or rotation.
- `status` (string): `active`, `revoked` or `expired`.
- `expires_at` (string | null): Keys with an expiry stop authenticating at that instant and are marked `expired`.

## List keys

**`GET /v1/api-keys`**

Returns all keys on the account, including revoked and expired ones, as `{ "object": "list", "data": [...] }`.

## Create a key

**`POST /v1/api-keys`**

- `name` (string, required): Label shown in the dashboard. 1–80 characters.
- `expires_at` (string): ISO-8601 timestamp in the future.
- `expires_in_days` (integer): Alternative to `expires_at`; 1–3650 days.

Returns `201` with the key object plus a one-time `key` field containing the full `sk-...` secret. Store it immediately; it cannot be retrieved again. Your plan's `max_api_keys` limit applies to active keys, and at most 20 keys can be created per hour.

In the [dashboard](https://claudech.com/api-keys), the full key appears in a **copy-once** dialog after you click **Create key** (or **Rotate**). Dismiss it only after you have saved the secret.

**Base URLs** (same key everywhere): OpenAI-format clients use `https://api.claudech.com/v1`; Claude Code and the Anthropic SDK use `https://api.claudech.com` (see [Integrations](https://claudech.com/docs/integrations)).

```json
{
  "id": "5d1c4c2e-...",
  "object": "api_key",
  "name": "production backend",
  "prefix": "sk-vh7vSQ",
  "status": "active",
  "created_at": "2026-09-15T17:30:00.000Z",
  "expires_at": null,
  "last_used_at": null,
  "revoked_at": null,
  "total_requests": 0,
  "key": "sk-vh7vSQFEbcSHcqxg2spzjYhKCda6Kn1JUGhWIFwTaNevXQ7g"
}
```

## Rotate a key

**`POST /v1/api-keys/{id}/rotate`**

Creates a new key with the same name and expiry, revokes the old one, and returns the new key object with its one-time `key` field (`201`). Requests using the old key fail from that moment, so deploy the new secret first and rotate immediately after.

## Revoke a key

**`DELETE /v1/api-keys/{id}`**

Permanently disables the key and returns the key object with `"deleted": true`. Revocation takes effect immediately, including for in-flight streams that have not yet started.

## Examples

Because writes need a browser session, the practical way to manage keys programmatically is from a signed-in dashboard context. Reads work with any key:

**curl**

```bash
curl https://api.claudech.com/v1/api-keys \
  -H "Authorization: Bearer $CLAUDECH_API_KEY"
```

**JavaScript**

```javascript
const res = await fetch('https://api.claudech.com/v1/api-keys', {
  headers: { authorization: `Bearer ${process.env.CLAUDECH_API_KEY}` },
});
const { data } = await res.json();
for (const k of data) console.log(k.name, k.prefix, k.status, k.last_used_at);
```

Key creation, rotation and revocation are recorded in your account's audit trail, and every newly issued key is confirmed by email to the account address.

---

Source: https://claudech.com/docs/api/api-keys
