---
title: "Create a key"
method: POST
path: "/v1/realms/{realmId}/consumers/{consumerId}/keys"
tags: ["Centrally Managed Keys"]
---

# Create a key

`POST /v1/realms/{realmId}/consumers/{consumerId}/keys`

This operation generates an API key for the specified consumer. The key is returned only at the time of creation
and will not be retrievable in any subsequent GET requests on the entity.

The API supports two key creation types: `new` and `legacy`.

* `new`: The recommended and more efficient option. The API automatically generates the key and returns it during
this operation.
* `legacy`: Allows you to provide your own secret. This approach has a performance impact when proxying requests, as it involves
additional processing and resource usage.

Note: Regardless of the type selected, the key is only returned by the API when a key is created. It is not retrievable in the future.

## Request body

- CreateApiKeyPayload
  - `type` 'new' | 'legacy', required
  - `secret` string — secret to be created. Must be unique within the realm. If not specified a secret will be automatically generated.
  - `tags` string[]

## Response `201`

success

- CreateApiKeyResult
  - `id` string, required
  - `type` 'legacy' | 'new', required
  - `secret` string, required
  - `created_at` string, date-time, required — An ISO-8601 timestamp representation of entity creation date.
  - `updated_at` string, date-time, required — An ISO-8601 timestamp representation of entity update date.
  - `tags` string[], required

## Other responses

- `400` — Bad Request
- `404` — Not Found

---

[API](https://skmtc.net/kong/apis/konnect-api.md) · [All operations](https://skmtc.net/kong/apis/konnect-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/kong/konnect-api/revisions/06734a9c491f/schema)
