> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-mintlify-8c05c8a2.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# 创建密钥

> 创建新的 API key。



## OpenAPI

````yaml /zh/_specs/cloud-openapi.json post /v1/organizations/{organizationId}/keys
openapi: 3.0.1
info:
  contact:
    email: support@clickhouse.com
    name: ClickHouse Support
    url: >-
      https://clickhouse.com/docs/en/cloud/manage/openapi?referrer=openapi-299828
  title: OpenAPI spec for ClickHouse Cloud
  version: '1.0'
servers:
  - url: https://api.clickhouse.cloud
security:
  - basicAuth: []
tags:
  - name: Organization
  - name: User management
  - name: Billing
  - name: Service
  - name: Backup
  - name: OpenAPI
  - name: Prometheus
  - name: ClickPipes
paths:
  /v1/organizations/{organizationId}/keys:
    post:
      tags:
        - OpenAPI
      summary: 创建密钥
      description: 创建新的 API key。
      parameters:
        - description: 将拥有该密钥的 organization 的 ID。
          in: path
          name: organizationId
          required: true
          schema:
            format: uuid
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ApiKeyPostRequest'
      responses:
        '200':
          content:
            application/json:
              schema:
                properties:
                  requestId:
                    description: 分配给每个请求的唯一 ID。UUIDv4
                    format: uuid
                    type: string
                  result:
                    $ref: '#/components/schemas/ApiKeyPostResponse'
                  status:
                    description: HTTP 状态码。
                    example: 200
                    type: number
                type: object
          description: 成功响应
        '400':
          content:
            application/json:
              schema:
                properties:
                  error:
                    description: 详细错误描述。
                    type: string
                  status:
                    description: HTTP 状态码。
                    example: 400
                    type: number
                type: object
          description: 由于请求存在被视为客户端错误的问题，server 无法或不会处理该请求。
components:
  schemas:
    ApiKeyPostRequest:
      properties:
        expireAt:
          description: key 的过期时间戳。如果未提供、为 `null` 或为空，则该 key 永不过期。ISO-8601。
          format: date-time
          nullable: true
          type: string
        hashData:
          $ref: '#/components/schemas/ApiKeyHashData'
        ipAccessList:
          description: 允许使用此 key 访问 API 的 IP 地址列表
          items:
            $ref: '#/components/schemas/IpAccessListEntry'
          type: array
        name:
          description: key 的名称。
          type: string
        roles:
          description: 分配给该 key 的 role 列表。至少包含 1 个元素。
          items:
            enum:
              - admin
              - developer
              - query_endpoints
            type: string
          type: array
        state:
          description: key 的初始状态：'enabled'、'disabled'。如果未提供，则新 key 的状态为 'enabled'。
          enum:
            - enabled
            - disabled
          type: string
    ApiKeyPostResponse:
      properties:
        key:
          $ref: '#/components/schemas/ApiKey'
        keyId:
          description: 生成的 key ID。仅当请求中没有 'hashData' 时提供。
          type: string
        keySecret:
          description: 生成的 key secret。仅当请求中没有 'hashData' 时提供。
          type: string
    ApiKeyHashData:
      properties:
        keyIdHash:
          description: 密钥 ID 的哈希值。
          type: string
        keyIdSuffix:
          description: >-
            密钥 ID 的后 4 位数字。算法：echo -n "yourpassword" | sha256sum | tr -d '-' |
            xxd -r -p | base64
          type: string
        keySecretHash:
          description: >-
            密钥 secret 的哈希值。算法：echo -n "yourpassword" | sha256sum | tr -d '-' |
            xxd -r -p | base64
          type: string
    IpAccessListEntry:
      properties:
        description:
          description: 允许从其访问的 IPv4 地址或 IPv4 CIDR 的可选描述
          type: string
        source:
          description: IP 或 CIDR
          type: string
    ApiKey:
      properties:
        createdAt:
          description: 密钥的创建时间戳。ISO-8601。
          format: date-time
          type: string
        expireAt:
          description: 密钥过期时间戳。如果该字段不存在、为 `null` 或为空，则该密钥永不过期。ISO-8601。
          format: date-time
          nullable: true
          type: string
        id:
          description: 唯一 API key ID。
          format: uuid
          type: string
        ipAccessList:
          description: 允许使用此密钥访问 API 的 IP 地址列表
          items:
            $ref: '#/components/schemas/IpAccessListEntry'
          type: array
        keySuffix:
          description: 密钥的后 4 个字符。
          type: string
        name:
          description: 密钥名称
          type: string
        roles:
          description: 分配给该密钥的角色列表。至少包含 1 个元素。
          items:
            enum:
              - admin
              - developer
              - query_endpoints
            type: string
          type: array
        state:
          description: 密钥状态：‘enabled’、‘disabled’。
          enum:
            - enabled
            - disabled
          type: string
        usedAt:
          description: 密钥上次使用的时间戳。如果该字段不存在，则该密钥从未使用过。ISO-8601。
          format: date-time
          type: string
  securitySchemes:
    basicAuth:
      description: >-
        使用从 ClickHouse Cloud 控制台获取的 key ID 和 key
        secret：https://clickhouse.com/docs/cloud/manage/openapi
      scheme: basic
      type: http

````