---
title: "Create an API key"
method: POST
path: "/admin/api_keys"
tags: ["API Keys"]
---

# Create an API key

`POST /admin/api_keys`

## Request

- Base URL: `https://h2ogpte.genai.h2o.ai/api/v1`
- URL: `https://h2ogpte.genai.h2o.ai/api/v1/admin/api_keys`
- Auth: HTTP bearer
- TypeScript: <https://skmtc.dev/h2o/apis/h2ogpte-rest-api/docs/admin/api_keys/post.ts> (a function with typed inputs; its response is checked against the schema)

Allows admins to create an API key for another user.

## Request body

- APIKeyCreateRequest
  - `user_id` string, required: Id of the user the key will be created for
  - `name` string: The name for the API key
  - `collection_id` string: The id of the collection you want the key to be configured to
  - `expires_in` string: Interval of when the API key should expire
  - `inactivity_interval` integer: The number of days a key can be unused for (no activity) before it becomes invalid.

## Response `201`

Successful operation

- APIKeyResult
  - `secret_key` string, required: The secret key associated with the newly generated API Key.
  - `api_key` APIKeyInfo, required
    - `id` string, required: The unique identifier of the API key
    - `username` string, required: The username of the user this key belongs to
    - `name` string, required: The name of the API key
    - `hint` string, required: Hint for the secret key of the API key
    - `created_at` string, date-time, required: The date and time of when the API key was created
    - `expires_at` string, date-time: The date and time of the API key expiration
    - `last_used_at` string, date-time: The date and time of the most recent API call using this key
    - `inactivity_interval` integer: The number of days this API key can be inactive for before becoming invalid
    - `total_calls` integer, required: Number of times this API key has been used
    - `is_active` boolean, required: Status denoting if the API key is active or not
    - `collection_name` string: The name of the collection associated with the API key (if it has been configured to a collection)
    - `collection_id` string: The id of the collection associated with the API key (if it has been configured to a collection)
    - `is_global_key` boolean, required: Status denoting if the API key is global or collection specific

## Other responses

- `400`: Bad request
- `401`: Unauthorized - Invalid or missing API key
- `404`: Not found
- `500`: Internal server error
- `default`: Unexpected error

---

[API](https://skmtc.dev/h2o/apis/h2ogpte-rest-api.md) - [All operations](https://skmtc.dev/h2o/apis/h2ogpte-rest-api/llms.txt) - [OpenAPI document](https://skmtc.dev/h2o/apis/h2ogpte-rest-api/revisions/a82a117320f4?raw)
