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

# Gửi câu hỏi AI

> Tạo câu trả lời từ tài liệu, lịch sử và công cụ dữ liệu được phép.

Server trả JSON sau khi xử lý xong. Câu hỏi được trim; validation độ dài trong service chạy sau bước embedding/tìm tài liệu của handler. Không giả định câu hỏi không hợp lệ luôn bị từ chối trước khi gọi OpenAI.

Xem [Trợ lý AI](https://docs.taho.com.vn/ai/index.md) để hiểu dữ liệu gửi tới provider và giới hạn tra cứu.


## OpenAPI

````yaml openapi.json POST /admin/ai/chat
openapi: 3.0.3
info:
  title: 'Taho: Mini App và AI'
  version: source-review-2026-10-07
  description: >-
    Đặc tả biên soạn trong docs từ handler và service hiện tại. Không phải
    endpoint Swagger do application phục vụ; không xác nhận kết nối provider
    hoặc UAT.
servers: []
security: []
tags:
  - name: Mini App
  - name: Admin Mini App
  - name: AI
paths:
  /admin/ai/chat:
    post:
      tags:
        - AI
      summary: Gửi câu hỏi AI
      description: >-
        Cần same-origin, quyền AI và khóa OpenAI. Body tối đa 32 KiB; 20
        request/phút theo actor/tòa nhà/scope. Tìm tối đa 6 đoạn; dùng tối đa 12
        tin nhắn gần nhất khi hỏi tiếp. Trả JSON sau khi xử lý; không streaming.
      operationId: sendAiMessage
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                message:
                  type: string
                  minLength: 1
                  maxLength: 4000
                threadId:
                  type: string
                  description: >-
                    Bỏ trống để tạo thread mới; có giá trị phải thuộc chủ và tòa
                    nhà.
              required:
                - message
              additionalProperties: true
      responses:
        '200':
          description: Câu trả lời sau khi ghi lượt hỏi–đáp.
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    enum:
                      - true
                  data:
                    type: object
                    properties:
                      threadId:
                        type: string
                      message:
                        type: object
                        properties:
                          role:
                            type: string
                            enum:
                              - assistant
                          content:
                            type: string
                          citations:
                            type: array
                            items:
                              type: string
                        required:
                          - role
                          - content
                          - citations
                        additionalProperties: true
                      model:
                        type: string
                    required:
                      - threadId
                      - message
                      - model
                    additionalProperties: true
                required:
                  - success
                  - data
                additionalProperties: true
        '400':
          description: invalid-chat-request cho lỗi được publicChatError nhận diện.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: unauthorized.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '403':
          description: forbidden-origin hoặc forbidden.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '413':
          description: request-too-large.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '429':
          description: rate-limited.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '502':
          description: >-
            ai-unavailable; JSON lỗi cú pháp ngoài nhóm nhận diện cũng tới catch
            chung.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '503':
          description: ai-not-configured.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
      security:
        - AdminBearer: []
        - AdminCookie: []
components:
  schemas:
    Error:
      type: object
      properties:
        success:
          type: boolean
          enum:
            - false
        error:
          type: object
          properties:
            code:
              type: string
            message:
              type: string
            details: {}
          required:
            - code
            - message
          additionalProperties: true
      required:
        - success
        - error
      additionalProperties: true
  securitySchemes:
    AdminBearer:
      type: http
      scheme: bearer
      description: Token phiên quản trị, vẫn phải qua route/action và active tower checks.
    AdminCookie:
      type: apiKey
      in: cookie
      name: taho_jwt

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.