---
title: "Create an API key"
method: POST
path: "/api_keys"
tags: ["API Keys"]
---

# Create an API key

`POST /api_keys`

## Request

- Base URL: `https://alttext.ai/api/v1`
- URL: `https://alttext.ai/api/v1/api_keys`
- Auth: API key in header `X-API-Key`

Creates a `site` key and returns its token. Keys made through the API always have `origin` `api`.
A key's kind can't be set through the API: sending `kind` returns `422` `invalid_params`. Full-access keys are created in the dashboard only.

An account can have up to 10,000 active site keys. Past that, creating returns `422` `site_key_cap_reached`.
The name of a connected integration, such as the Webflow Designer key or a connected Shopify store, is reserved: `422` `reserved_name`.

Send an `Idempotency-Key` header to retry safely.

## Headers

- `Idempotency-Key` string

## Request body

- ApiKeyCreate
  - `name` string, required: A name for the key. Required.
  - `usage_limit` integer, nullable: [optional] The recorded-usage threshold that stops new requests this billing period. In-flight work can still be charged beyond it. Omit or send `null` for no limit.

## Response `201`

The new key, with its token.

- ApiKey: An API key. The API Keys endpoints list and manage `site` keys. Full-access keys, MCP connection keys and the Webflow Designer key are never returned.
  - `id` integer
  - `name` string
  - `kind` 'site': Always `site` here. Full-access keys are created and managed in the dashboard only.
  - `origin` 'unknown' | 'dashboard' | 'api' | 'shopify' | 'bigcommerce' | 'wordpress_connect': Where the key was created.
  - `integration` 'shopify' | 'bigcommerce' | 'wordpress_connect' | 'null', nullable: The integration that created and uses this key, or `null`. Rotating or revoking an integration key stops that integration until it reconnects.
  - `status` 'active' | 'revoked'
  - `token` string, nullable: The key's token, or `null` once the key is revoked or when an assistant connection without write access reads it. Tokens begin with `atai_`. Keys created before that format existed keep their original tokens, which stay valid. Treat the token as a secret.
  - `token_hint` string, nullable: The last four characters of the token, or `null` once the key is revoked.
  - `usage_limit` integer, nullable: The recorded-usage threshold that stops new requests this billing period. In-flight work can still be charged beyond it. `null` means no limit.
  - `credits_used` integer: Credits this key has used this period, counted against `usage_limit`.
  - `billable_credits` integer: Every credit charged to the account through this key this period, whether or not the charge crossed the key's limit.
  - `billable_complete` boolean: Whether every charge in the current period was tracked by the billing-aware release after the operator's verified old-task drain cutoff. False when tracking is incomplete or the cutoff is absent.
  - `period_start` string, date-time, nullable: When the current period started, if the key has been reset.
  - `resets_at` string, date-time, nullable: When the account's current billing period ends, or `null` when it has no active subscription with a renewal date.
  - `previous_period` ApiKeyPreviousPeriod: The credits billed through the key in its last closed period. `null` until the key has had a reset or been revoked.
    - `billable_credits` integer: Every credit charged to the account through this key during that period, whether or not the charge crossed the key's limit.
    - `billable_complete` boolean: `false` when the period started or was recorded before billable credits were tracked, so the number can be low.
    - `recorded_at` string, date-time: When the period closed.
  - `created_by` ApiKeyCreator: Who created the key, from the audit trail. `null` for keys that predate the audit trail.
    - `type` 'user' | 'api_key' | 'mcp_connection' | 'system'
    - `name` string, nullable
  - `created_at` string, date-time
  - `last_used_at` string, date-time, nullable
  - `revoked_at` string, date-time, nullable

## Other responses

- `403`: The request was refused. `error_code` is one of: - `invalid_api_key`: the `X-API-Key` header is missing or doesn't match a key. - `api_key_revoked`: the key was revoked. Create a new key. - `full_access_required`: managing keys needs a full-access key. Create one in the dashboard under Account > API Keys. - `insufficient_scope`: an assistant connection lacks the Manage API keys permission (`required_scope` is `mcp:keys`), or read-only access when changing keys or revealing a token (`mcp:write`). Reconnect with the permission. - `credential_no_longer_authorized`: the account closed or the calling credential lost authority before the mutation acquired its lock. Reconnect or use a current full-access key. - `out_of_scope`: this key can't be used for this request.
- `409`: `request_in_progress`: a request with this `Idempotency-Key` is still being processed. Retry in a few seconds. `idempotent_replay_superseded`: the key was rotated or revoked after the original request, so its token can't be replayed. The body carries `api_key_id` and `status` (`rotated` or `revoked`).
- `422`: `error_code` is one of `invalid_params` (blank or too long name, negative limit, or `kind` sent), `reserved_name`, `site_key_cap_reached`, or `idempotency_key_reused` (this `Idempotency-Key` was already used for a different request).
- `429`: Too many key requests for this account. The limit is 120 reads and 30 changes per minute, counted per account across all the API Keys endpoints. Wait `Retry-After` seconds. `error_code` is `rate_limited`.

---

[API](https://skmtc.dev/alttext/apis/alttext-ai-api.md) · [All operations](https://skmtc.dev/alttext/apis/alttext-ai-api/llms.txt) · [OpenAPI document](https://skmtc.dev/alttext/apis/alttext-ai-api/revisions/6eb62e8e450c?raw)
