> ## Documentation Index
> Fetch the complete documentation index at: https://docs.memorylake.cn/llms.txt
> Use this file to discover all available pages before exploring further.

# 创建 API 密钥

> 创建一把数据面 API 密钥，并一次性返回其完整值

```
POST /openapi/admin/api/v1/api-keys
```

创建一把**数据**密钥，并且只返回一次完整值 —— 请立即保存，读取类接口不会再返回它。

本接口无法创建管理密钥。管理密钥由已登录的 Owner 或 Admin 在控制台签发，因此泄露的管理密钥永远无法用来签发出另一把管理密钥。

<Note>
  **所需权限：** `service_account:create`
</Note>

### 请求头

<ParamField header="Idempotency-Key" type="string">
  可选。用相同的值重试会重放第一次的结果，而不会创建出第二把密钥。
</ParamField>

### 请求体

<ParamField body="name" type="string" required>
  显示名称（1–100 个字符）
</ParamField>

<ParamField body="expires_at" type="integer">
  过期时间，Unix 秒。省略或传 0 表示该密钥永不过期。
</ParamField>

<ParamField body="member_principal_id" type="string">
  为某个[虚拟成员](/features/management-api/members/create-member)签发密钥；该密钥随后会以这个成员的身份行事，使用它的角色，产出也归属到它。只能指向虚拟成员 —— 传入真人成员会返回 `404`。除 `service_account:create` 之外，还需要 `member:manage_virtual` 权限。
</ParamField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST 'https://app.memorylake.cn/openapi/admin/api/v1/api-keys' \
    -H 'Authorization: Bearer sk-admin-xxxxxx' \
    -H 'Content-Type: application/json' \
    -H 'Idempotency-Key: 5f3a2b1c-9d8e-4f00-a1b2-c3d4e5f60789' \
    -d '{"name": "ci-pipeline", "expires_at": 1786536000}'
  ```
</RequestExample>

### 响应

<ResponseField name="data" type="object">
  <Expandable title="创建出的密钥对象 —— 唯一会携带密钥值的响应">
    <ResponseField name="id" type="string">稳定的密钥标识符</ResponseField>
    <ResponseField name="name" type="string">显示名称</ResponseField>
    <ResponseField name="key_prefix" type="string">用于展示的前缀</ResponseField>
    <ResponseField name="key_type" type="string">恒为 `data`</ResponseField>
    <ResponseField name="key" type="string">完整的 API 密钥，包含 `sk-` 前缀。**请立即保存** —— 它不会再次显示。</ResponseField>
  </Expandable>
</ResponseField>

<ResponseExample>
  ```json Success (201) theme={null}
  {
    "success": true,
    "message": "Operation completed successfully",
    "data": {
      "id": "313",
      "name": "ci-pipeline",
      "key_prefix": "a1b2c3d4",
      "key_type": "data",
      "key": "sk-a1b2c3d4...redacted...e5f6"
    }
  }
  ```
</ResponseExample>
