---
title: "POST /api-keys"
method: POST
path: "/api-keys"
tags: ["API Keys"]
---

# POST /api-keys

`POST /api-keys`

## Request

- Base URL: `/api` (relative, and the document was published on a file host, not at the API’s origin)
- URL: `/api/api-keys`
- Auth: HTTP bearer

## Request body

- CreateApiKeyRequest
  - `environment_id` integer, nullable
  - `expires_at` string, date-time, nullable
  - `name` string, required
  - `permissions` string[], nullable
  - `project_id` integer, nullable: Immutable optional deployment resource scope.
  - `role_type` string, required

## Response `201`

API key created successfully

- CreateApiKeyResponse
  - `api_key` string, required
  - `created_at` string, date-time, required
  - `environment_id` integer, nullable
  - `expires_at` string, date-time, nullable
  - `id` integer, required
  - `key_prefix` string, required
  - `name` string, required
  - `permissions` string[], nullable
  - `project_id` integer, nullable: Immutable optional deployment resource scope.
  - `role_type` string, required

## Other responses

- `400`: Bad request
- `401`: Unauthorized
- `403`: Forbidden
- `409`: Conflict - API key name already exists
- `428`: Recent MFA verification required
- `500`: Internal server error

## Changes

- **2026-11-16** `eb31063c55e2`: 4 info
  - added the new optional request property `environment_id`
  - added the new optional request property `project_id`
  - added the optional property `environment_id` to the response with the `201` status
  - added the optional property `project_id` to the response with the `201` status
- **2026-08-04** `c647b6ab1d2c`: 1 info
  - added the non-success response with the status `428`

[Operation history](https://skmtc.dev/gotempsh/apis/temps/changes/api-keys/post.md)

---

[API](https://skmtc.dev/gotempsh/apis/temps.md) - [All operations](https://skmtc.dev/gotempsh/apis/temps/llms.txt) - [OpenAPI document](https://skmtc.dev/gotempsh/apis/temps/revisions/3b040526eb43?raw)
