> ## 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 Key

> 创建 API Key，并仅返回一次完整值

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

创建 API Key，并仅返回一次完整值。传入 `member_principal_id` 可为虚拟成员签发 Key（该 Key 将以该成员身份操作）；不能为真人成员签发。

<Note>
  **所需权限：** `service_account:create`（全部 Key）

  * 设置了 `member_principal_id` 时：`member:manage_virtual`
  * 如果改动会让某人获得管理员角色，或会缩小管理员能访问的范围，还需要由团队所有者或管理员操作。
</Note>

### 请求头

<ParamField header="Idempotency-Key" type="string">
  可选。使用相同值重试会重放首次结果，而不会创建第二个 Key。
</ParamField>

### 请求体

<ParamField body="name" type="string" required>
  Key 的显示名称
</ParamField>

<ParamField body="allowed_ips" type="array">
  可选。允许使用此 Key 的客户端 IP 或 CIDR 网段（例如 `10.0.0.1`、`192.168.0.0/16`）。省略或传 `[]` 表示不限制。
</ParamField>

<ParamField body="backup_group" type="string">
  可选。备用模型路由分组，规则同 `group`。
</ParamField>

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

<ParamField body="group" type="string">
  可选。模型路由分组。必须是公共分组或所有者自己的分组。
</ParamField>

<ParamField body="member_principal_id" type="string">
  可选。为此虚拟成员（来自 POST /members）签发 Key；该 Key 代表该成员。不能指定真人成员。
</ParamField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST 'https://app.memorylake.cn/openapi/memorylake/admin/v1/api-keys' \
    -H 'Authorization: Bearer sk_xxxxxx' \
    -H 'Idempotency-Key: 7c1d2e3f-0a9b-4c8d-b7e6-f5a4d3c2b1a0' \
    -H 'Content-Type: application/json' \
    -d '{
      "name": "Example name",
      "allowed_ips": [
        "example"
      ],
      "backup_group": "example",
      "expires_at": 1760000000,
      "group": "example",
      "member_principal_id": "3c044ef28d3c60180490868efdce0ca8"
    }'
  ```
</RequestExample>

### 响应

<ResponseField name="data" type="object">
  <Expandable title="API Key Created 对象">
    <ResponseField name="id" type="string">此 API Key 的稳定标识符</ResponseField>
    <ResponseField name="key" type="string">完整的 API Key，包含 `sk-` 前缀。请立即保存——读取类端点不会再返回它。</ResponseField>
    <ResponseField name="key_prefix" type="string">Key 主体的前 8 个字符</ResponseField>
    <ResponseField name="name" type="string">显示名称</ResponseField>
    <ResponseField name="key_suffix" type="string">Key 的后 4 个字符</ResponseField>
  </Expandable>
</ResponseField>

<ResponseExample>
  ```json Success (201) theme={null}
  {
    "success": true,
    "message": "Operation completed successfully",
    "data": {
      "id": "b62967384a5222f7709e7ee5220e565f",
      "key": "sk-f6e5d4c3...redacted...b2a1",
      "key_prefix": "f6e5d4c3",
      "name": "Example name",
      "key_suffix": "b2a1"
    }
  }
  ```
</ResponseExample>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.