---
title: "Rotate a key's token"
method: POST
path: "/api_keys/{id}/rotation"
tags: ["API Keys"]
---

# Rotate a key's token

`POST /api_keys/{id}/rotation`

## Request

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

Issues a new token for the key. The old token stops working immediately. The key keeps its ID, name and limit.
If the key belongs to a Shopify, BigCommerce or WordPress Connect integration, the response includes
`integration_warning`: that integration stops working until it reconnects.

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

## Path parameters

- `id` integer, required

## Headers

- `Idempotency-Key` string

## Response `200`

The key with its new token.

- ApiKeyWithWarning: 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
  - `integration_warning` string: Present only for keys that belong to a Shopify, BigCommerce or WordPress Connect integration. The integration stops working until it reconnects with a new key.

## 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.
- `404`: No manageable key with that ID on this account. `error_code` is `not_found`. Full-access keys, MCP connection keys and the Webflow Designer key are never found here.
- `409`: `key_revoked`: a revoked key can't be rotated. `request_in_progress`: a request with this `Idempotency-Key` is still being processed. `idempotent_replay_superseded`: the key was rotated again or revoked after the original request.
- `422`: `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)
