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

# Create an API key

> Requires scope: keys. The raw key is returned only once.



## OpenAPI

````yaml /openapi.json post /api-keys
openapi: 3.1.0
info:
  title: MapX SaaS API
  version: 1.0.0
  description: >-
    Public REST API for MapX. Authenticate with a personal API key (Bearer
    mkx_...) created from the MapX account. All endpoints are scoped to the
    account that owns the key; each endpoint also enforces a capability scope
    (session, chat, files, layers, map, reports, remote, keys). Errors use a
    uniform envelope: {"error":{"code","message","details"}}. Rate limit: 300
    requests per minute per key. The API resource is named `session` for
    historical reasons; it represents a persistent project in the product (a
    workspace with map state, layers, files, chat history, and reports).
servers:
  - url: https://api.mapxagent.com/api/v1
    description: Production
  - url: http://localhost:3001/api/v1
    description: Local development
security:
  - bearerAuth: []
tags:
  - name: Projects
    description: Project lifecycle and metadata.
  - name: Authentication
    description: API key validation.
  - name: Map
    description: Map state and actions.
  - name: Chat
    description: AI chat turns and question responses.
  - name: Files
    description: File listing, upload, and content access.
  - name: Layers
    description: Layer metadata, style, visibility, and ordering.
  - name: Reports
    description: HTML report generation and metadata.
  - name: API Keys
    description: Personal API key management.
  - name: Usage
    description: Current plan usage.
  - name: Meta
    description: API metadata.
paths:
  /api-keys:
    post:
      tags:
        - API Keys
      summary: Create an API key
      description: 'Requires scope: keys. The raw key is returned only once.'
      operationId: createApiKey
      requestBody:
        required: true
        description: >-
          API key configuration. The raw key is returned only once; store it
          immediately.
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                  minLength: 1
                  maxLength: 64
                  description: API key display name (1-64 characters).
                expiresAt:
                  anyOf:
                    - type: string
                      format: date-time
                      pattern: >-
                        ^(?:(?:\d\d[2468][048]|\d\d[13579][26]|\d\d0[48]|[02468][048]00|[13579][26]00)-02-29|\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\d|30)|(?:02)-(?:0[1-9]|1\d|2[0-8])))T(?:(?:[01]\d|2[0-3]):[0-5]\d(?::[0-5]\d(?:\.\d+)?)?(?:Z))$
                    - type: 'null'
                  description: >-
                    ISO 8601 expiry timestamp. Omitted or null means the key
                    never expires.
                scopes:
                  description: >-
                    Capability scopes. Empty array or ["*"] grants all access.
                    Allowed values: session, chat, files, layers, map, reports,
                    remote, keys.
                  type: array
                  items:
                    type: string
              required:
                - name
              additionalProperties: false
      responses:
        '201':
          description: API key created with the raw key.
          content:
            application/json:
              schema:
                type: object
                required:
                  - id
                  - name
                  - prefix
                  - scopes
                  - enabled
                  - createdAt
                  - key
                properties:
                  id:
                    type: string
                    description: API key id.
                  name:
                    type: string
                    description: Display name.
                  prefix:
                    type: string
                    description: Key prefix (first 8 characters of mkx_...).
                  scopes:
                    type: array
                    items:
                      type: string
                    description: Granted scopes; ["*"] means all access.
                  enabled:
                    type: boolean
                    description: Whether the key is active.
                  expiresAt:
                    type:
                      - string
                      - 'null'
                    format: date-time
                    description: Expiry time; null means never expires.
                  createdAt:
                    type: string
                    format: date-time
                    description: Creation time.
                  key:
                    type: string
                    description: >-
                      Raw API key (mkx_...). Only returned once at creation;
                      store it immediately.
                additionalProperties: false
        '400':
          description: Bad request — invalid or missing fields
          content:
            application/json:
              schema:
                type: object
                required:
                  - error
                properties:
                  error:
                    type: object
                    required:
                      - code
                      - message
                    properties:
                      code:
                        type: string
                        description: MapX v1 error code.
                        enum:
                          - bad_request
                          - unauthorized
                          - forbidden
                          - not_found
                          - conflict
                          - rate_limited
                          - usage_limit_exceeded
                          - internal_error
                      message:
                        type: string
                      details:
                        description: Optional extra context.
        '401':
          description: Missing or invalid API key
          content:
            application/json:
              schema:
                type: object
                required:
                  - error
                properties:
                  error:
                    type: object
                    required:
                      - code
                      - message
                    properties:
                      code:
                        type: string
                        description: MapX v1 error code.
                        enum:
                          - bad_request
                          - unauthorized
                          - forbidden
                          - not_found
                          - conflict
                          - rate_limited
                          - usage_limit_exceeded
                          - internal_error
                      message:
                        type: string
                      details:
                        description: Optional extra context.
        '403':
          description: Forbidden — insufficient scope or disabled account
          content:
            application/json:
              schema:
                type: object
                required:
                  - error
                properties:
                  error:
                    type: object
                    required:
                      - code
                      - message
                    properties:
                      code:
                        type: string
                        description: MapX v1 error code.
                        enum:
                          - bad_request
                          - unauthorized
                          - forbidden
                          - not_found
                          - conflict
                          - rate_limited
                          - usage_limit_exceeded
                          - internal_error
                      message:
                        type: string
                      details:
                        description: Optional extra context.
        '404':
          description: Not found
          content:
            application/json:
              schema:
                type: object
                required:
                  - error
                properties:
                  error:
                    type: object
                    required:
                      - code
                      - message
                    properties:
                      code:
                        type: string
                        description: MapX v1 error code.
                        enum:
                          - bad_request
                          - unauthorized
                          - forbidden
                          - not_found
                          - conflict
                          - rate_limited
                          - usage_limit_exceeded
                          - internal_error
                      message:
                        type: string
                      details:
                        description: Optional extra context.
        '409':
          description: Conflict — e.g. a chat turn is already in progress
          content:
            application/json:
              schema:
                type: object
                required:
                  - error
                properties:
                  error:
                    type: object
                    required:
                      - code
                      - message
                    properties:
                      code:
                        type: string
                        description: MapX v1 error code.
                        enum:
                          - bad_request
                          - unauthorized
                          - forbidden
                          - not_found
                          - conflict
                          - rate_limited
                          - usage_limit_exceeded
                          - internal_error
                      message:
                        type: string
                      details:
                        description: Optional extra context.
        '429':
          description: Rate limited or usage limit reached
          content:
            application/json:
              schema:
                type: object
                required:
                  - error
                properties:
                  error:
                    type: object
                    required:
                      - code
                      - message
                    properties:
                      code:
                        type: string
                        description: MapX v1 error code.
                        enum:
                          - bad_request
                          - unauthorized
                          - forbidden
                          - not_found
                          - conflict
                          - rate_limited
                          - usage_limit_exceeded
                          - internal_error
                      message:
                        type: string
                      details:
                        description: Optional extra context.
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: Personal API key (mkx_...) created from the MapX account.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.