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

# Create a chat completion

> Creates a model response for the given conversation. Supports streaming via SSE,
tool calling, and multi-modal input (text, images, files).



## OpenAPI

````yaml /spec/ai-chat-completions.yaml post /api/{workspaceID}/v1/chat/completions
openapi: 3.0.1
info:
  title: AI - Chat Completions
  description: >-
    OpenAI-compatible chat completion endpoints for AI inference with support
    for streaming, tool calling, and multi-modal inputs.


    Parameters:

    - `workspaceID`: The ID of the workspace to use for billing and routing

    - `teamID`: To access services in a team (query param or `x-teamid` header)


    Authentication: API Key (Bearer token) sent via the `Authorization` header.
  termsOfService: '#'
  contact:
    email: info@liara.ir
  version: 1.0.0
servers:
  - url: https://ai.liara.ir
security:
  - apiKey: []
tags:
  - name: Chat Completions
    description: Generate chat completions with various AI models
  - name: Models
    description: List available AI models for inference
externalDocs:
  description: Find out more about Liara AI
  url: https://liara.ir
paths:
  /api/{workspaceID}/v1/chat/completions:
    post:
      tags:
        - Chat Completions
      summary: Create a chat completion
      description: >-
        Creates a model response for the given conversation. Supports streaming
        via SSE,

        tool calling, and multi-modal input (text, images, files).
      operationId: createChatCompletion
      parameters:
        - name: workspaceID
          in: path
          required: true
          description: The workspace ID
          schema:
            type: string
            pattern: ^[a-f0-9]{24}$
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ChatCompletionRequest'
      responses:
        '200':
          description: Successful response (non-streaming)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChatCompletionResponse'
        '400':
          description: Bad request
          content: {}
        '401':
          description: Missing authentication
          content: {}
        '402':
          description: Payment required - insufficient balance
          content: {}
        '403':
          description: Forbidden - workspace frozen or key disabled
          content: {}
        '503':
          description: Service unavailable (feature disabled)
          content: {}
components:
  schemas:
    ChatCompletionRequest:
      type: object
      required:
        - model
        - messages
      properties:
        model:
          type: string
          description: Model ID
          example: openai/gpt-5
        messages:
          type: array
          description: Array of conversation messages
          items:
            $ref: '#/components/schemas/ChatMessage'
        stream:
          type: boolean
          default: false
          description: Enable SSE streaming
        stream_options:
          type: object
          properties:
            include_usage:
              type: boolean
              description: Include usage stats in streaming response
        max_tokens:
          type: integer
          description: Maximum tokens to generate
        max_completion_tokens:
          type: integer
          description: Maximum completion tokens (OpenAI-style)
        temperature:
          type: number
          description: Sampling temperature (0-2)
        top_p:
          type: number
          description: Nucleus sampling parameter
        top_k:
          type: number
          description: Top-K sampling parameter
        frequency_penalty:
          type: number
          description: Frequency penalty (-2 to 2)
        presence_penalty:
          type: number
          description: Presence penalty (-2 to 2)
        repetition_penalty:
          type: number
          description: Repetition penalty
        seed:
          type: integer
          description: Random seed for deterministic output
        'n':
          type: integer
          minimum: 1
          description: Number of completions to generate
        stop:
          description: Stop sequences
          oneOf:
            - type: string
            - type: array
              items:
                type: string
              maxItems: 4
        logit_bias:
          type: object
          description: Token ID to bias mapping
          additionalProperties:
            type: number
        logprobs:
          type: boolean
          description: Return log probabilities
        top_logprobs:
          type: integer
          description: Number of top log probabilities to return
        min_p:
          type: number
          description: Minimum probability parameter
        top_a:
          type: number
          description: Top-A sampling parameter
        reasoning:
          type: object
          description: Reasoning configuration
        reasoning_effort:
          type: string
          description: Reasoning effort level
        modalities:
          type: array
          items:
            type: string
            enum:
              - image
              - text
          description: Output modalities
        functions:
          type: array
          description: Legacy function definitions
          items:
            type: object
        tools:
          type: array
          description: Tool definitions for function calling
          items:
            type: object
        tool_choice:
          oneOf:
            - type: string
              enum:
                - none
                - auto
                - required
            - type: object
              properties:
                type:
                  type: string
                  enum:
                    - function
                function:
                  type: object
                  properties:
                    name:
                      type: string
        parallel_tool_calls:
          type: boolean
          default: true
          description: Allow parallel tool calls
        response_format:
          type: object
          description: Response format specification
        prediction:
          type: object
          description: Predicted output for latency optimization
        metadata:
          description: Additional metadata
        store:
          type: boolean
          description: Store the completion
        service_tier:
          type: string
          description: Service tier
        user:
          type: string
          description: End-user identifier
    ChatCompletionResponse:
      type: object
      properties:
        id:
          type: string
          description: Log ID
        model:
          type: string
          description: Model ID used
        object:
          type: string
          enum:
            - chat.completion
        created:
          type: integer
          format: unix-timestamp
        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
            total_cost_toman:
              type: number
            total_cost:
              type: number
    ChatMessage:
      type: object
      required:
        - role
      properties:
        role:
          type: string
          enum:
            - user
            - assistant
            - system
            - developer
            - tool
        content:
          oneOf:
            - type: string
            - type: array
              items:
                $ref: '#/components/schemas/ContentPart'
        name:
          type: string
          description: Name of the participant
        tool_calls:
          type: array
          description: Tool calls made by the assistant
          items:
            type: object
        tool_call_id:
          type: string
          description: ID of the tool call this message responds to
        refusal:
          type: string
          description: Refusal message from the assistant
    ContentPart:
      oneOf:
        - type: object
          description: Text content
          required:
            - type
            - text
          properties:
            type:
              type: string
              enum:
                - text
            text:
              type: string
        - type: object
          description: Image URL content
          required:
            - type
            - image_url
          properties:
            type:
              type: string
              enum:
                - image_url
            image_url:
              type: object
              required:
                - url
              properties:
                url:
                  type: string
                  format: uri
        - type: object
          description: File content
          required:
            - type
            - file
          properties:
            type:
              type: string
              enum:
                - file
            file:
              type: object
              required:
                - filename
                - file_data
              properties:
                filename:
                  type: string
                file_data:
                  type: string
  securitySchemes:
    apiKey:
      type: apiKey
      description: >-
        Enter the API key with the `Bearer: ` prefix, e.g. "Bearer
        <your-api-key>"
      name: Authorization
      in: header

````