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

# Create Api Key

> Create a new API key for the authenticated user.

The new key is bound to ``key_data.org_id`` when provided. An *omitted*
``org_id`` falls back to the request's effective org (preserving the
pre-existing API). An *explicit* ``org_id: null`` creates an unbound
key whose effective org is resolved per-request via the ``X-Org-Id``
header or, as a fallback, the caller's ``user.current_org_id``. When a
specific ``org_id`` is supplied, the caller must be a member of that
org (or hold a super role).



## OpenAPI

````yaml /openapi/openhands-cloud.json post /api/keys
openapi: 3.1.0
info:
  title: OpenHands
  description: 'OpenHands: Code Less, Make More'
  version: 0.0.1
servers: []
security: []
paths:
  /api/keys:
    post:
      tags:
        - Keys
      summary: Create Api Key
      description: |-
        Create a new API key for the authenticated user.

        The new key is bound to ``key_data.org_id`` when provided. An *omitted*
        ``org_id`` falls back to the request's effective org (preserving the
        pre-existing API). An *explicit* ``org_id: null`` creates an unbound
        key whose effective org is resolved per-request via the ``X-Org-Id``
        header or, as a fallback, the caller's ``user.current_org_id``. When a
        specific ``org_id`` is supplied, the caller must be a member of that
        org (or hold a super role).
      operationId: create_api_key_api_keys_post
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ApiKeyCreate'
        required: true
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiKeyCreateResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - APIKeyHeader: []
components:
  schemas:
    ApiKeyCreate:
      properties:
        name:
          anyOf:
            - type: string
            - type: 'null'
          title: Name
        not_before:
          anyOf:
            - type: string
              format: date-time
            - type: 'null'
          title: Not Before
        expires_at:
          anyOf:
            - type: string
              format: date-time
            - type: 'null'
          title: Expires At
        org_id:
          anyOf:
            - type: string
              format: uuid
            - type: 'null'
          title: Org Id
      type: object
      title: ApiKeyCreate
    ApiKeyCreateResponse:
      properties:
        id:
          type: integer
          title: Id
        name:
          anyOf:
            - type: string
            - type: 'null'
          title: Name
        created_at:
          type: string
          format: date-time
          title: Created At
        last_used_at:
          anyOf:
            - type: string
              format: date-time
            - type: 'null'
          title: Last Used At
        not_before:
          anyOf:
            - type: string
              format: date-time
            - type: 'null'
          title: Not Before
        expires_at:
          anyOf:
            - type: string
              format: date-time
            - type: 'null'
          title: Expires At
        org_id:
          anyOf:
            - type: string
              format: uuid
            - type: 'null'
          title: Org Id
        key:
          type: string
          title: Key
      type: object
      required:
        - id
        - created_at
        - key
      title: ApiKeyCreateResponse
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
        input:
          title: Input
        ctx:
          type: object
          title: Context
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
  securitySchemes:
    APIKeyHeader:
      type: apiKey
      in: header
      name: X-Access-Token

````