---
title: "Create Key"
method: POST
path: "/v1/keys"
tags: ["Keys"]
---

# Create Key

`POST /v1/keys`

## Request

- The document declares no server URL.
- Auth: HTTP bearer

Create a new API key for the authenticated user.

## Request body

- ApiInfrastructureFastapiSchemasKeysCreateKeyBody
  - `name` string, required: Name of the key.
  - `expires` integer, nullable: Expiration time, as Unix timestamp. If None, uses the configured maximum key lifetime when set, otherwise the key never expires.

## Response `201`

Successful Response

- KeyResponse
  - `object` 'key': Type of the object.
  - `id` integer, required: ID of the key.
  - `name` string, required: Name of the key.
  - `value` string, required: Value of the key.
  - `user_id` integer, required: ID of the user that owns the key.
  - `expires` integer, nullable: Time of expiration, as Unix timestamp. If None, the key never expires.
  - `created` integer, required: Time of creation, as Unix timestamp.
  - `revoked` boolean, required: Whether the key has been revoked.

## Other responses

- `400`: Key expiration timestamp cannot be greater than {max_expiration_days} days from now.<br>Key name {name} is reserved.
- `401`: Invalid authentication scheme.<br>Invalid API key.
- `403`: Your account has expired. Please contact support to renew your account.
- `404`: User {user_id}|{email} not found.
- `422`: Validation Error

## Changes

- **2026-09-29** `2f7a4a0aac8f`: 1 info
  - endpoint added
- **2026-09-29** `da70d9cd1957`: 1 breaking
  - api path removed without deprecation
- **2026-09-28** `87472bc2094f`: 2 info
  - removed the non-success response with the status `409`
  - added the required property `revoked` to the response with the `201` status
- **2026-09-21** `5fdbd3614b8c`: 1 breaking, 1 info
  - removed the required property `user` from the response with the `201` status
  - added the required property `user_id` to the response with the `201` status
- **2026-08-27** `1627e468291c`: 1 info
  - endpoint added

[Operation history](https://skmtc.dev/betagouv/apis/opengatellm/changes/v1/keys/post.md)

---

[API](https://skmtc.dev/betagouv/apis/opengatellm.md) - [All operations](https://skmtc.dev/betagouv/apis/opengatellm/llms.txt) - [OpenAPI document](https://skmtc.dev/betagouv/apis/opengatellm/revisions/2f7a4a0aac8f?raw)
