---
title: "Create key"
method: POST
path: "/v1/organizations/{organizationId}/keys"
tags: ["API keys"]
---

# Create key

`POST /v1/organizations/{organizationId}/keys`

## Request

- Base URL: `https://api.clickhouse.cloud`
- URL: `https://api.clickhouse.cloud/v1/organizations/{organizationId}/keys`
- Auth: HTTP basic

Creates new API key.

## Path parameters

- `organizationId` string, uuid, required

## Request body

- ApiKeyPostRequest
  - `name` string, required: Name of the key.
  - `expireAt` string, date-time, nullable: Timestamp the key expires. If not present, `null` or is empty the key never expires. ISO-8601.
  - `state` 'enabled' | 'disabled': Initial state of the key: 'enabled', 'disabled'. If not provided the new key will be 'enabled'.
  - `hashData` ApiKeyHashData
    - `keyIdHash` string: Hash of the key ID.
    - `keyIdSuffix` string: Last 4 digits of the key ID. Algorithm: echo -n "yourpassword" | sha256sum | tr -d '-' | xxd -r -p | base64
    - `keySecretHash` string: Hash of the key secret. Algorithm: echo -n "yourpassword" | sha256sum | tr -d '-' | xxd -r -p | base64
  - `roles` string[]: DEPRECATED. Use `assignedRoleIds` instead. List of roles assigned to the key. Contains at least 1 element.
  - `assignedRoleIds` string[]: Array of role UUIDs to assign to the API key
  - `ipAccessList` IpAccessListEntry[]: List of IP addresses allowed to access the API using this key
    - `source` string: IP or CIDR
    - `description` string: Optional description of IPv4 address or IPv4 CIDR to allow access from

## Response `200`

Successful response

- object
  - `status` number: HTTP status code.
  - `requestId` string, uuid: Unique id assigned to every request. UUIDv4
  - `result` ApiKeyPostResponse
    - `key` ApiKey
      - `id` string, uuid: Unique API key ID.
      - `name` string: Name of the key
      - `state` 'enabled' | 'disabled': State of the key: 'enabled', 'disabled'.
      - `roles` string[]: DEPRECATED. Use `assignedRoles` instead. List of roles assigned to the key. For organizations that have migrated to custom roles, this field is frozen at the pre-migration value and does not reflect current role assignments.
      - `assignedRoles` AssignedRole[]: Custom roles and System roles assigned to this API key
        - `roleId` string, uuid: Unique identifier of the role
        - `roleName` string: Human-readable name of the role
        - `roleType` 'system' | 'custom': Type of role: system (predefined) or custom (organization-defined)
      - `keySuffix` string: Last 4 letters of the key.
      - `createdAt` string, date-time: Timestamp the key was created. ISO-8601.
      - `expireAt` string, date-time, nullable: Timestamp the key expires. If not present, `null` or is empty the key never expires. ISO-8601.
      - `usedAt` string, date-time: Timestamp the key was used last time, with one-minute precision. If not present the key was never used. ISO-8601.
      - `ipAccessList` IpAccessListEntry[]: List of IP addresses allowed to access the API using this key
        - `source` string: IP or CIDR
        - `description` string: Optional description of IPv4 address or IPv4 CIDR to allow access from
    - `keyId` string: Generated key ID. Provided only if there was no 'hashData' in the request.
    - `keySecret` string: Generated key secret. Provided only if there was no 'hashData' in the request.

## Other responses

- `400`: The request cannot be processed due to a client error. Please verify your request parameters and try again.
- `500`: An internal server error has occurred. If this issue persists, please contact ClickHouse Cloud support for assistance.

---

[API](https://skmtc.dev/clickhouse/apis/openapi-spec-for-clickhouse-cloud.md) - [All operations](https://skmtc.dev/clickhouse/apis/openapi-spec-for-clickhouse-cloud/llms.txt) - [OpenAPI document](https://skmtc.dev/clickhouse/apis/openapi-spec-for-clickhouse-cloud/revisions/eac345053548?raw)
