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

# 管理 API Key

> ClickHouse Cloud 提供基于 OpenAPI 的 API，您可以通过编程方式管理账户及各项服务。

export const Image = ({img, alt, size = "lg"}) => {
  const normalizedSize = ["sm", "md", "lg"].includes(size) ? size : "lg";
  return <div className={`ch-image-${normalizedSize}`}>
      <Frame>
        <img src={img} alt={alt} />
      </Frame>
    </div>;
};

ClickHouse Cloud 提供基于 OpenAPI 的 API，您可以通过编程方式管理账户及各项服务。

<Note>
  本文档介绍的是 ClickHouse Cloud API。有关数据库 API 端点，请参见 [Cloud Endpoints API](/zh/products/cloud/guides/sql-console/query-endpoints)
</Note>

1. 您可以使用左侧菜单中的 **API Key** 选项卡来创建和管理 API Key。

<Image img="https://mintcdn.com/private-7c7dfe99-detect-table-modification/I0yKDIFW2QfsHJIe/images/cloud/manage/openapi1.webp?fit=max&auto=format&n=I0yKDIFW2QfsHJIe&q=85&s=ca153b781717512fec377c1398e7f417" size="sm" alt="API Key 选项卡" border width="433" height="472" data-path="images/cloud/manage/openapi1.webp" />

2. **API Key** 页面初始会显示一个提示，指导您创建第一个 API Key，如下所示。创建第一个密钥后，您可以使用右上角出现的 `New API Key` 按钮创建新的密钥。

<Image img="https://mintcdn.com/private-7c7dfe99-detect-table-modification/I0yKDIFW2QfsHJIe/images/cloud/manage/openapi2.webp?fit=max&auto=format&n=I0yKDIFW2QfsHJIe&q=85&s=fc6939ba6483077d4e6e882c6bb4406a" size="md" alt="API Key 页面" border width="1036" height="466" data-path="images/cloud/manage/openapi2.webp" />

3. 要创建 API Key，请指定密钥名称、密钥权限和过期时间，然后点击 `Generate API Key`。

<br />

<Note>
  权限与 ClickHouse Cloud 的[预定义角色](/zh/products/cloud/reference/security/console-roles)一致。`Developer` 角色对已分配的服务具有只读权限，`Admin` 角色具有完整的读写权限。
</Note>

<Tip>
  **查询 API 端点**

  要将 API Key 用于[查询 API 端点](/zh/products/cloud/guides/sql-console/query-endpoints)，请将 Organization Role 设置为 `Member` (最低要求) ，并为 `Query Endpoints` 授予 Service Role 访问权限。
</Tip>

<Image img="https://mintcdn.com/private-7c7dfe99-detect-table-modification/I0yKDIFW2QfsHJIe/images/cloud/manage/openapi3.png?fit=max&auto=format&n=I0yKDIFW2QfsHJIe&q=85&s=999392ffdb33ebcb4d181cea15db7784" size="md" alt="创建 API Key 表单" border width="661" height="410" data-path="images/cloud/manage/openapi3.png" />

4. 下一页将显示您的 Key ID 和 Key secret。请复制这些值并将其保存在安全的地方，例如密钥保管库。离开此页面后，这些值将不会再次显示。

<Image img="https://mintcdn.com/private-7c7dfe99-detect-table-modification/I0yKDIFW2QfsHJIe/images/cloud/manage/openapi4.webp?fit=max&auto=format&n=I0yKDIFW2QfsHJIe&q=85&s=57dd93c94eb91e5e772d8dc58e56e99d" size="md" alt="API Key 详细信息" border width="653" height="271" data-path="images/cloud/manage/openapi4.webp" />

5. ClickHouse Cloud API 使用 [HTTP Basic Authentication](https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication) 验证您的 API Key。以下示例展示了如何使用 `curl` 和您的 API Key 向 ClickHouse Cloud API 发送请求：

```bash theme={null}
$ KEY_ID=mykeyid
$ KEY_SECRET=mykeysecret

$ curl --user $KEY_ID:$KEY_SECRET https://api.clickhouse.cloud/v1/organizations
```

6. 返回 **API Key** 页面后，你会看到密钥名称、Key ID 的后四位字符、权限、状态、到期日期和创建者。你可以在此页面编辑密钥名称、权限和到期日期，也可以在此页面禁用或删除密钥。

<br />

<Note>
  删除 API Key 是不可恢复的永久操作。任何使用该密钥的服务都将立即失去对 ClickHouse Cloud 的访问权限。
</Note>

<Image img="https://mintcdn.com/private-7c7dfe99-detect-table-modification/I0yKDIFW2QfsHJIe/images/cloud/manage/openapi5.webp?fit=max&auto=format&n=I0yKDIFW2QfsHJIe&q=85&s=f1673d47b5c267303c0ba944e14d62f5" size="md" alt="API Key 管理页面" border width="1092" height="335" data-path="images/cloud/manage/openapi5.webp" />

<div id="endpoints">
  ## 端点
</div>

有关端点的详细信息，请参阅 [API 参考文档](/zh/api-reference/organization/get-list-of-available-organizations)。
请使用您的 API Key 和 API Secret，base URL 为 `https://api.clickhouse.cloud/v1`。
