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

# Create Api Key

`POST /v1/create-api-key`

## Request

- Base URL: `https://api.pioneer.ai` (the document declares no server; this is the origin it was published from)
- URL: `https://api.pioneer.ai/v1/create-api-key`
- Auth: one of:
  - API key in header `X-API-Key`
  - HTTP bearer
- TypeScript: <https://skmtc.dev/pioneer/apis/brain-api/docs/v1/create-api-key/post.ts> (a function with typed inputs; its response is checked against the schema)

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.

Nothing here waits on Stripe — see
:func:`_schedule_stripe_customer_backfill`.

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 key cap
        is zero, 409 if the cap is already reached or the name is taken,
        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

## Changes

- **2026-09-24** `0e5e86e2bae5`: 1 info
  - endpoint added

[Operation history](https://skmtc.dev/pioneer/apis/brain-api/changes/v1/create-api-key/post.md)

---

[API](https://skmtc.dev/pioneer/apis/brain-api.md) - [All operations](https://skmtc.dev/pioneer/apis/brain-api/llms.txt) - [OpenAPI document](https://skmtc.dev/pioneer/apis/brain-api/revisions/0e5e86e2bae5?raw)
