---
title: "CreateApiKeyBody"
description: "Request body for creating an ApiKey."
section: "Reference"
group: "Types"
order: 15
---

## Definition

```ts
interface CreateApiKeyBody {
  workspaceId: string;
  name: string;
  type: "private" | "public" | "session";
  scopes?:
    | {
        operations?: Array<string> | undefined;
        entityIds?: Array<string> | undefined;
      }
    | null
    | undefined;
  expiresIn?: string | undefined;
  ownerUserId?: string | undefined;
}
```

## Fields

| Field         | Type                                                                                                        | Notes                                                                                                                                                                                                                                                                                                            |
| ------------- | ----------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `workspaceId` | `string`                                                                                                    | `required` — Workspace that will own the new key.                                                                                                                                                                                                                                                                |
| `name`        | `string`                                                                                                    | `required` — Key name                                                                                                                                                                                                                                                                                            |
| `type`        | `"private" \| "public" \| "session"`                                                                        | `required` — Key type                                                                                                                                                                                                                                                                                            |
| `scopes`      | `{ operations?: Array<string> \| undefined; entityIds?: Array<string> \| undefined; } \| null \| undefined` | `optional` — Restricts what this key may do; null/empty means full access within its key type.                                                                                                                                                                                                                   |
| `expiresIn`   | `string \| undefined`                                                                                       | `optional` — Duration until expiry (e.g. '30d', '1h')                                                                                                                                                                                                                                                            |
| `ownerUserId` | `string \| undefined`                                                                                       | `optional` — Optional override for the user the key authenticates as. Defaults to the workspace's default service user (so headless calls auto-attribute to the service identity); falls back to the creator when no default exists. Workspace-admin-only to set; target user must be a member of the workspace. |
