> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-fix-nav-issues.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}) => {
  return <Frame>
      <img src={img} alt={alt} />
    </Frame>;
};

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-fix-nav-issues/-5HsuqGEaVjyHCfx/images/cloud/manage/openapi1.png?fit=max&auto=format&n=-5HsuqGEaVjyHCfx&q=85&s=838eafd0a0de6185ae18627a1055e4ee" size="sm" alt="API Key 选项卡" border width="433" height="472" data-path="images/cloud/manage/openapi1.png" />

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

<Image img="https://mintcdn.com/private-7c7dfe99-fix-nav-issues/-5HsuqGEaVjyHCfx/images/cloud/manage/openapi2.png?fit=max&auto=format&n=-5HsuqGEaVjyHCfx&q=85&s=593722f25f605525ce48422f11f9460d" size="md" alt="API Key 页面" border width="1036" height="466" data-path="images/cloud/manage/openapi2.png" />

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-fix-nav-issues/-5HsuqGEaVjyHCfx/images/cloud/manage/openapi3.png?fit=max&auto=format&n=-5HsuqGEaVjyHCfx&q=85&s=53f74d4f5f4d99eecb4e4e61842b0322" 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-fix-nav-issues/-5HsuqGEaVjyHCfx/images/cloud/manage/openapi4.png?fit=max&auto=format&n=-5HsuqGEaVjyHCfx&q=85&s=008971d5bc5321463b55f2a420994ba4" size="md" alt="API Key 详细信息" border width="653" height="271" data-path="images/cloud/manage/openapi4.png" />

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-fix-nav-issues/-5HsuqGEaVjyHCfx/images/cloud/manage/openapi5.png?fit=max&auto=format&n=-5HsuqGEaVjyHCfx&q=85&s=3aa72a37b3a4f5d85c85372d50c71291" size="md" alt="API Key 管理页面" border width="1092" height="335" data-path="images/cloud/manage/openapi5.png" />

<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`。
