---
title: "Create a workspace API key"
description: "PubNio API apiKeys.create: create a workspace API key. Request fields, examples in five clients, errors, and idempotency."
---

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

# Create a workspace API key

Create a workspace API key with [`POST /api/v1/workspaces/{workspaceId}/api-keys`](https://pubnio.com/api/v1/docs#tag/apikeys/POST/api/v1/workspaces/{workspaceId}/api-keys). Requires a signed-in workspace owner, in the web app or the CLI; API keys are not accepted and MCP cannot call it.

## Request

| Parameter     | In   | Type | Required |
| ------------- | ---- | ---- | -------- |
| `workspaceId` | path | UUID | Yes      |

| Body field  | Type                      | Required |
| ----------- | ------------------------- | -------- |
| `name`      | string                    | Yes      |
| `scopes`    | array of one of 5 strings | No       |
| `expiresAt` | string                    | No       |

## Response

- HTTP 201: an object with `key`, `secret`.

The [OpenAPI document](https://pubnio.com/api/v1/openapi) has each field's type.

## Examples

### TypeScript

```ts
const created = await workspace.apiKeys.create({
  name: "Publishing agent",
  scopes: ["read", "publish"],
});
```

Create this client with a signed-in person's `accessToken`, not an `apiKey`.

### Python

The Python SDK authenticates with a workspace API key, which this operation does not accept, so it has no method for it.

### cURL

```sh
curl -X POST "https://pubnio.com/api/v1/workspaces/$WORKSPACE_ID/api-keys" \
  -H "Authorization: Bearer $PUBNIO_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"name":"Publishing agent","scopes":["read","publish"]}'
```

### CLI

```sh
pnio api-keys create --name "Publishing agent" --scope read --scope publish
```

### MCP execute

```js
async () => {
  const response = await codemode.request({
    method: "POST",
    path: `/api/v1/workspaces/${codemode.workspaceId}/api-keys`,
    body: { name: "Publishing agent", scopes: ["read", "publish"] },
  });
  return response.data;
};
```

## Errors

It declares no problem of its own.

It declares the problems [most operations](https://pubnio.com/docs/reference/#shared-problems) declare.

## Idempotency

No key, so a retried `POST` is not deduplicated. Read the current state before you retry.

## Limits

- API keys and MCP cannot call it. A signed-in person runs it from the CLI after `pnio auth login` or in the web app.

## Related

- [API keys operations](https://pubnio.com/docs/reference/#api-keys)
- [Accounts and connections](https://pubnio.com/docs/accounts/)

Source: https://pubnio.com/docs/reference/api-keys-create/index.mdx
