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

# Create API Key

> Creates an API key and returns its full value once

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

Creates an API key and returns its full value once. Pass member\_principal\_id to issue the key for a VIRTUAL member (the key then acts as that member); human members cannot be targeted.

<Note>
  **Permission required:** `service_account:create` (all keys)

  * When you set `member_principal_id`: `member:manage_virtual`
  * Changes that give someone an admin role, or that reduce what an admin can reach, also require the team owner or an admin.
</Note>

### Headers

<ParamField header="Idempotency-Key" type="string">
  Optional. Retrying with the same value replays the first result instead of creating a second key.
</ParamField>

### Request Body

<ParamField body="name" type="string" required>
  Display name for the key
</ParamField>

<ParamField body="allowed_ips" type="array">
  Optional. Client IPs or CIDR ranges (e.g. 10.0.0.1, 192.168.0.0/16) this key may be used from. Omit or send \[] for no restriction.
</ParamField>

<ParamField body="backup_group" type="string">
  Optional. Fallback model-routing group, same rule as group.
</ParamField>

<ParamField body="expires_at" type="integer">
  Expiry, Unix seconds. Omit or send 0 for a key that never expires.
</ParamField>

<ParamField body="group" type="string">
  Optional. Model-routing group. Must be a public group or the owner's own group.
</ParamField>

<ParamField body="member_principal_id" type="string">
  Optional. Issue the key for this VIRTUAL member (from POST /members); the key acts as that member. Human members cannot be targeted.
</ParamField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST 'https://app.memorylake.ai/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>

### Response

<ResponseField name="data" type="object">
  <Expandable title="API Key Created object">
    <ResponseField name="id" type="string">Stable identifier of this API key</ResponseField>
    <ResponseField name="key" type="string">The full API key, including the sk- prefix. Save it now — read endpoints never return it.</ResponseField>
    <ResponseField name="key_prefix" type="string">First 8 characters of the key body</ResponseField>
    <ResponseField name="name" type="string">Display name</ResponseField>
    <ResponseField name="key_suffix" type="string">Last 4 characters of the key</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>

### Errors

Errors answer with `success: false`, a `message` and an `error_code`. See [Error Codes](/features/memorylake/api-reference/errors) for every code.

| Status | Meaning |
| - | - |
| `400` | A parameter or the body is invalid |
| `401` | The API key is missing, invalid, disabled or expired |
| `403` | The key is not allowed to do this |
| `409` | The request conflicts with the current state, e.g. a duplicate or a limit reached |
| `422` | The body or a parameter failed validation |
| `429` | Too many requests. Wait for the time in `Retry-After` |
| `500` | Server-side error |
| `503` | Temporarily unavailable. Retry later |


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