# 通用对话

## OpenAPI Specification

```yaml
openapi: 3.0.1
info:
  title: ''
  description: ''
  version: 1.0.0
paths:
  /v1/chat/completions:
    post:
      summary: 通用对话
      deprecated: false
      description: 详细说明参考：[API接口文档](https://docs.link-ai.tech/platform/api/chat)
      tags:
        - 智能体对话
      parameters:
        - name: Authorization
          in: header
          description: >-
            在 [LinkAI平台-应用接入](https://link-ai.tech/console/interface) 生成API
            Key并填入
          required: true
          example: Bearer YOUR_API_KEY
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                app_code:
                  type: string
                  title: 应用code
                  description: 应用、工作流或超级AI助理的 code。若不填则表示不绑定具体应用，将请求直接传递给模型
                messages:
                  type: array
                  items:
                    type: object
                    properties:
                      role:
                        type: string
                        title: 角色
                        description: 支持填写 system, user, assistant 中的一个，分别表示系统提示词、用户问题、AI回复
                      content:
                        type: string
                        title: 内容
                        description: 文本内容
                    x-apifox-orders:
                      - role
                      - content
                    required:
                      - role
                      - content
                  title: 消息列表
                  description: 消息上下文列表，可以传入历史对话记忆，每一轮包含一条user消息和一条assistant消息，最后一条为用户的问题
                model:
                  type: string
                  title: 模型编码
                  description: >-
                    不传则使用应用的默认模型，所有支持模型见
                    [模型列表](https://link-ai.tech/console/models)
                top_p:
                  type: integer
                  title: 模型采样范围
                  description: 控制模型采样范围，默认值为 1
                temperature:
                  type: number
                  title: 温度
                  description: 默认为应用中配置的温度。温度越高回复越具有创意和不确定性，温度越低则回复更严谨
                frequency_penalty:
                  type: number
                  title: 频率惩罚项
                  description: 该参数越大则更倾向于产生不同的内容，范围为 [-2, 2]，默认值为 0
                presence_penalty:
                  type: number
                  title: 存在惩罚项
                  description: 该参数越大则更倾向于产生不同的内容，范围为 [-2, 2]，默认值为 0
                stream:
                  type: boolean
                  title: 是否流式输出
                  description: 默认值为 false
                stream_options:
                  type: object
                  properties:
                    include_usage:
                      type: boolean
                      description: 设置为true时流式输出最后一个chunk将包含 token 用量信息
                      title: 流式Token用量信息
                  x-apifox-orders:
                    - include_usage
                  title: 流式输出选项
                  description: 流式输出相关选项
                tool_choice:
                  type: string
                  description: auto:自动选择, none:不会调用, required:必须调用一个或多个tool
                  title: 工具选择模式
                tools:
                  type: array
                  items:
                    type: object
                    properties: {}
                    x-apifox-orders: []
                  title: 工具列表
                  description: 需要模型调用的工具列表
                response_format:
                  type: object
                  properties:
                    type:
                      type: string
                      title: 格式类型
                      description: 'json_object: 以JSON格式输出，text: 文本格式输出'
                  x-apifox-orders:
                    - type
                  title: 输出格式
                  description: 设置模型的输出格式
                thinking:
                  type: object
                  properties:
                    type:
                      type: string
                      title: 思考开关
                      description: enabled:开启, disabled:关闭
                  x-apifox-orders:
                    - type
                  title: 深度思考
                reasoning_effort:
                  type: string
                  description: >-
                    推理强度，控制推理模型在思考阶段消耗的 token 数。常用取值 minimal / low / medium /
                    high。仅对支持该参数的推理模型生效
                  title: 推理强度
              x-apifox-orders:
                - messages
                - app_code
                - model
                - temperature
                - top_p
                - frequency_penalty
                - presence_penalty
                - stream
                - stream_options
                - tool_choice
                - tools
                - response_format
                - thinking
                - reasoning_effort
              required:
                - messages
            example:
              app_code: ''
              messages:
                - role: user
                  content: 你好
      responses:
        '200':
          description: ''
          content:
            application/json:
              schema:
                type: object
                properties:
                  choices:
                    type: array
                    items:
                      type: object
                      properties:
                        index:
                          type: integer
                        message:
                          type: object
                          properties:
                            role:
                              type: string
                              title: 角色
                              description: 响应中该字段值为 assistant
                            content:
                              type: string
                              title: 响应内容
                              description: AI回复结果
                          required:
                            - role
                            - content
                          x-apifox-orders:
                            - role
                            - content
                      x-apifox-orders:
                        - index
                        - message
                  usage:
                    type: object
                    properties:
                      prompt_tokens:
                        type: integer
                        title: 请求token数
                      completion_tokens:
                        type: integer
                        title: 响应token数
                      total_tokens:
                        type: integer
                        title: 总token数
                        description: >-
                          总token计算包含 请求 和 响应 中的总token数， 其中请求又包含
                          应用设定、历史对话、知识库内容、用户问题
                    required:
                      - prompt_tokens
                      - completion_tokens
                      - total_tokens
                    x-apifox-orders:
                      - prompt_tokens
                      - completion_tokens
                      - total_tokens
                  01J1H26ATPJJ2T82RT7TC6DVMQ:
                    type: string
                required:
                  - choices
                  - usage
                  - 01J1H26ATPJJ2T82RT7TC6DVMQ
                x-apifox-orders:
                  - 01J1H26ATPJJ2T82RT7TC6DVMQ
                  - choices
                  - usage
              example:
                choices:
                  - message:
                      role: assistant
                      content: 你好啊！有什么我可以帮助你的吗？
                usage:
                  prompt_tokens: 32
                  completion_tokens: 24
                  total_tokens: 56
          headers: {}
          x-apifox-name: 成功
        '400':
          description: ''
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      type:
                        type: string
                      message:
                        type: string
                    x-apifox-orders:
                      - type
                      - message
                required:
                  - error
                x-apifox-orders:
                  - error
              example:
                error:
                  type: invalid_request_error
                  message: 'Invalid request: user message content is empty'
          headers: {}
          x-apifox-name: 参数不正确
        '401':
          description: ''
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      type:
                        type: string
                      message:
                        type: string
                    x-apifox-orders:
                      - type
                      - message
                required:
                  - error
                x-apifox-orders:
                  - error
              example:
                error:
                  type: invalid_request_error
                  message: >-
                    Authentication failed, please check your API_KEY in
                    https://link-ai.tech/console/interface
          headers: {}
          x-apifox-name: API Key鉴权失败
        '402':
          description: ''
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      message:
                        type: string
                    required:
                      - message
                    x-apifox-orders:
                      - message
                x-apifox-orders:
                  - error
              example:
                error:
                  message: App not found, please check your app_code param
          headers: {}
          x-apifox-name: 应用不存在
        '403':
          description: ''
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      message:
                        type: string
                    required:
                      - message
                    x-apifox-orders:
                      - message
                x-apifox-orders:
                  - error
              example:
                error:
                  message: No app access permissions
          headers: {}
          x-apifox-name: 应用无访问权限
        '406':
          description: ''
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      message:
                        type: string
                    required:
                      - message
                    x-apifox-orders:
                      - message
                x-apifox-orders:
                  - error
              example:
                error:
                  message: >-
                    You exceeded your current quota, please check your balance
                    in https://link-ai.tech/console/account
          headers: {}
          x-apifox-name: 余额不足
        '409':
          description: ''
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      message:
                        type: string
                    required:
                      - message
                    x-apifox-orders:
                      - message
                x-apifox-orders:
                  - error
              example:
                error:
                  message: Content sensitivity detection failed (内容合规检查不通过)
          headers: {}
          x-apifox-name: 内容审核不通过
        '503':
          description: ''
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      message:
                        type: string
                    required:
                      - message
                    x-apifox-orders:
                      - message
                x-apifox-orders:
                  - error
              example:
                error:
                  message: >-
                    Server is too busy, please retry or contact the customer
                    service
          headers: {}
          x-apifox-name: 服务异常
        x-200:成功-流式输出:
          description: ''
          content:
            text/event-stream:
              schema:
                type: object
                properties: {}
              example: >-
                data: {"choices": [{"index": 0, "delta": {"content": "你好！"},
                "finish_reason": null}], "session_id": null}


                data: {"choices": [{"index": 0, "delta": {"content": "我能"},
                "finish_reason": null}], "session_id": null}


                data: {"choices": [{"index": 0, "delta": {"content": "为你"},
                "finish_reason": null}], "session_id": null}


                data: {"choices": [{"index": 0, "delta": {"content": "做些什么？"},
                "finish_reason": null}], "session_id": null}


                data: {"choices": [{"index": 0, "delta": {}, "finish_reason":
                "stop", "usage": {"prompt_tokens": 9, "completion_tokens": 6,
                "total_tokens": 15}}], "session_id": null}


                data: [DONE]
          headers: {}
          x-apifox-name: 成功-流式输出
      security:
        - bearerAuth: []
          x-apifox:
            schemeGroups:
              - id: fxalgFNckA8_wiEiIOIkk
                schemeIds:
                  - bearerAuth
            required: true
            use:
              id: fxalgFNckA8_wiEiIOIkk
            scopes:
              fxalgFNckA8_wiEiIOIkk:
                bearerAuth: []
      x-apifox-folder: 智能体对话
      x-apifox-status: released
      x-run-in-apifox: https://app.apifox.com/web/project/3294133/apis/api-110597681-run
components:
  schemas: {}
  securitySchemes:
    bearerAuth:
      type: bearer
      scheme: bearer
      description: LinkAI API Key，可在 https://link-ai.tech/console/interface 创建
servers:
  - url: https://api.link-ai.tech
    description: 正式环境
security:
  - bearerAuth: []
    x-apifox:
      schemeGroups:
        - id: fxalgFNckA8_wiEiIOIkk
          schemeIds:
            - bearerAuth
      required: true
      use:
        id: fxalgFNckA8_wiEiIOIkk
      scopes:
        fxalgFNckA8_wiEiIOIkk:
          bearerAuth: []

```
