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

# Create chat completion

> OpenAI-compatible chat completions. Point any OpenAI SDK at your Kubox base URL and it works unchanged, including streaming (`stream: true`, SSE chunks passed through as generated). Usage is billed per token against your credit balance.



## OpenAPI

````yaml POST /v1/chat/completions
openapi: 3.1.0
info:
  title: Kubox API
  description: >-
    OpenAI-compatible AI endpoints on sovereign Australian infrastructure.
    Authenticate with your `kbx_live_…` API key as a Bearer token. This
    reference is generated from the gateway source code.
  version: 1.0.0
servers:
  - url: https://api.kubox.ai
    description: Kubox cloud
security:
  - bearerAuth: []
paths:
  /v1/chat/completions:
    post:
      summary: Create chat completion
      description: >-
        OpenAI-compatible chat completions. Point any OpenAI SDK at your Kubox
        base URL and it works unchanged, including streaming (`stream: true`,
        SSE chunks passed through as generated). Usage is billed per token
        against your credit balance.
      operationId: createChatCompletion
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - model
                - messages
              additionalProperties: true
              properties:
                model:
                  type: string
                  description: A model id from `GET /v1/models`.
                  example: MAGPiE
                messages:
                  type: array
                  items:
                    $ref: '#/components/schemas/ChatMessage'
                stream:
                  type: boolean
                  description: When true, the response streams as server-sent events.
                  default: false
                max_tokens:
                  type: integer
                  minimum: 1
                temperature:
                  type: number
                  minimum: 0
                  maximum: 2
      responses:
        '200':
          description: >-
            The completion. JSON when `stream` is false; `text/event-stream` of
            `chat.completion.chunk` events terminated by `data: [DONE]` when
            true.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChatCompletion'
            text/event-stream:
              schema:
                type: string
                description: SSE stream of chat.completion.chunk objects.
        '401':
          description: Incorrect API key provided.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error:
                  type: invalid_request_error
                  code: invalid_api_key
                  message: Incorrect API key provided.
        '402':
          description: Insufficient credits. Top up to continue.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error:
                  type: insufficient_quota
                  code: insufficient_balance
                  message: Insufficient credits. Top up to continue.
        '404':
          description: The model `<id>` does not exist.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error:
                  type: invalid_request_error
                  code: model_not_found
                  message: The model `<id>` does not exist.
        '502':
          description: The provider rejected the request.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error:
                  type: api_error
                  code: upstream_error
                  message: The provider rejected the request.
      security:
        - bearerAuth: []
components:
  schemas:
    ChatMessage:
      type: object
      required:
        - role
        - content
      properties:
        role:
          type: string
          enum:
            - system
            - user
            - assistant
            - tool
        content:
          type: string
      additionalProperties: true
    ChatCompletion:
      type: object
      properties:
        id:
          type: string
        object:
          type: string
          enum:
            - chat.completion
        model:
          type: string
        choices:
          type: array
          items:
            type: object
            properties:
              index:
                type: integer
              message:
                $ref: '#/components/schemas/ChatMessage'
              finish_reason:
                type: string
        usage:
          type: object
          properties:
            prompt_tokens:
              type: integer
            completion_tokens:
              type: integer
            total_tokens:
              type: integer
      additionalProperties: true
    Error:
      type: object
      properties:
        error:
          type: object
          properties:
            type:
              type: string
            code:
              type: string
            message:
              type: string
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: Your Kubox API key (`kbx_live_…`) from the console.

````