---
title: "Create an API key"
description: "Creates an API key with an owner access token or a claimed agent access token and returns its secret exactly once."
canonical: "https://www.cool.computer/docs/api-reference/authentication/create-an-api-key"
---
# Create an API key

> Creates an API key with an owner access token or a claimed agent access token and returns its secret exactly once.

```http
POST https://api.cool.computer/api/api-keys
```

Creates an API key with an owner access token or a claimed agent access token and returns its secret exactly once. Do not retry this request automatically: the one-time secret cannot be replayed. List existing key metadata before deciding whether to create another key. API keys are rejected with access_token_required.

## Authorization

- A WorkOS access token returned by the self-serve email authorization flow. A claimed agent access token is also accepted for creating an API key, and only for that. API keys are not accepted for API-key administration.

## Request body

Required.

- `application/json` (object)
  - `name` (string, 1 to 100 characters, required)

## Responses

- `201`: The new API key and its one-time secret.
  - `application/json` (object)
    - `api_key` (string, required)
    - `key` (object, required)
      - `id` (string, required)
      - `name` (string, required)
      - `obfuscated_value` (string, required)
      - `created_at` (string, date-time, required)
      - `last_used_at` (string or null, date-time)
      - `expires_at` (string or null, date-time)
- `400`: Bad Request.
- `401`: Unauthorized.
- `403`: An owner access token or a claimed agent access token is required. API keys receive access_token_required; an agent token without cool-computers:operate receives insufficient_scope.
- `413`: Payload Too Large.
- `429`: Too Many Requests. If the problem code is api_request_rate_exceeded, wait for Retry-After seconds; other problem codes describe a separate limit.
- `500`: Internal Server Error.
- `default`: A machine-readable API error with a stable code and recovery instruction.

An error is an `application/problem+json` document with a stable `code`; [API errors](/docs/api-reference/errors) says how to handle one.

## Example

```sh
curl -X POST "https://api.cool.computer/api/api-keys" \
  -H "authorization: Bearer $TOKEN" \
  -H "content-type: application/json" \
  --data '{"name":"string"}'
```
