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

# Chat Completions

> OpenAI Chat Completions–compatible endpoint on the Modellix LLM gateway. Accepts a synchronous request with `model` (provider/name format) and an OpenAI-style `messages` array; returns a chat.completion JSON object by default, or SSE (`text/event-stream`) when `stream=true`. Use this path for the OpenAI SDK, Codex, and most OpenAI-compatible chat clients. Do not send Responses fields (`input`, `max_output_tokens`) or Anthropic Messages-only shapes on this endpoint—use `/responses` or `/messages` instead. Optional fields follow [OpenAI Chat Completions](https://platform.openai.com/docs/api-reference/chat); support depends on the selected model.



## OpenAPI

````yaml /llm/llm.json post /chat/completions
openapi: 3.1.0
info:
  title: Modellix LLM API
  description: >-
    Public API of the Modellix LLM Gateway (llm-bff): OpenAI-compatible Chat
    Completions and Responses, plus Anthropic-compatible Messages.


    Optional fields follow the corresponding official protocols; this document
    lists commonly used core fields only. See `docs/api/llm.md` for the
    human-readable guide.
  version: '2026-08-04'
  contact:
    name: Modellix
servers:
  - url: https://llm.modellix.ai/v1
    description: Production
security:
  - BearerAuth: []
  - ApiKeyAuth: []
tags:
  - name: Chat Completions
    description: OpenAI-compatible Chat Completions
  - name: Responses
    description: OpenAI-compatible Responses
  - name: Messages
    description: Anthropic-compatible Messages
paths:
  /chat/completions:
    post:
      tags:
        - Chat Completions
      summary: Chat Completions
      description: >-
        OpenAI Chat Completions–compatible endpoint on the Modellix LLM gateway.
        Accepts a synchronous request with `model` (provider/name format) and an
        OpenAI-style `messages` array; returns a chat.completion JSON object by
        default, or SSE (`text/event-stream`) when `stream=true`. Use this path
        for the OpenAI SDK, Codex, and most OpenAI-compatible chat clients. Do
        not send Responses fields (`input`, `max_output_tokens`) or Anthropic
        Messages-only shapes on this endpoint—use `/responses` or `/messages`
        instead. Optional fields follow [OpenAI Chat
        Completions](https://platform.openai.com/docs/api-reference/chat);
        support depends on the selected model.
      operationId: createChatCompletion
      parameters:
        - $ref: '#/components/parameters/SessionIdHeader'
      requestBody:
        required: true
        description: >-
          OpenAI Chat Completions request body. Requires model and messages;
          optional stream, max_tokens, max_completion_tokens, temperature, and
          n.
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ChatCompletionRequest'
            examples:
              nonStream:
                summary: Non-streaming
                value:
                  model: openai/gpt-5.6-sol
                  stream: false
                  max_tokens: 256
                  messages:
                    - role: user
                      content: Introduce yourself in one sentence
              stream:
                summary: Streaming
                value:
                  model: openai/gpt-5.6-sol
                  stream: true
                  max_tokens: 256
                  messages:
                    - role: user
                      content: ping
      responses:
        '200':
          description: Success. Non-streaming returns JSON; streaming returns SSE.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChatCompletionResponse'
            text/event-stream:
              schema:
                type: string
                description: >-
                  SSE: `data: {chat.completion.chunk}` lines, terminated by
                  `data: [DONE]`
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '402':
          $ref: '#/components/responses/PaymentRequired'
        '404':
          $ref: '#/components/responses/NotFound'
        '429':
          $ref: '#/components/responses/RateLimited'
        5XX:
          $ref: '#/components/responses/UpstreamError'
components:
  parameters:
    SessionIdHeader:
      name: X-Mdlx-Session-Id
      in: header
      required: false
      description: >-
        Optional session affinity header. Length 8–128; alphanumeric, `-`, and
        `_` only.
      schema:
        type: string
        minLength: 8
        maxLength: 128
        pattern: ^[A-Za-z0-9_-]+$
        example: my-conversation-001
  schemas:
    ChatCompletionRequest:
      type: object
      required:
        - model
        - messages
      additionalProperties: true
      description: Core fields below; other fields follow OpenAI Chat Completions.
      properties:
        model:
          $ref: '#/components/schemas/ModelId'
        messages:
          type: array
          minItems: 1
          description: >-
            OpenAI Chat Completions message list (min 1). Each item has role and
            content; roles include system, user, assistant, and tool.
          items:
            $ref: '#/components/schemas/ChatMessage'
        stream:
          type: boolean
          default: false
          description: >-
            Default false. When true, returns SSE chat.completion.chunk events
            ending with data: [DONE].
        max_tokens:
          type: integer
          minimum: 1
          description: Optional maximum number of tokens to generate. Model-dependent.
        max_completion_tokens:
          type: integer
          minimum: 1
          description: Optional generation cap preferred by some newer OpenAI-style models.
        temperature:
          type: number
          description: Sampling temperature for Chat Completions. Model-dependent.
        'n':
          type: integer
          minimum: 1
          description: Number of chat completion choices to generate.
    ChatCompletionResponse:
      type: object
      additionalProperties: true
      description: Shape follows OpenAI chat.completion
      properties:
        id:
          type: string
          description: Unique identifier for this chat completion.
        object:
          type: string
          example: chat.completion
          description: Object type. Typically chat.completion for non-streaming responses.
        created:
          type: integer
          description: Unix timestamp (seconds) when the chat completion was created.
        model:
          type: string
          description: Model ID that produced this chat completion.
        choices:
          type: array
          description: List of chat completion choices.
          items:
            type: object
            additionalProperties: true
            description: >-
              A single OpenAI chat completion choice (message, finish_reason,
              index, and related fields).
        usage:
          $ref: '#/components/schemas/Usage'
    ModelId:
      type: string
      description: Model ID in `provider/name` form
      examples:
        - openai/gpt-5.5
        - openai/gpt-5.6-sol
        - anthropic/claude-sonnet-5
        - google/gemini-3.6-flash
    ChatMessage:
      type: object
      required:
        - role
        - content
      additionalProperties: true
      description: A single OpenAI Chat Completions message with role and content.
      properties:
        role:
          type: string
          description: e.g. system / user / assistant / tool
        content:
          description: Text string or content-part array
          oneOf:
            - type: string
            - type: array
              items:
                type: object
                additionalProperties: true
                description: OpenAI Chat Completions content part object
    Usage:
      type: object
      additionalProperties: true
      description: OpenAI chat.completion token usage counts.
      properties:
        prompt_tokens:
          type: integer
          description: Number of tokens in the prompt for Chat Completions.
        completion_tokens:
          type: integer
          description: Number of tokens in the generated completion.
        total_tokens:
          type: integer
          description: Total tokens used (prompt plus completion).
    ErrorBody:
      type: object
      required:
        - error
      description: >-
        Gateway error envelope shared by Chat Completions, Responses, and
        Messages.
      properties:
        error:
          type: object
          required:
            - message
            - type
          additionalProperties: true
          description: Error details object.
          properties:
            message:
              type: string
              description: Human-readable error message.
            type:
              type: string
              description: >-
                Error type string (for example invalid_request_error,
                rate_limit_exceeded, insufficient_quota).
              examples:
                - invalid_request_error
                - api_error
                - rate_limit_exceeded
                - request_limited
                - insufficient_quota
            code:
              type:
                - string
                - 'null'
              description: Optional machine-readable error code, or null.
            param:
              type:
                - string
                - 'null'
              description: Optional parameter name related to the error, or null.
  responses:
    BadRequest:
      description: Invalid request parameters
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorBody'
    Unauthorized:
      description: >-
        Missing or invalid API key, or conflicting Authorization and x-api-key
        values
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorBody'
          example:
            error:
              message: invalid API key
              type: invalid_request_error
    PaymentRequired:
      description: Insufficient account balance
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorBody'
          example:
            error:
              message: insufficient balance, please recharge your account
              type: insufficient_quota
    NotFound:
      description: Unknown path, or the selected model is unavailable
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorBody'
          examples:
            modelUnavailable:
              summary: Model unavailable
              value:
                error:
                  message: the selected model is unavailable
                  type: invalid_request_error
    RateLimited:
      description: >-
        Rate limited (RPM or other request limits), or the selected model is
        temporarily unavailable (e.g. upstream deployment cooldown)
      headers:
        X-RateLimit-Limit:
          description: Maximum number of requests allowed in the current rate-limit window.
          schema:
            type: integer
        X-RateLimit-Remaining:
          description: Number of requests remaining in the current rate-limit window.
          schema:
            type: integer
        X-RateLimit-Reset:
          description: Unix timestamp (seconds) when the current rate-limit window resets.
          schema:
            type: integer
        Retry-After:
          schema:
            type: integer
          description: >-
            May be returned when the model is temporarily unavailable; value in
            seconds
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorBody'
          examples:
            rpm:
              summary: RPM exceeded
              value:
                error:
                  message: rate limit exceeded
                  type: rate_limit_exceeded
            modelCooldown:
              summary: Model temporarily unavailable
              value:
                error:
                  message: >-
                    the selected model is temporarily unavailable, please retry
                    later or try another model
                  type: api_error
    UpstreamError:
      description: >-
        Temporary service unavailability or upstream error (client-facing
        message may be sanitized)
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorBody'
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: API Key
      description: >-
        Authorization: Bearer <Modellix API Key> (OpenAI SDK, Codex, OpenCode,
        etc.)
    ApiKeyAuth:
      type: apiKey
      in: header
      name: x-api-key
      description: >-
        x-api-key: <Modellix API Key> (Anthropic SDK, Claude Code, etc.).
        Equivalent to Bearer; if both are present they must be the same key.

````