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

# 向智能体提问

<Note>
  智能体训练完成后（status=done），就可以通过对话接口向它提问了。
</Note>

响应数据根据是否是流式响应而变化，可以参考下面的请求示例进行判断：

### cURL 请求示例

```bash theme={null}
curl --location --request POST 'https://geekai.co/api/v1/agent/chat' \
--header 'Authorization: Bearer {YOUR_GEEKAI_API_KEY}' \
--header 'Content-Type: application/json' \
--data-raw '{
    "uuid": "智能体ID",
    "question": "用户问题",
    "messages": [
        {
            "text": "历史问题1",
            "role": "human"
        },
        {
            "text": "历史回答1",
            "role": "ai"
        }
    ],
    "stream": true
}'
```

### Postman 请求流式响应示例

<img src="https://static.geekai.co/storage/2024/07/14/image-20230813022959074.png" className="mt-2" alt="向智能体提问" />

### Postman 请求非流式响应示例

<img src="https://static.geekai.co/storage/2024/07/14/image-20230813023111564.png" className="mt-2" alt="向智能体提问" />


## OpenAPI

````yaml openapi.yaml POST /agent/chat
openapi: 3.1.0
info:
  title: GeekAI API Docs
  description: >-
    GeekAI API Specification Document Provides AI capabilities such as chat,
    image generation, speech processing, video generation, ai agents and file
    extract.
  version: 1.0.0
servers:
  - url: https://geekai.dev/api/v1
    description: base URL
security:
  - bearerAuth: []
  - apiKeyAuth: []
paths:
  /agent/chat:
    post:
      tags:
        - Agent
      summary: Chat with Agent
      description: Chat with the specified AI agent
      operationId: chatWithAgent
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - uuid
                - question
              properties:
                uuid:
                  type: string
                  format: uuid
                  description: agent UUID
                  example: 29db255d-211c-4fc6-8fbe-af97fa59cafa
                question:
                  type: string
                  description: chat question
                  example: How do I apply for XXX?
                messages:
                  type: array
                  description: chat messages
                  items:
                    type: object
                    required:
                      - text
                      - role
                    properties:
                      text:
                        type: string
                        description: message text
                      role:
                        type: string
                        enum:
                          - human
                          - ai
                        description: message role
                  example:
                    - text: How long is the warranty period for your products？
                      role: human
                    - text: Our products come with a standard one-year warranty.
                      role: ai
                stream:
                  type: boolean
                  description: enable stream output
                  default: false
                  example: true
                sess_id:
                  type: string
                  format: uuid
                  description: Session ID implemented by the third-party application.
      responses:
        '200':
          description: successful response
          content:
            application/json:
              schema:
                type: object
                required:
                  - message_id
                  - content
                properties:
                  message_id:
                    type: string
                    format: uuid
                    description: message ID
                    example: msg_123456789
                  content:
                    type: string
                    description: chat response
                    example: Our return and exchange policy is as follows:...
                  reference:
                    type: array
                    description: reference information
                    items:
                      type: object
                      properties:
                        content:
                          type: string
                          description: reference content
                        source:
                          type: string
                          description: reference source
                        confidence:
                          type: number
                          description: reference confidence
                  usage:
                    type: object
                    description: usage information
                    properties:
                      prompt_tokens:
                        type: integer
                        description: prompt token count
                      completion_tokens:
                        type: integer
                        description: completion token count
                      total_tokens:
                        type: integer
                        description: total token count
            text/event-stream:
              schema:
                type: string
                description: chat response
        '400':
          $ref: '#/components/responses/ValidationError'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          $ref: '#/components/responses/NotFound'
        '500':
          $ref: '#/components/responses/StandardError'
components:
  responses:
    ValidationError:
      description: validation error
      content:
        application/json:
          schema:
            type: object
            properties:
              code:
                type: string
                example: validation_error
              message:
                type: string
                example: validation error
              details:
                type: object
                additionalProperties:
                  type: string
                example:
                  field: error message
    Unauthorized:
      description: unauthorized
      content:
        application/json:
          schema:
            type: object
            properties:
              code:
                type: string
                example: unauthorized
              message:
                type: string
                example: invalid api key or token
    NotFound:
      description: resource not found
      content:
        application/json:
          schema:
            type: object
            properties:
              code:
                type: string
                example: not_found
              message:
                type: string
                example: resource not found
    StandardError:
      description: standard error response
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
  schemas:
    Error:
      type: object
      required:
        - code
        - message
      properties:
        code:
          type: string
          description: error code
          example: invalid_request
        message:
          type: string
          description: error message
          example: invalid request
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: token
    apiKeyAuth:
      type: apiKey
      in: header
      name: X-API-Key
      description: api key

````