# 对话补全

## OpenAPI Specification

```yaml
openapi: 3.0.1
info:
  title: ''
  description: ''
  version: 1.0.0
paths:
  /chat/completions:
    post:
      summary: 对话补全
      deprecated: false
      description: 根据输入的上下文，来让模型补全对话内容。
      tags:
        - API 文档
      parameters: []
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                messages:
                  type: array
                  items:
                    oneOf:
                      - type: object
                        properties:
                          content:
                            type: string
                            description: system 消息的内容
                          role:
                            type: string
                            description: 该消息的发起角色，其值为 `system`
                            x-apifox-mock: system
                          name:
                            type: string
                            description: 可以选填的参与者的名称，为模型提供信息以区分相同角色的参与者
                        x-apifox-orders:
                          - content
                          - role
                          - name
                        required:
                          - content
                          - role
                        title: System message
                      - type: object
                        properties:
                          content:
                            type: string
                            description: user 消息的内容
                          role:
                            type: string
                            description: 该消息的发起角色，其值为 `user`
                            x-apifox-mock: user
                          name:
                            type: string
                            description: 可以选填的参与者的名称，为模型提供信息以区分相同角色的参与者
                        x-apifox-orders:
                          - content
                          - role
                          - name
                        required:
                          - content
                          - role
                        title: User message
                      - type: object
                        properties:
                          content:
                            type: string
                            description: assistant 消息的内容
                          role:
                            type: string
                            description: 该消息的发起角色，其值为 `assistant`
                            x-apifox-mock: assistant
                          name:
                            type: string
                            description: 可以选填的参与者的名称，为模型提供信息以区分相同角色的参与者。
                        x-apifox-orders:
                          - content
                          - role
                          - name
                        title: Assistant message
                        required:
                          - content
                          - role
                      - type: object
                        properties:
                          role:
                            type: string
                            description: 该消息的发起角色，其值为 `tool`
                            x-apifox-mock: tool
                          content:
                            type: string
                            description: tool 消息的内容
                          tool_call_id:
                            type: string
                            description: 此消息所响应的 tool call 的 ID
                        x-apifox-orders:
                          - content
                          - role
                          - tool_call_id
                        required:
                          - role
                          - content
                          - tool_call_id
                        title: Tool message
                  minItems: 1
                  description: 对话的消息列表
                model:
                  type: string
                  description: 使用的 AI 模型
                  enum:
                    - deepseek-chat
                    - deepseek-reasoner
                  x-apifox-enum:
                    - value: deepseek-chat
                      name: ''
                      description: ''
                    - value: deepseek-reasoner
                      name: ''
                      description: ''
                frequency_penalty:
                  type: number
                  nullable: true
                max_tokens:
                  type: integer
                  nullable: true
                presence_penalty:
                  type: number
                  nullable: true
                response_format:
                  type: object
                  properties:
                    type:
                      type: string
                      nullable: true
                  x-apifox-orders:
                    - type
                  nullable: true
                stop:
                  oneOf:
                    - type: string
                      nullable: true
                    - type: array
                      items:
                        type: string
                      nullable: true
                stream:
                  type: boolean
                  description: 是否启用流式传输
                  default: true
                  nullable: true
                stream_options:
                  type: object
                  properties:
                    include_usage:
                      type: boolean
                  x-apifox-orders:
                    - include_usage
                  nullable: true
                temperature:
                  type: number
                  nullable: true
                top_p:
                  type: number
                  nullable: true
                tools:
                  type: 'null'
                tool_choice:
                  oneOf:
                    - type: string
                    - type: object
                      properties: {}
                      x-apifox-orders: []
                logprobs:
                  type: boolean
                  nullable: true
                top_logprobs:
                  type: integer
                  nullable: true
              required:
                - messages
                - model
              x-apifox-orders:
                - messages
                - model
                - frequency_penalty
                - max_tokens
                - presence_penalty
                - response_format
                - stop
                - stream
                - stream_options
                - temperature
                - top_p
                - tools
                - tool_choice
                - logprobs
                - top_logprobs
            examples:
              '1':
                value:
                  messages:
                    - content: You are a helpful assistant
                      role: system
                    - content: 你是谁？
                      role: user
                  model: deepseek-chat
                  stream: true
                summary: 流式
              '2':
                value:
                  messages:
                    - content: You are a helpful assistant
                      role: system
                    - content: 你是谁？
                      role: user
                  model: deepseek-chat
                  frequency_penalty: 0
                  max_tokens: 2048
                  presence_penalty: 0
                  response_format:
                    type: text
                  stop: null
                  stream: false
                  stream_options: null
                  temperature: 1
                  top_p: 1
                  tools: null
                  tool_choice: none
                  logprobs: false
                  top_logprobs: null
                summary: 非流式
      responses:
        '200':
          description: OK, 返回一个 `chat completion` 对象。
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                  choices:
                    type: array
                    items:
                      type: object
                      properties:
                        finish_reason:
                          type: string
                        index:
                          type: integer
                        message:
                          type: object
                          properties:
                            content:
                              type: string
                              nullable: true
                            reasoning_content:
                              type: string
                              nullable: true
                            tool_calls:
                              type: array
                              items:
                                type: object
                                properties:
                                  id:
                                    type: string
                                  type:
                                    type: string
                                  function:
                                    type: object
                                    properties:
                                      name:
                                        type: string
                                      arguments:
                                        type: string
                                    required:
                                      - name
                                      - arguments
                                    x-apifox-orders:
                                      - name
                                      - arguments
                                x-apifox-orders:
                                  - id
                                  - type
                                  - function
                            role:
                              type: string
                          required:
                            - content
                            - role
                          x-apifox-orders:
                            - content
                            - reasoning_content
                            - tool_calls
                            - role
                        logprobs:
                          type: object
                          properties:
                            content:
                              type: array
                              items:
                                type: object
                                properties:
                                  token:
                                    type: string
                                  logprob:
                                    type: number
                                  bytes:
                                    type: array
                                    items:
                                      type: integer
                                    nullable: true
                                  top_logprobs:
                                    type: array
                                    items:
                                      type: object
                                      properties:
                                        token:
                                          type: string
                                        logprob:
                                          type: integer
                                        bytes:
                                          type: array
                                          items:
                                            type: integer
                                      x-apifox-orders:
                                        - token
                                        - logprob
                                        - bytes
                                x-apifox-orders:
                                  - token
                                  - logprob
                                  - bytes
                                  - top_logprobs
                                required:
                                  - token
                                  - logprob
                                  - bytes
                                  - top_logprobs
                              nullable: true
                          x-apifox-orders:
                            - content
                          required:
                            - content
                          nullable: true
                      x-apifox-orders:
                        - finish_reason
                        - index
                        - message
                        - logprobs
                      required:
                        - logprobs
                  created:
                    type: integer
                  model:
                    type: string
                  system_fingerprint:
                    type: string
                  object:
                    type: string
                  usage:
                    type: object
                    properties:
                      completion_tokens:
                        type: integer
                      prompt_tokens:
                        type: integer
                      prompt_cache_hit_tokens:
                        type: integer
                      prompt_cache_miss_tokens:
                        type: integer
                      total_tokens:
                        type: integer
                      completion_tokens_details:
                        type: object
                        properties:
                          reasoning_tokens:
                            type: integer
                        required:
                          - reasoning_tokens
                        x-apifox-orders:
                          - reasoning_tokens
                    required:
                      - completion_tokens
                      - prompt_tokens
                      - prompt_cache_hit_tokens
                      - prompt_cache_miss_tokens
                      - total_tokens
                    x-apifox-orders:
                      - completion_tokens
                      - prompt_tokens
                      - prompt_cache_hit_tokens
                      - prompt_cache_miss_tokens
                      - total_tokens
                      - completion_tokens_details
                required:
                  - id
                  - choices
                  - created
                  - model
                  - system_fingerprint
                  - object
                x-apifox-orders:
                  - id
                  - choices
                  - created
                  - model
                  - system_fingerprint
                  - object
                  - usage
              example:
                id: e137bb42-7580-4cb8-88ba-825209cf966b
                choices:
                  - index: 0
                    message:
                      role: assistant
                      content: Hello! How can I assist you today? 😊
                    logprobs: null
                    finish_reason: stop
                created: 1739112811
                model: deepseek-chat
                system_fingerprint: fp_3a5790e1b4
                object: chat.completion
                usage:
                  prompt_tokens: 9
                  completion_tokens: 11
                  total_tokens: 20
                  prompt_tokens_details:
                    cached_tokens: 0
                  prompt_cache_hit_tokens: 0
                  prompt_cache_miss_tokens: 9
          headers: {}
          x-apifox-name: No streaming
        x-200:Streaming:
          description: OK, 返回包含一系列 `chat completion chunk` 对象的流式输出。
          content:
            text/event-stream:
              schema:
                type: 'null'
              example: "data: {\r\n    \"id\": \"1f633d8bfc032625086f14113c411638\",\r\n    \"choices\": [\r\n        {\r\n            \"index\": 0,\r\n            \"delta\": {\r\n                \"content\": \"\",\r\n                \"role\": \"assistant\"\r\n            },\r\n            \"finish_reason\": null,\r\n            \"logprobs\": null\r\n        }\r\n    ],\r\n    \"created\": 1718345013,\r\n    \"model\": \"deepseek-chat\",\r\n    \"system_fingerprint\": \"fp_a49d71b8a1\",\r\n    \"object\": \"chat.completion.chunk\",\r\n    \"usage\": null\r\n}\r\n\r\ndata: {\r\n    \"choices\": [\r\n        {\r\n            \"delta\": {\r\n                \"content\": \"Hello\",\r\n                \"role\": \"assistant\"\r\n            },\r\n            \"finish_reason\": null,\r\n            \"index\": 0,\r\n            \"logprobs\": null\r\n        }\r\n    ],\r\n    \"created\": 1718345013,\r\n    \"id\": \"1f633d8bfc032625086f14113c411638\",\r\n    \"model\": \"deepseek-chat\",\r\n    \"object\": \"chat.completion.chunk\",\r\n    \"system_fingerprint\": \"fp_a49d71b8a1\"\r\n}\r\n\r\ndata: {\r\n    \"choices\": [\r\n        {\r\n            \"delta\": {\r\n                \"content\": \"!\",\r\n                \"role\": \"assistant\"\r\n            },\r\n            \"finish_reason\": null,\r\n            \"index\": 0,\r\n            \"logprobs\": null\r\n        }\r\n    ],\r\n    \"created\": 1718345013,\r\n    \"id\": \"1f633d8bfc032625086f14113c411638\",\r\n    \"model\": \"deepseek-chat\",\r\n    \"object\": \"chat.completion.chunk\",\r\n    \"system_fingerprint\": \"fp_a49d71b8a1\"\r\n}\r\n\r\ndata: {\r\n    \"choices\": [\r\n        {\r\n            \"delta\": {\r\n                \"content\": \" How\",\r\n                \"role\": \"assistant\"\r\n            },\r\n            \"finish_reason\": null,\r\n            \"index\": 0,\r\n            \"logprobs\": null\r\n        }\r\n    ],\r\n    \"created\": 1718345013,\r\n    \"id\": \"1f633d8bfc032625086f14113c411638\",\r\n    \"model\": \"deepseek-chat\",\r\n    \"object\": \"chat.completion.chunk\",\r\n    \"system_fingerprint\": \"fp_a49d71b8a1\"\r\n}\r\n\r\ndata: {\r\n    \"choices\": [\r\n        {\r\n            \"delta\": {\r\n                \"content\": \" can\",\r\n                \"role\": \"assistant\"\r\n            },\r\n            \"finish_reason\": null,\r\n            \"index\": 0,\r\n            \"logprobs\": null\r\n        }\r\n    ],\r\n    \"created\": 1718345013,\r\n    \"id\": \"1f633d8bfc032625086f14113c411638\",\r\n    \"model\": \"deepseek-chat\",\r\n    \"object\": \"chat.completion.chunk\",\r\n    \"system_fingerprint\": \"fp_a49d71b8a1\"\r\n}\r\n\r\ndata: {\r\n    \"choices\": [\r\n        {\r\n            \"delta\": {\r\n                \"content\": \" I\",\r\n                \"role\": \"assistant\"\r\n            },\r\n            \"finish_reason\": null,\r\n            \"index\": 0,\r\n            \"logprobs\": null\r\n        }\r\n    ],\r\n    \"created\": 1718345013,\r\n    \"id\": \"1f633d8bfc032625086f14113c411638\",\r\n    \"model\": \"deepseek-chat\",\r\n    \"object\": \"chat.completion.chunk\",\r\n    \"system_fingerprint\": \"fp_a49d71b8a1\"\r\n}\r\n\r\ndata: {\r\n    \"choices\": [\r\n        {\r\n            \"delta\": {\r\n                \"content\": \" assist\",\r\n                \"role\": \"assistant\"\r\n            },\r\n            \"finish_reason\": null,\r\n            \"index\": 0,\r\n            \"logprobs\": null\r\n        }\r\n    ],\r\n    \"created\": 1718345013,\r\n    \"id\": \"1f633d8bfc032625086f14113c411638\",\r\n    \"model\": \"deepseek-chat\",\r\n    \"object\": \"chat.completion.chunk\",\r\n    \"system_fingerprint\": \"fp_a49d71b8a1\"\r\n}\r\n\r\ndata: {\r\n    \"choices\": [\r\n        {\r\n            \"delta\": {\r\n                \"content\": \" you\",\r\n                \"role\": \"assistant\"\r\n            },\r\n            \"finish_reason\": null,\r\n            \"index\": 0,\r\n            \"logprobs\": null\r\n        }\r\n    ],\r\n    \"created\": 1718345013,\r\n    \"id\": \"1f633d8bfc032625086f14113c411638\",\r\n    \"model\": \"deepseek-chat\",\r\n    \"object\": \"chat.completion.chunk\",\r\n    \"system_fingerprint\": \"fp_a49d71b8a1\"\r\n}\r\n\r\ndata: {\r\n    \"choices\": [\r\n        {\r\n            \"delta\": {\r\n                \"content\": \" today\",\r\n                \"role\": \"assistant\"\r\n            },\r\n            \"finish_reason\": null,\r\n            \"index\": 0,\r\n            \"logprobs\": null\r\n        }\r\n    ],\r\n    \"created\": 1718345013,\r\n    \"id\": \"1f633d8bfc032625086f14113c411638\",\r\n    \"model\": \"deepseek-chat\",\r\n    \"object\": \"chat.completion.chunk\",\r\n    \"system_fingerprint\": \"fp_a49d71b8a1\"\r\n}\r\n\r\ndata: {\r\n    \"choices\": [\r\n        {\r\n            \"delta\": {\r\n                \"content\": \"?\",\r\n                \"role\": \"assistant\"\r\n            },\r\n            \"finish_reason\": null,\r\n            \"index\": 0,\r\n            \"logprobs\": null\r\n        }\r\n    ],\r\n    \"created\": 1718345013,\r\n    \"id\": \"1f633d8bfc032625086f14113c411638\",\r\n    \"model\": \"deepseek-chat\",\r\n    \"object\": \"chat.completion.chunk\",\r\n    \"system_fingerprint\": \"fp_a49d71b8a1\"\r\n}\r\n\r\ndata: {\r\n    \"choices\": [\r\n        {\r\n            \"delta\": {\r\n                \"content\": \"\",\r\n                \"role\": null\r\n            },\r\n            \"finish_reason\": \"stop\",\r\n            \"index\": 0,\r\n            \"logprobs\": null\r\n        }\r\n    ],\r\n    \"created\": 1718345013,\r\n    \"id\": \"1f633d8bfc032625086f14113c411638\",\r\n    \"model\": \"deepseek-chat\",\r\n    \"object\": \"chat.completion.chunk\",\r\n    \"system_fingerprint\": \"fp_a49d71b8a1\",\r\n    \"usage\": {\r\n        \"completion_tokens\": 9,\r\n        \"prompt_tokens\": 17,\r\n        \"total_tokens\": 26\r\n    }\r\n}\r\n\r\ndata: [DONE\r\n]"
          headers: {}
          x-apifox-name: Streaming
      security: []
      x-apifox-folder: API 文档
      x-apifox-status: released
      x-run-in-apifox: https://app.apifox.com/web/project/5813541/apis/api-257835379-run
components:
  schemas: {}
  securitySchemes:
    bearer:
      type: bearer
      scheme: bearer
servers:
  - url: https://api.deepseek.com
    description: 正式环境
security:
  - bearer: []
    x-apifox:
      schemeGroups:
        - id: DOp0WuT-c0vg6PnvNSIS-
          schemeIds:
            - bearer
      required: true
      use:
        id: DOp0WuT-c0vg6PnvNSIS-

```
