> ## 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 exactly once — save it immediately; read endpoints never return it again.

The new key carries the same authority as the key that created it, unless you issue it for a [virtual member](/features/management-api/members/create-member) with a narrower role.

<Note>
  **Permission required:** `service_account:create`
</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 (1–100 characters)
</ParamField>

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

<ParamField body="member_principal_id" type="string">
  Issue the key for a [virtual member](/features/management-api/members/create-member); the key then acts as that member, with its role and attribution. Only virtual members can be targeted — human members return `404`. Requires `member:manage_virtual` in addition to `service_account:create`.
</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 'Content-Type: application/json' \
    -H 'Idempotency-Key: 5f3a2b1c-9d8e-4f00-a1b2-c3d4e5f60789' \
    -d '{"name": "ci-pipeline", "expires_at": 1786536000}'
  ```
</RequestExample>

### Response

<ResponseField name="data" type="object">
  <Expandable title="Created key object — the ONLY response carrying the key">
    <ResponseField name="id" type="string">Stable key identifier</ResponseField>
    <ResponseField name="name" type="string">Display name</ResponseField>
    <ResponseField name="key_prefix" type="string">Display prefix</ResponseField>
    <ResponseField name="key" type="string">The full API key, including the `sk-` prefix. **Save it now** — it is never shown again.</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": "sk-a1b2c3d4...redacted...e5f6"
    }
  }
  ```
</ResponseExample>
