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

# Create chat completion

> Creates a completion for the chat conversation. Fully OpenAI compatible. Any additional property supported by the target model (e.g., `tools`, `response_format`, `top_p`) will be passed through.



## OpenAPI

````yaml /api-reference/openapi.json post /chat/completions
openapi: 3.1.0
info:
  title: LLM Router API
  description: >-
    Intelligent AI Gateway with smart routing, Skills, Zero Data Retention, and
    cost optimization. Fully compatible with the OpenAI API.
  version: 1.0.0
  contact:
    name: LLM Router Support
    url: https://docs.llmrouter.app
servers:
  - url: https://api.llmrouter.app/v1
    description: Production Server
security:
  - bearerAuth: []
paths:
  /chat/completions:
    post:
      tags:
        - Chat
      summary: Create chat completion
      description: >-
        Creates a completion for the chat conversation. Fully OpenAI compatible.
        Any additional property supported by the target model (e.g., `tools`,
        `response_format`, `top_p`) will be passed through.
      requestBody:
        description: Chat completion request parameters
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ChatCompletionRequest'
      responses:
        '200':
          description: Successful chat completion response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChatCompletionResponse'
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
components:
  schemas:
    ChatCompletionRequest:
      type: object
      required:
        - model
        - messages
      properties:
        model:
          type: string
          description: ID of the model to use (e.g., anthropic/claude-3-5-sonnet)
        messages:
          type: array
          items:
            $ref: '#/components/schemas/Message'
        temperature:
          type: number
          default: 1
        max_tokens:
          type: integer
        stream:
          type: boolean
          default: false
        gateway:
          $ref: '#/components/schemas/GatewayConfig'
      additionalProperties: true
      description: >-
        Accepts any additional properties supported by the upstream model (e.g.,
        tools, top_p, response_format).
    ChatCompletionResponse:
      type: object
      properties:
        id:
          type: string
        object:
          type: string
        created:
          type: integer
        model:
          type: string
        choices:
          type: array
          items:
            type: object
            properties:
              index:
                type: integer
              message:
                $ref: '#/components/schemas/Message'
              finish_reason:
                type: string
        usage:
          type: object
          properties:
            prompt_tokens:
              type: integer
            completion_tokens:
              type: integer
            total_tokens:
              type: integer
            cost:
              type: integer
              description: >-
                The cost of the AI model usage for this request without the
                routing/analysis cost
            planning_usage_details:
              allOf:
                - $ref: '#/components/schemas/Usage'
              nullable: true
              description: >-
                The cost breakdown for the planning/reasoning phase of the
                request (if applicable). Can be null.
      additionalProperties: true
    Error:
      type: object
      required:
        - error
      properties:
        error:
          type: object
          properties:
            message:
              type: string
            code:
              type: string
              nullable: true
              enum:
                - UNAUTHORIZED
                - FORBIDDEN
                - INTERNAL_SERVER_ERROR
                - BAD_REQUEST
                - USER_NOT_FOUND
                - MODEL_NOT_FOUND
                - EXCEEDS_MONTHLY_LIMIT
                - INVALID_GATEWAY_SETTINGS
                - TOO_MANY_REQUESTS
              description: Error code (can be null or undefined)
          additionalProperties: true
      additionalProperties: true
    Message:
      type: object
      required:
        - role
        - content
      properties:
        role:
          type: string
          enum:
            - system
            - user
            - assistant
            - tool
            - function
        content:
          type:
            - string
            - array
          description: >-
            The contents of the message. Can be a string or an array of
            multimodal content parts.
        name:
          type: string
      additionalProperties: true
    GatewayConfig:
      type: object
      description: Custom LLM Router configurations injected into the request.
      properties:
        zdr:
          type: boolean
          description: >-
            If true, enforces Zero Data Retention by only routing to non-logging
            providers.
        order:
          type: array
          items:
            type: string
          description: Priority list of provider slugs for fallbacks.
        only:
          type: array
          items:
            type: string
          description: Strict whitelist of allowed provider slugs.
        planningTriggerScore:
          type: number
          minimum: 0
          maximum: 1
          description: Threshold to trigger the Chain-of-Thought planning model.
        imageGenerationModel:
          type: string
          description: Fallback model used if the request requires an image output.
        tags:
          type: array
          description: Intent-based routing rules.
          items:
            type: object
            required:
              - name
              - description
              - models
            properties:
              name:
                type: string
              description:
                type: string
              models:
                type: array
                items:
                  type: string
        skills:
          type: object
          required:
            - skillIds
          properties:
            skillIds:
              type: array
              items:
                type: string
            enableAutoSearch:
              type: boolean
              default: false
        chatHistoryCompression:
          type: object
          properties:
            enabled:
              type: boolean
              default: false
            score:
              type: number
              minimum: 0
              maximum: 1
              default: 0.6
        mediaOptimization:
          type: boolean
          default: false
        toolOptimization:
          type: object
          properties:
            enabled:
              type: boolean
              default: false
            acceptScore:
              type: number
              minimum: 0
              maximum: 1
              default: 0.5
            alwaysInclude:
              type: array
              items:
                type: string
        redact:
          type: object
          description: PII redaction configuration
          properties:
            email:
              type: boolean
            phone:
              type: boolean
            ip:
              type: boolean
            uuid:
              type: boolean
            token:
              type: boolean
            credit_card:
              type: boolean
            iban:
              type: boolean
            ssn:
              type: boolean
            mac:
              type: boolean
            custom:
              type: array
              items:
                type: string
    Usage:
      type: object
      properties:
        prompt_tokens:
          type: integer
        completion_tokens:
          type: integer
        total_tokens:
          type: integer
        cost:
          type: integer
          description: Total model usage cost (excluding routing fees)
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: LLM Router API Key (e.g., sk-llmr-...)

````