---
search:
  tags:
    - Workspace
    - POST
seo:
  description: >-
    Creates an API key for the workspace with some of the caller's permissions,
    and… Reference for the POST /api/v1/workspace/api-keys endpoint in the Peal
    API.
sidebar:
  label: Create an API key
  badge: POST
title: Create an API key
type: openapi-operation
---
Creates an API key for the workspace with some of the caller's permissions, and answers with the key itself, which is not shown again. Needs apiKey:create, and a signed-in member: API keys cannot create keys. The key is the caller's: it stops working once they leave the workspace, are removed or close their account, and once their role no longer holds one of its permissions.

`POST /api/v1/workspace/api-keys`

**Request body** (`application/json`, required)

- `expiresInDays` (integer)
- `name` (string, required)
- `permissions` (Permission[], required)

Request body example:

```json
{
  "expiresInDays": 1,
  "name": "string",
  "permissions": [
    "activity:read"
  ]
}
```

**Responses**

- `201` — CreatedApiKey
- `400` — The request names no workspace, and its credential belongs to none: send the workspace's id in the \`Peal-Workspace\` header. Nothing was done.
- `401` — Sign in, or send an API key as a bearer token: the request has no valid credentials.
- `403` — The credentials are valid but do not allow this request. \`reason\` says why: the OAuth client was not given the scope the request takes (\`missingScope\`, with \`scope\` and \`permission\`: the user connects the client again and allows it), the member's role or the API key lacks a permission (\`missingPermission\`, with \`permission\`: an owner or an admin changes the role, or creates a key with it), only a person in their own session may do it (\`personRequired\`), the key or token belongs to another workspace (\`wrongWorkspace\`), the account is suspended (\`suspended\`), a browser sent the cookie from another site (\`untrustedOrigin\`), or the workspace requires two-step verification and the member's account does not have it on (\`twoStepRequired\`: they turn it on in the web app's account settings, and their sessions, applications and command line work again at once; API keys are never refused for it).
- `404` — No workspace with this id is open to the caller.
- `429` — This credential sent more than \`limit\` requests in \`windowSeconds\` seconds: nothing was done. Wait \`retryAfterSeconds\` seconds, as the \`Retry-After\` header says, then send the request again. Every answer to a key or a token carries the \`RateLimit-Policy\` and \`RateLimit\` headers, which say how many requests are left. \`policy\` says which limit applied: on a server that bills, a billing account without a payment method sends fewer (\`free\`), and \`withPaymentMethod\` is what a payment method gives.

Response example, 201:

```json
{
  "apiKey": {
    "createdAt": "string",
    "createdBy": {
      "id": "string",
      "name": "string"
    },
    "expiresAt": "string",
    "id": "string",
    "name": "string",
    "permissions": [
      "activity:read"
    ],
    "start": "string"
  },
  "key": "string"
}
```
