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

# Create a new API key

`POST /api/api-keys`

# Errors
Returns error if permissions are invalid, database error, or key generation fails

## Request body

- CreateApiKeyRequest — Request payload for creating a new API key
  - `expiresAt` string, date-time, nullable — When the API key should expire (optional)
  - `name` string, required — Name identifier for the new API key
  - `permissions` string[], nullable — Array of permissions to grant to this key

## Response `201`

API key created successfully

- CreateApiKeyResponse — Response when creating a new API key - includes the actual key value
  - `createdAt` string, date-time, nullable — Timestamp of when the API key was just created
  - `expiresAt` string, date-time, nullable — Key expiration date (when provided)
  - `id` string, uuid, required — UUID of the newly created API key
  - `isActive` boolean, required — Initial active status of the new API key
  - `key` string, required — The actual API key value (only shown once during creation)
  - `keyPrefix` string, required — Prefix portion of the newly generated key
  - `name` string, required — Display name shown for this API key
  - `permissions` string[], required — Permissions assigned to the new API key

## Other responses

- `400` — Invalid API key data
- `401` — Authentication required to create API keys
- `500` — Server error during API key creation

## Changes

- **2025-09-24** `143443c14b73` — 1 info
  - endpoint added
- **2025-09-01** `a2488be8a6e4` — 1 breaking
  - api path removed without deprecation

[Change history](https://skmtc.dev/patroninc/apis/patron-api/changes/api/api-keys/post.md)

---

[API](https://skmtc.dev/patroninc/apis/patron-api.md) · [All operations](https://skmtc.dev/patroninc/apis/patron-api/llms.txt) · [OpenAPI document](https://skmtc-service-production.skmtc.workers.dev/v1/apis/patroninc/patron-api/revisions/1583b1f4c97d/schema)
