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

# Tạo cuộc hội thoại chat

> Tạo phản hồi của mô hình dựa trên lịch sử hội thoại. Hỗ trợ phản hồi dạng truyền trực tuyến (streaming) và không truyền trực tuyến.

Tương thích với OpenAI Chat Completions API.



## OpenAPI

````yaml api-reference/vi/openapi.json POST /v1/chat/completions
openapi: 3.0.0
info:
  title: Tài liệu tham khảo API của 出海营
  version: 1.0.0
  description: Public AI Gateway API Reference
servers:
  - url: https://api.aiid.edu.kg
security:
  - BearerAuth: []
tags:
  - name: Định dạng OpenAI (Chat)
  - name: Định dạng OpenAI (Responses)
  - name: Định dạng Gemini cho tạo ảnh
  - name: Tạo hình ảnhOpenAI định dạng DALL-E
  - name: Lấy danh sách mô hình
  - name: Tạo video HappyHorse và Wan
  - name: Định dạngKling tạo video
  - name: Định dạng Video Generation Omni và Veo
  - name: Tạo video Seedance
  - name: Định dạng tương thích Sora cho tạo video
  - name: Tạo video Vidu
  - name: Định dạng tác vụ tạo nhạc
paths:
  /v1/chat/completions:
    post:
      tags:
        - Định dạng OpenAI (Chat)
      summary: Tạo cuộc hội thoại chat
      description: >-
        Tạo phản hồi của mô hình dựa trên lịch sử hội thoại. Hỗ trợ phản hồi
        dạng truyền trực tuyến (streaming) và không truyền trực tuyến.


        Tương thích với OpenAI Chat Completions API.
      operationId: createChatCompletion
      parameters: []
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ChatCompletionRequest'
        required: true
      responses:
        '200':
          description: Phản hồi tạo thành công
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChatCompletionResponse'
          headers: {}
        '400':
          description: Tham số yêu cầu bị lỗi
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          headers: {}
        '429':
          description: Giới hạn tỷ lệ yêu cầu
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          headers: {}
      deprecated: false
      security:
        - BearerAuth: []
components:
  schemas:
    ChatCompletionRequest:
      type: object
      required:
        - model
        - messages
      properties:
        model:
          type: string
          description: ID mô hình
          example: gpt-4
        messages:
          type: array
          items:
            $ref: '#/components/schemas/Message'
          description: Danh sách tin nhắn hội thoại
        temperature:
          type: number
          minimum: 0
          maximum: 2
          default: 1
          description: Nhiệt độ lấy mẫu
        top_p:
          type: number
          minimum: 0
          maximum: 1
          default: 1
          description: Tham số Nucleus Sampling
        'n':
          type: integer
          minimum: 1
          default: 1
          description: Số lượng tạo
        stream:
          type: boolean
          default: false
          description: Có phản hồi dạng luồng (streaming) hay không
        stream_options:
          type: object
          properties:
            include_usage:
              type: boolean
        stop:
          oneOf:
            - type: string
            - type: array
              items:
                type: string
          description: Chuỗi dừng
        max_tokens:
          type: integer
          description: Số lượng Token tạo ra tối đa
        max_completion_tokens:
          type: integer
          description: Số Token hoàn thiện tối đa
        presence_penalty:
          type: number
          minimum: -2
          maximum: 2
          default: 0
        frequency_penalty:
          type: number
          minimum: -2
          maximum: 2
          default: 0
        logit_bias:
          type: object
          additionalProperties:
            type: number
          properties: {}
        user:
          type: string
        tools:
          type: array
          items:
            $ref: '#/components/schemas/Tool'
        tool_choice:
          oneOf:
            - type: string
              enum:
                - none
                - auto
                - required
            - type: object
              properties:
                type:
                  type: string
                function:
                  type: object
                  properties:
                    name:
                      type: string
        response_format:
          $ref: '#/components/schemas/ResponseFormat'
        seed:
          type: integer
        reasoning_effort:
          type: string
          enum:
            - low
            - medium
            - high
          description: Cường độ suy luận (dùng cho các mô hình hỗ trợ suy luận)
        modalities:
          type: array
          items:
            type: string
            enum:
              - text
              - audio
        audio:
          type: object
          properties:
            voice:
              type: string
            format:
              type: string
    ChatCompletionResponse:
      type: object
      properties:
        id:
          type: string
        object:
          type: string
          example: chat.completion
        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
                enum:
                  - stop
                  - length
                  - tool_calls
                  - content_filter
        usage:
          $ref: '#/components/schemas/Usage'
        system_fingerprint:
          type: string
    ErrorResponse:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
              description: Thông báo lỗi
            type:
              type: string
              description: Loại lỗi
            param:
              type: string
              description: Các tham số liên quan
              nullable: true
            code:
              type: string
              description: Mã lỗi
              nullable: true
    Message:
      type: object
      required:
        - role
        - content
      properties:
        role:
          type: string
          enum:
            - system
            - user
            - assistant
            - tool
            - developer
          description: Vai trò tin nhắn
        content:
          oneOf:
            - type: string
            - type: array
              items:
                $ref: '#/components/schemas/MessageContent'
          description: Nội dung tin nhắn
        name:
          type: string
          description: Tên người gửi
        tool_calls:
          type: array
          items:
            $ref: '#/components/schemas/ToolCall'
        tool_call_id:
          type: string
          description: ID của lệnh gọi công cụ (dùng cho tin nhắn vai trò tool)
        reasoning_content:
          type: string
          description: Nội dung suy luận
    Tool:
      type: object
      properties:
        type:
          type: string
          example: function
        function:
          type: object
          properties:
            name:
              type: string
            description:
              type: string
            parameters:
              type: object
              description: Định nghĩa tham số theo định dạng JSON Schema
              properties: {}
    ResponseFormat:
      type: object
      properties:
        type:
          type: string
          enum:
            - text
            - json_object
            - json_schema
        json_schema:
          type: object
          description: Định nghĩa JSON Schema
          properties: {}
    Usage:
      type: object
      properties:
        prompt_tokens:
          type: integer
          description: Số lượng Token của lời nhắc
        completion_tokens:
          type: integer
          description: Số Token hoàn thiện
        total_tokens:
          type: integer
          description: Tổng số Token
        prompt_tokens_details:
          type: object
          properties:
            cached_tokens:
              type: integer
            text_tokens:
              type: integer
            audio_tokens:
              type: integer
            image_tokens:
              type: integer
        completion_tokens_details:
          type: object
          properties:
            text_tokens:
              type: integer
            audio_tokens:
              type: integer
            reasoning_tokens:
              type: integer
    MessageContent:
      type: object
      properties:
        type:
          type: string
          enum:
            - text
            - image_url
            - input_audio
            - file
            - video_url
        text:
          type: string
        image_url:
          type: object
          properties:
            url:
              type: string
              description: URL hình ảnh hoặc base64
            detail:
              type: string
              enum:
                - low
                - high
                - auto
        input_audio:
          type: object
          properties:
            data:
              type: string
              description: Dữ liệu âm thanh được mã hóa Base64
            format:
              type: string
              enum:
                - wav
                - mp3
        file:
          type: object
          properties:
            filename:
              type: string
            file_data:
              type: string
            file_id:
              type: string
        video_url:
          type: object
          properties:
            url:
              type: string
    ToolCall:
      type: object
      properties:
        id:
          type: string
        type:
          type: string
          example: function
        function:
          type: object
          properties:
            name:
              type: string
            arguments:
              type: string
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      description: |-
        Sử dụng xác thực Bearer Token.
        Định dạng: `Authorization: Bearer sk-xxxxxx`

````