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

# Create API Key

> Creates a new partner API key. The response includes the `rawKey` — **it is shown only once**. Store it securely. Requires staff JWT authentication.



## OpenAPI

````yaml POST /api-keys
openapi: 3.0.3
info:
  title: Exchange Partner API
  version: 1.0.0
  description: >-
    REST API for exchange office partners. Authenticate with a Bearer API key
    (`sk_branch_*`, `sk_personal_*`, or `pk_*`). API key management endpoints
    use JWT Bearer auth from the staff panel.
servers:
  - url: https://api.example.com/api/v1
    description: Production
security:
  - bearerAuth: []
tags:
  - name: Partner — Public
    description: >-
      Read-only endpoints accessible with any key type (including pk_* public
      keys)
  - name: Partner — Exchanges
    description: Read public exchange office data and rates
  - name: Partner — Offers
    description: Browse available currency exchange rate offers
  - name: Partner — Orders
    description: Create and manage client exchange orders
  - name: Partner — Clients
    description: Register and manage client accounts
  - name: Partner — Webhooks
    description: Manage webhook endpoint registrations
  - name: API Keys
    description: Create and revoke partner API keys (JWT auth required)
paths:
  /api-keys:
    post:
      tags:
        - API Keys
      summary: Create a new API key
      description: >-
        Creates a new partner API key. The response includes the `rawKey` — **it
        is shown only once**. Store it securely. Requires staff JWT
        authentication.
      operationId: createApiKey
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateApiKeyRequest'
            example:
              name: My CRM Integration
              type: personal
      responses:
        '201':
          description: API key created. The `rawKey` field is shown only in this response.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CreateApiKeyResponse'
        '400':
          $ref: '#/components/responses/ValidationError'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
      security:
        - jwtAuth: []
components:
  schemas:
    CreateApiKeyRequest:
      type: object
      required:
        - name
        - type
      properties:
        name:
          type: string
          maxLength: 100
          example: My CRM Integration
        type:
          type: string
          enum:
            - branch
            - personal
            - public
          default: personal
        branchId:
          type: integer
          description: Required when type=branch or type=public
          example: 1
        expiresAt:
          type: string
          format: date-time
          description: ISO 8601 expiry date. Omit for no expiry.
          example: '2027-01-01T00:00:00Z'
    CreateApiKeyResponse:
      allOf:
        - $ref: '#/components/schemas/ApiKey'
        - type: object
          properties:
            rawKey:
              type: string
              description: The full API key. Shown only once — store securely.
              example: sk_personal_Ab3xYz7qR2mN9kLpW4vC8dE1fT6uS0hJ
            note:
              type: string
              example: Store this key securely — it will not be shown again.
    ApiKey:
      type: object
      properties:
        id:
          type: string
          format: uuid
        name:
          type: string
          example: My CRM Integration
        type:
          type: string
          enum:
            - branch
            - personal
            - public
        keyPrefix:
          type: string
          example: sk_personal_Ab3x
          description: First 20 chars of the key, for display
        isActive:
          type: boolean
          example: true
        lastUsedAt:
          type: string
          format: date-time
          nullable: true
        expiresAt:
          type: string
          format: date-time
          nullable: true
        createdAt:
          type: string
          format: date-time
        updatedAt:
          type: string
          format: date-time
    Error:
      type: object
      properties:
        statusCode:
          type: integer
          example: 400
        message:
          oneOf:
            - type: string
            - type: array
              items:
                type: string
          example: Validation failed
        error:
          type: string
          example: Bad Request
      required:
        - statusCode
        - message
  responses:
    ValidationError:
      description: Request body or parameters failed validation
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            statusCode: 400
            message:
              - url must be a URL address
              - events should not be empty
            error: Bad Request
    Unauthorized:
      description: Missing or invalid API key
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            statusCode: 401
            message: Unauthorized
    Forbidden:
      description: API key does not have permission to access this resource
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            statusCode: 403
            message: Forbidden
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >-
        Partner API key. Format: `sk_branch_<32chars>`, `sk_personal_<32chars>`,
        or `pk_<32chars>` (public, read-only)
    jwtAuth:
      type: http
      scheme: bearer
      description: Staff panel JWT access token

````