1. Docs
  2. API Reference
  3. Create a new API key

Create a new API key

POST/api/v1/api-keys

Issues a new API key in the active Application, scoped to the current Environment. The full cnpy_-prefixed secret is returned in the key field of the response and is not recoverable afterward, only a masked key_preview and metadata persist; the one exception is a retry carrying the same Idempotency-Key within 24 hours, which replays this response. access_mode: "scoped" requires a non-empty scopes array and enforces it on every authorization check; access_mode: "full_access" forbids scopes and bypasses RBAC entirely within the Application. Pass expires_at (ISO 8601) for an expiring key or omit it for none. Supports Idempotency-Key for safe retries, emits an api_key.created event, and is limited to 20 requests a minute per caller. A scope the platform does not offer is refused with 400. A scoped API key can create only scoped keys whose scopes it holds itself; asking for more is refused with 403.

Authentication

Bearer TokenAuthorization Option A

JWT access token. Never send alongside X-API-Key: a request carrying both is refused.

API KeyX-API-Key Option B

API key for management-tier access. Never send alongside an Authorization header: a request carrying both is refused.

Request body

application/json

namestring Required

API key name

descriptionstring Optional

API key description

access_modeenum Required

Required. `scoped` enforces the `scopes` array on every authorization check (deny if the requested permission isn't listed). `full_access` bypasses RBAC entirely within the key's Application — every permission is granted. Pick `scoped` whenever possible; `full_access` should be a deliberate choice (use cases: bootstrap automation, trusted backend services that legitimately need App-wide access). `scoped` requires a non-empty `scopes` array; `full_access` forbids `scopes`. A scoped API key can create only scoped keys whose scopes it holds itself.

one of "scoped" · "full_access"

scopesenum[] Optional

Permission scopes this key is authorized for, each one the platform offers (`GET .../api-keys/scopes`). Required and must be non-empty when `access_mode` is `scoped`. Must be omitted when `access_mode` is `full_access`.

expires_atstring Optional

Expiration date (ISO 8601). Omit for no expiration.

Responses

application/json

  • dataApiKeyCreatedResponseDto*

application/json

  • errorApiErrorBodyDto*

application/json

  • errorApiErrorBodyDto*

application/json

  • errorApiErrorBodyDto*

application/json

  • errorApiErrorBodyDto*

application/json

  • errorApiErrorBodyDto*

application/json

  • errorApiErrorBodyDto*

Errors

When the request can't be completed, the response body includes a stable error code you can branch on, and a correlation_id (also sent as the X-Correlation-Id header). Quote the correlation id when you contact support: it identifies the exact request in Canopy's logs.

403api_key.access_exceeds_callerForbidden
When it happens

The caller is a scoped API key asking for more than it holds, or acting on a key that has more: a full-access key, or a scope outside its own. Applies to creating, rotating, enabling, disabling and deleting keys.

Remediation

Request only scopes the calling key already holds, or make the change from the Console or with a full-access key.

409plan_limit_exceededConflict
When it happens

The Account's plan allows no more of this resource. The error's data names the dimension, the limit and how many are in use.

Remediation

Remove an existing one, or upgrade the plan from the Workspace's Billing page.

Idempotency

Idempotency-Key header

Send an Idempotency-Key header to make retries safe. Canopy replays the same response for matching keys within 24 hours, and refuses the same key sent with a different request with 422 idempotency.key_reused_with_different_request.

Rate limit

20 requests per 1mPer caller: the signed-in user for a bearer token; for an API key, the key and the end user's address when a backend forwards it, otherwise the client address

Emitted events

  • api_key.created

Returned object

Request
curl -X POST "https://auth.canopy-io.com/api/v1/api-keys" \
  -H "X-API-Key: $CANOPY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "string",
    "description": "string",
    "access_mode": "scoped",
    "scopes": [
      "hierarchy.view"
    ],
    "expires_at": "string"
  }'
Response
{
  "data": {
    "id": "string",
    "name": "string",
    "description": "string",
    "key": "string",
    "key_preview": "string",
    "access_mode": "scoped",
    "scopes": [
      "string"
    ],
    "expires_at": "2026-04-20T12:00:00.000Z",
    "created_at": "2026-04-20T12:00:00.000Z"
  }
}
Related endpoints
GETList API keys for Application
PATCHActivate or deactivate an API key
DELETEDelete an API key
POSTRotate an API key's secret
Was this page helpful?

Tell us how we can improve this guide.