---
title: "Create a key"
url: "https://nov18-dev.movespot.fyi/apis/konnect-centrally-managed-consumers-admin-api-0/versions/84f5e371-6d0e-45b1-b943-fe4dc428c317/operations/create-consumer-key"
---

> Full API specification: https://nov18-dev.movespot.fyi/apis/konnect-centrally-managed-consumers-admin-api-0/versions/84f5e371-6d0e-45b1-b943-fe4dc428c317.md

# Create a key

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

Operation ID: `create-consumer-key`

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.

## Path parameters

- `realmId` (string, uuid, required) - ID of the realm
- `consumerId` (string, required) - ID of the of the consumer

## Request body (required)

Content types: `application/json`

## Responses

- `201` - success
- `400` - Bad Request
- `404` - Not Found

## OpenAPI definition

```yaml
openapi: 3.0.3
info:
  title: Konnect Centrally Managed Consumers admin api
  version: 0.0.1
servers:
  - url: https://us.api.konghq.com/v1
    description: United-States Production region
  - url: https://eu.api.konghq.com/v1
    description: Europe Production region
  - url: https://au.api.konghq.com/v1
    description: Australia Production region
  - url: https://me.api.konghq.com/v1
    description: Middle-East Production region
  - url: https://in.api.konghq.com/v1
    description: India Production region
  - url: https://sg.api.konghq.com/v1
    description: Singapore Production region
paths:
  /realms/{realmId}/consumers/{consumerId}/keys:
    parameters:
      - $ref: "#/components/parameters/realmId"
      - $ref: "#/components/parameters/consumerId"
    post:
      operationId: create-consumer-key
      summary: Create a key
      description: >
        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.
      requestBody:
        $ref: "#/components/requestBodies/CreateApiKey"
      responses:
        "201":
          description: success
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/CreateApiKeyResult"
              examples:
                CreateKeyResult:
                  $ref: "#/components/examples/CreateApiKeyResult"
                CreateApiKeyResultLegacy:
                  $ref: "#/components/examples/CreateApiKeyResultLegacy"
        "400":
          description: Bad Request
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/BadRequestError"
              examples:
                BadType:
                  value:
                    status: 400
                    title: Bad Request
                    instance: kong:trace:6816496025408232265
                    detail: Bad Request
                    invalid_parameters:
                      - field: type
                        rule: enum
                        source: body
                        reason: "must be one of: [legacy,new]"
                        choices:
                          - legacy
                          - new
        "404":
          $ref: "#/components/responses/NotFound"
      tags:
        - Centrally Managed Keys
security:
  - systemAccountAccessToken: []
  - personalAccessToken: []
  - konnectAccessToken: []
components:
  parameters:
    realmId:
      name: realmId
      in: path
      required: true
      description: ID of the realm
      schema:
        type: string
        format: uuid
    consumerId:
      name: consumerId
      in: path
      required: true
      description: ID of the of the consumer
      schema:
        type: string
  requestBodies:
    CreateApiKey:
      required: true
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/CreateApiKeyPayload"
          examples:
            New:
              value:
                type: new
            Legacy:
              value:
                type: legacy
                secret: S€CR€T
  schemas:
    CreateApiKeyResult:
      type: object
      properties:
        id:
          type: string
        type:
          $ref: "#/components/schemas/KeyTypeEnum"
        secret:
          type: string
          x-sensitive: true
        created_at:
          $ref: "#/components/schemas/CreatedAt"
        updated_at:
          $ref: "#/components/schemas/UpdatedAt"
        tags:
          $ref: "#/components/schemas/Tags"
      required:
        - id
        - type
        - secret
        - created_at
        - updated_at
        - tags
    BadRequestError:
      allOf:
        - $ref: "#/components/schemas/BaseError"
        - type: object
          required:
            - invalid_parameters
          properties:
            invalid_parameters:
              $ref: "#/components/schemas/InvalidParameters"
    CreateApiKeyPayload:
      oneOf:
        - $ref: "#/components/schemas/CreateApiKeyPayloadNew"
        - $ref: "#/components/schemas/CreateApiKeyPayloadLegacy"
    KeyTypeEnum:
      type: string
      enum:
        - legacy
        - new
    CreatedAt:
      description: An ISO-8601 timestamp representation of entity creation date.
      type: string
      format: date-time
      example: 2022-11-04T20:10:06.927Z
      readOnly: true
    UpdatedAt:
      description: An ISO-8601 timestamp representation of entity update date.
      type: string
      format: date-time
      example: 2022-11-04T20:10:06.927Z
      readOnly: true
    Tags:
      type: array
      items:
        type: string
      uniqueItems: true
    BaseError:
      description: standard error
      type: object
      properties:
        status:
          description: >
            The HTTP status code of the error. Useful when passing the response

            body to child properties in a frontend UI. Must be returned as an
            integer.
          type: integer
          readOnly: true
        title:
          description: |
            A short, human-readable summary of the problem. It should not
            change between occurences of a problem, except for localization.
            Should be provided as "Sentence case" for direct use in the UI.
          type: string
          readOnly: true
        type:
          description: The error type.
          type: string
          readOnly: true
        instance:
          description: |
            Used to return the correlation ID back to the user, in the format
            kong:trace:<correlation_id>. This helps us find the relevant logs
            when a customer reports an issue.
          type: string
          readOnly: true
        detail:
          description: >
            A human readable explanation specific to this occurence of the
            problem.

            This field may contain request/entity data to help the user
            understand

            what went wrong. Enclose variable values in square brackets. Should
            be

            provided as "Sentence case" for direct use in the UI.
          type: string
          readOnly: true
      required:
        - status
        - title
        - instance
        - detail
      title: Error
    InvalidParameters:
      description: invalid parameters
      type: array
      items:
        oneOf:
          - $ref: "#/components/schemas/InvalidParameterStandard"
          - $ref: "#/components/schemas/InvalidParameterMinimumLength"
          - $ref: "#/components/schemas/InvalidParameterMaximumLength"
          - $ref: "#/components/schemas/InvalidParameterChoiceItem"
          - $ref: "#/components/schemas/InvalidParameterDependentItem"
      minItems: 1
      nullable: false
      uniqueItems: true
    NotFoundError:
      allOf:
        - $ref: "#/components/schemas/BaseError"
        - type: object
          properties:
            status:
              example: 404
            title:
              example: Not Found
            type:
              example: https://httpstatuses.com/404
            instance:
              example: kong:trace:1234567890
            detail:
              example: Not found
    CreateApiKeyPayloadNew:
      type: object
      properties:
        type:
          type: string
          default: new
          enum:
            - new
        tags:
          $ref: "#/components/schemas/Tags"
      additionalProperties: false
      required:
        - type
    CreateApiKeyPayloadLegacy:
      type: object
      properties:
        type:
          type: string
          default: legacy
          enum:
            - legacy
        secret:
          description: secret to be created. Must be unique within the realm. If not
            specified a secret will be automatically generated.
          type: string
          x-sensitive: true
        tags:
          $ref: "#/components/schemas/Tags"
      additionalProperties: false
      required:
        - type
        - secret
    InvalidParameterStandard:
      type: object
      properties:
        field:
          type: string
          example: name
          readOnly: true
        rule:
          $ref: "#/components/schemas/InvalidRules"
        source:
          type: string
          example: body
        reason:
          type: string
          example: is a required field
          readOnly: true
      additionalProperties: false
      required:
        - field
        - reason
    InvalidParameterMinimumLength:
      type: object
      properties:
        field:
          type: string
          example: name
          readOnly: true
        rule:
          description: invalid parameters rules
          type: string
          enum:
            - min_length
            - min_digits
            - min_lowercase
            - min_uppercase
            - min_symbols
            - min_items
            - min
          nullable: false
          readOnly: true
        minimum:
          type: integer
          example: 8
        source:
          type: string
          example: body
        reason:
          type: string
          example: must have at least 8 characters
          readOnly: true
      additionalProperties: false
      required:
        - field
        - reason
        - rule
        - minimum
    InvalidParameterMaximumLength:
      type: object
      properties:
        field:
          type: string
          example: name
          readOnly: true
        rule:
          description: invalid parameters rules
          type: string
          enum:
            - max_length
            - max_items
            - max
          nullable: false
          readOnly: true
        maximum:
          type: integer
          example: 8
        source:
          type: string
          example: body
        reason:
          type: string
          example: must not have more than 8 characters
          readOnly: true
      additionalProperties: false
      required:
        - field
        - reason
        - rule
        - maximum
    InvalidParameterChoiceItem:
      type: object
      properties:
        field:
          type: string
          example: name
          readOnly: true
        rule:
          description: invalid parameters rules
          type: string
          enum:
            - enum
          nullable: false
          readOnly: true
        reason:
          type: string
          example: is a required field
          readOnly: true
        choices:
          type: array
          items: {}
          minItems: 1
          nullable: false
          readOnly: true
          uniqueItems: true
        source:
          type: string
          example: body
      additionalProperties: false
      required:
        - field
        - reason
        - rule
        - choices
    InvalidParameterDependentItem:
      type: object
      properties:
        field:
          type: string
          example: name
          readOnly: true
        rule:
          description: invalid parameters rules
          type: string
          enum:
            - dependent_fields
          nullable: true
          readOnly: true
        reason:
          type: string
          example: is a required field
          readOnly: true
        dependents:
          type: array
          items: {}
          nullable: true
          readOnly: true
          uniqueItems: true
        source:
          type: string
          example: body
      additionalProperties: false
      required:
        - field
        - rule
        - reason
        - dependents
    InvalidRules:
      description: invalid parameters rules
      type: string
      enum:
        - required
        - is_array
        - is_base64
        - is_boolean
        - is_date_time
        - is_integer
        - is_null
        - is_number
        - is_object
        - is_string
        - is_uuid
        - is_fqdn
        - is_arn
        - unknown_property
        - missing_reference
        - is_label
        - matches_regex
        - invalid
        - is_supported_network_availability_zone_list
        - is_supported_network_cidr_block
        - is_supported_provider_region
        - type
      nullable: true
      readOnly: true
  examples:
    CreateApiKeyResult:
      value:
        id: 2cec70a4-d197-495c-8f3e-c0a1199d1da4
        type: new
        secret: 1_7YQ4eVaGyskxnMuvLFwm4_NfsDNyzHccHgD741EjpMGMZLLQUbQtDU92nGzpYgNWr8qs2rA_65ef014d
        tags:
          - one
          - two
        created_at: 2023-03-20T09:29:14.52Z
        updated_at: 2023-03-21T09:29:14.52Z
    CreateApiKeyResultLegacy:
      value:
        id: 2cec70a4-d197-495c-8f3e-c0a1199d1da4
        type: legacy
        secret: S€CR€T
        tags:
          - one
          - two
        created_at: 2023-03-20T09:29:14.52Z
        updated_at: 2023-03-21T09:29:14.52Z
    NotFoundExample:
      value:
        status: 404
        title: Not Found
        instance: kong:trace:6816496025408232265
        detail: Not Found
  responses:
    NotFound:
      description: Not Found
      content:
        application/problem+json:
          schema:
            $ref: "#/components/schemas/NotFoundError"
          examples:
            NotFoundExample:
              $ref: "#/components/examples/NotFoundExample"
  securitySchemes:
    systemAccountAccessToken:
      type: http
      scheme: bearer
      bearerFormat: Token
      description: >
        The system account access token is meant for automations and
        integrations that are not directly associated with a human identity.

        You can generate a system account Access Token by creating a system
        account and then obtaining a system account access token for that
        account.

        The access token must be passed in the header of a request, for example:

        `curl -X GET 'https://global.api.konghq.com/v2/users/' --header
        'Authorization: Bearer spat_i2Ej...'`
    personalAccessToken:
      type: http
      scheme: bearer
      bearerFormat: Token
      description: >
        The personal access token is meant to be used as an alternative to
        basic-auth when accessing Konnect via APIs.

        You can generate a Personal Access Token (PAT) from the [personal access
        token page](https://cloud.konghq.com/global/account/tokens/) in the
        Konnect dashboard.

        The PAT token must be passed in the header of a request, for example:

        `curl -X GET 'https://global.api.konghq.com/v2/users/' --header
        'Authorization: Bearer kpat_xgfT...'`
    konnectAccessToken:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: >
        The Konnect access token is meant to be used by the Konnect dashboard
        and the decK CLI authenticate with.
```
