> ## Documentation Index
> Fetch the complete documentation index at: https://docs.adrelay.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Rotate API Key

> Rotate your API key. The previous key is immediately invalidated.

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST "https://api.adrelay.dev/v1/api-keys/rotate" \
    -H "X-API-Key: $ADRELAY_API_KEY"
  ```

  ```javascript Node.js theme={null}
  const response = await fetch("https://api.adrelay.dev/v1/api-keys/rotate", {
    method: "POST",
    headers: { "X-API-Key": process.env.ADRELAY_API_KEY },
  });

  const data = await response.json();
  // Store data.api_key securely -- it won't be shown again
  ```

  ```python Python theme={null}
  import requests

  response = requests.post(
      "https://api.adrelay.dev/v1/api-keys/rotate",
      headers={"X-API-Key": "your-api-key-here"},
  )

  data = response.json()
  # Store data["api_key"] securely -- it won't be shown again
  ```
</RequestExample>

<ResponseExample>
  ```json 200 theme={null}
  {
    "id": "key_new456",
    "api_key": "ar_live_newkey1234567890abcdef",
    "created_at": "2026-03-21T10:00:00Z"
  }
  ```

  ```json 401 theme={null}
  {
    "error": "Invalid or missing API key.",
    "code": "UNAUTHORIZED",
    "timestamp": 1711036800,
    "request_id": "req_abc123"
  }
  ```
</ResponseExample>

The new API key is returned in the `api_key` field. Store it securely -- this is the only time the full key will be shown. The previous key is invalidated immediately upon rotation.
