---
title: "Create Api Key"
method: POST
path: "/create-api-key"
tags: ["api-keys"]
---

# Create Api Key

`POST /create-api-key`

Create a new API key for the authenticated user.

Only JWT-authenticated (browser session) requests are permitted — API key
creation via an existing API key is blocked to prevent credential chaining.

Args:
    request: The incoming FastAPI request (used by SlowAPI rate limiter).
    body: The API key creation request payload.
    auth: The authenticated user context.

Returns:
    CreateAPIKeyResponse with the secret key (shown only once).

Raises:
    HTTPException: 403 if called via API key or the active team's plan does
        not include API keys, 409 if the team API-key cap is reached, 500
        for unexpected failures.

## Request body

- CreateAPIKeyRequest — Request model for creating an API key. Attributes: name: User-visible identifier for the key. expires_at: Optional ISO-8601 expiry; sentinels (``""``, ``never``, ``none``, ``null``) collapse to ``None``. team_id: Tenant the key is bound to. ``None`` defaults to the caller's active team; an explicit value must equal it. captcha_token: hCaptcha response token for bot verification.
  - `name` string, required — Name for the API key
  - `expires_at` string, nullable — Optional expiration timestamp (ISO 8601). Sentinel strings like 'never' are accepted and treated as no expiration.
  - `team_id` string, nullable — Team to bind the key to. Defaults to the caller's active team when omitted; an explicit value must equal the active team.
  - `captcha_token` string, nullable — hCaptcha response token for bot verification

## Response `200`

Successful Response

- CreateAPIKeyResponse — Response model for API key creation.
  - `id` string, required
  - `name` string, required
  - `api_key_last_digits` string, required
  - `created_at` string, required
  - `expires_at` string, nullable
  - `team_id` string, required
  - `secret_key` string, required
  - `stripe_customer_created` boolean

## Other responses

- `422` — Validation Error

---

[API](https://skmtc.net/pioneer/apis/brain-api.md) · [All operations](https://skmtc.net/pioneer/apis/brain-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/pioneer/brain-api/versions/31dfe831e079/schema)
