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

# Create API key

`POST /v1/api-keys`

## Request

- Base URL: `https://api.patricia.app` (the document declares no server; this is the origin it was published from)
- URL: `https://api.patricia.app/v1/api-keys`
- Auth: HTTP bearer

Mint a tenant API key. The plaintext key is returned once and cannot be retrieved again.

## Headers

- `X-Tenant-Id` string, nullable

## Request body

- ModelsApiKeyApiKeyCreateValidator: POST body. ``tenant_id`` + key material are server-assigned.
  - `name` string, required
  - `role_code` 'owner' | 'admin' | 'member' | 'viewer', required
  - `expires_at` string, date-time, nullable

## Response `201`

The created key, including the one-time plaintext.

- ModelsApiKeyApiKeyCreatedValidator: POST response: carries the one-time plaintext key.
  - `id` string, uuid, required
  - `tenant_id` string, uuid, required
  - `name` string, required
  - `prefix` string, required
  - `role_code` 'owner' | 'admin' | 'member' | 'viewer', required
  - `created_by` string, uuid, nullable
  - `last_used_at` string, date-time, nullable
  - `revoked_at` string, date-time, nullable
  - `expires_at` string, date-time, nullable
  - `created_at` string, date-time, required
  - `updated_at` string, date-time, required
  - `plaintext_key` string, required

## Other responses

- `400`: Bad request
- `401`: Unauthorized
- `403`: Forbidden. Inspect response body `code` for the specific reason (for example: PERMISSION_DENIED, EMAIL_NOT_VERIFIED, TENANT_ACCESS_REQUIRED, ROLE_UNRESOLVED)
- `409`: Conflict
- `422`: Validation error

---

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