---
title: "Generate API Key"
method: POST
path: "/api_keys/generate"
tags: ["api-keys"]
---

# Generate API Key

`POST /api_keys/generate`

Endpoint for generating a new API key with an automatically created key pair.  This endpoint generates both a public and private RSA key pair. The public key is stored on the platform, while the private key is returned to the user and must be stored securely. The private key cannot be retrieved again.

## Request body

- GenerateApiKeyRequest
  - `name` string, required — Name for the API key. This helps identify the key's purpose
  - `scopes` ApiKeyScope[] — List of scopes to grant to the API key. If the broad `write` parent scope is included, `read` must also be included. Child scopes may be granted without the broad parent scope. Defaults to full access (`read`, `write`) if not provided.
  - `subaccount` integer — If set, restricts the API key to a single sub-account (0-63) that you own. A restricted key may only read and trade on that sub-account; it cannot act on other sub-accounts, transfer funds between sub-accounts, or create sub-accounts. Omit to leave the key unrestricted.

## Response `201`

API key generated successfully

- GenerateApiKeyResponse
  - `api_key_id` string, required — Unique identifier for the newly generated API key
  - `private_key` string, required — RSA private key in PEM format. This must be stored securely and cannot be retrieved again after this response

## Other responses

- `400` — Bad request - invalid input
- `401` — Unauthorized
- `500` — Internal server error

---

[API](https://skmtc.net/kalshi/apis/kalshi-trade-api-manual-endpoints.md) · [All operations](https://skmtc.net/kalshi/apis/kalshi-trade-api-manual-endpoints/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/kalshi/kalshi-trade-api-manual-endpoints/versions/6e6402bf667d/schema)
