---
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

---

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