# 向聊天机器人发送消息

## OpenAPI Specification

```yaml
openapi: 3.0.1
info:
  title: ''
  description: ''
  version: 1.0.0
paths:
  /api/v1/chat:
    post:
      summary: 向聊天机器人发送消息
      deprecated: false
      description: >-
        聊天机器人交互 API 允许您使用请求与聊天机器人交互。此 API
        可供订阅付费计划的用户使用，并提供了一种以编程方式与聊天机器人进行通信的方法。


        ## 保存对话


        为了将对话保存到仪表板，需要在请求正文中包含一个参数。每次 API 调用都需要发送完整的对话，因为 Chatbase
        不保存以前的消息。在给定的最新 API 调用中收到的消息会覆盖已保存在那里的对话。`conversationId``converstionId`


        ## 错误处理


        如果 API 请求期间出现任何错误，相应的 HTTP 状态代码将与响应正文中的错误消息一起返回。确保在您的应用程序中妥善处理这些错误。


        就是这样！您现在应该能够使用消息 API 向聊天机器人发送消息。
      tags: []
      parameters:
        - name: Authorization
          in: header
          description: ''
          required: true
          example: Bearer <Your-Secret-Key>
          schema:
            type: string
        - name: Content-Type
          in: header
          description: ''
          required: true
          example: application/json
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                messages:
                  type: array
                  items:
                    type: object
                    properties:
                      content:
                        type: string
                      role:
                        type: string
                    required:
                      - content
                      - role
                    x-apifox-orders:
                      - content
                      - role
                  description: >-
                    包含用户和助手之间的所有消息的数组。每个消息对象应该具有和属性。该字段表示消息的文本内容，该字段可以是“用户”或“助理”，以指示消息的发送者。
                chatbotId:
                  type: string
                  description: >-
                    指您要与之交互的聊天机器人的 ID（可在聊天机器人设置页面上找到）。 stream（布尔值，可选，默认为
                    false）：一个布尔值，指示是否流回部分进度或等待完整响应。如果设置为，则单词将在可用时作为仅数据服务器发送的事件发回，并由消息终止流。如果设置为，一旦准备好，将返回完整的响应。
                stream:
                  type: boolean
                  description: >-
                    一个布尔值，指示是否流回部分进度或等待完整响应。如果设置为，则单词将在可用时作为仅数据服务器发送的事件发回，并由消息终止流。如果设置为，一旦准备好，将返回完整的响应。
                temperature:
                  type: integer
                  description: >-
                    使用什么采样温度，介于 0 和 1 之间。较高的值（如 0.8）将使输出更加随机，而较低的值（如
                    0.2）将使其更加集中和确定性。
                model:
                  type: string
                  description: >-
                    'gpt-3.5-turbo' |
                    'gpt-4'。如果将其添加到正文，它将优先于聊天机器人设置中设置的模型。如果未设置，则使用聊天机器人设置中设置的模型。“gpt-4”选项仅适用于标准和无限计划。
                conversationId:
                  type: string
                  description: >-
                    指当前会话的 ID。这样做的唯一目的是将对话保存到聊天机器人仪表板。如果未提供，对话将不会被保存。该 ID
                    应由您生成。您应该为不同的会话使用不同的 ID，并为同一会话使用相同的 ID 发出请求。每次您使用特定的
                    chatbotId 发送消息时，消息数组中的最后一条消息和响应都会添加到对话中。
              required:
                - messages
                - chatbotId
              x-apifox-orders:
                - messages
                - chatbotId
                - stream
                - temperature
                - model
                - conversationId
            example:
              messages:
                - content: How can I help you?
                  role: assistant
                - content: What is chatbase?
                  role: user
              chatbotId: <Your Chatbot ID>
              stream: false
              temperature: 0
              model: gpt-3.5-turbo
              conversationId: <Conversation ID generated on your end>
      responses:
        '200':
          description: ''
          content:
            application/json:
              schema:
                type: object
                properties:
                  text:
                    type: string
                required:
                  - text
                x-apifox-orders:
                  - text
              example:
                text: >-
                  Chatbase is an AI chatbot builder that lets you create a
                  GPT-based chatbot that knows data.
          headers: {}
          x-apifox-name: 成功
      security: []
      x-apifox-folder: ''
      x-apifox-status: released
      x-run-in-apifox: https://app.apifox.com/web/project/4195807/apis/api-157468808-run
components:
  schemas: {}
  securitySchemes: {}
servers:
  - url: http://dev-cn.your-api-server.com
    description: 开发环境
  - url: http://test-cn.your-api-server.com
    description: 测试环境
  - url: https://www.chatbase.co
    description: 正式环境
security: []

```
