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

# Create Key

`POST /v1/admin/keys`

## Request

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

Create a new key for a user.

## Request body

- ApiInfrastructureFastapiSchemasAdminKeysCreateKeyBody
  - `name` string, required: Name of the key.
  - `user` integer, required: User ID to create the token for another user (by default, the current user). Required CREATE_USER permission.
  - `expires` integer, nullable: Expiration time, as Unix timestamp. If None, 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.
- `401`: Invalid authentication scheme.<br>Invalid API key.
- `403`: User has no admin rights.<br>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
  - added the non-success response with the status `400`

[Operation history](https://skmtc.dev/betagouv/apis/opengatellm/changes/v1/admin/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)
