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

# 对话补全

> 使用 OpenAI 兼容格式调用 Gemini 模型生成回复。



## OpenAPI

````yaml zh/api-reference/endpoints/openapi/gemini-chat/openapi.yaml POST /v1/chat/completions
openapi: 3.1.0
info:
  title: Gemini Chat 兼容端点
  description: 通过 Anyfast 使用 OpenAI 兼容格式调用 Gemini 模型
  version: 1.0.0
servers:
  - url: https://www.anyfast.ai
security:
  - bearerAuth: []
paths:
  /v1/chat/completions:
    post:
      summary: 对话补全
      description: 使用 OpenAI 兼容格式调用 Gemini 模型生成回复。
      operationId: createChatCompletionGemini
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - model
                - messages
              properties:
                model:
                  type: string
                  enum:
                    - gemini-3.1-pro-preview
                    - gemini-3.1-flash-image
                    - gemini-3.1-flash-lite-preview
                    - gemini-3-pro-preview
                    - gemini-3-pro-image
                    - gemini-3-flash-preview
                    - gemini-2.5-pro
                    - gemini-2.5-flash
                    - gemini-2.5-flash-lite
                    - gemini-2.0-flash
                  description: 用于补全的 Gemini 模型 ID。
                  example: gemini-2.5-pro
                messages:
                  type: array
                  minItems: 1
                  description: 组成当前对话的消息列表。
                  items:
                    type: object
                    required:
                      - role
                      - content
                    properties:
                      role:
                        type: string
                        enum:
                          - system
                          - user
                          - assistant
                      content:
                        oneOf:
                          - type: string
                          - type: array
                            items:
                              type: object
                  example:
                    - role: user
                      content: 你好！
                max_tokens:
                  type: integer
                  minimum: 1
                  description: 对话补全中生成的最大 token 数。
                temperature:
                  type: number
                  minimum: 0
                  maximum: 2
                  default: 1
                  description: 采样温度，范围 0 到 2。
                  example: 1
                top_p:
                  type: number
                  minimum: 0
                  maximum: 1
                  description: 核采样阈值。
                frequency_penalty:
                  type: number
                  minimum: -2
                  maximum: 2
                  default: 0
                  description: 根据新 token 在文本中的现有频率进行惩罚。
                presence_penalty:
                  type: number
                  minimum: -2
                  maximum: 2
                  default: 0
                  description: 根据新 token 是否已出现在文本中进行惩罚。
                stream:
                  type: boolean
                  default: false
                  description: 如果为 true，将通过 SSE 流式发送部分消息。
                stop:
                  oneOf:
                    - type: string
                    - type: array
                      items:
                        type: string
                  description: API 将在生成这些序列时停止继续生成。
                'n':
                  type: integer
                  minimum: 1
                  default: 1
                  description: 为每条输入消息生成多少个补全选项。
                response_format:
                  type: object
                  properties:
                    type:
                      type: string
                      enum:
                        - text
                        - json_object
                  description: '指定模型必须输出的格式。设置为 {"type": "json_object"} 可启用 JSON 模式。'
      responses:
        '200':
          description: 补全生成成功
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChatCompletion'
        '400':
          description: 请求无效
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: 未授权
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '429':
          description: 超出速率限制
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
components:
  schemas:
    ChatCompletion:
      type: object
      required:
        - id
        - object
        - created
        - model
        - choices
      properties:
        id:
          type: string
          example: chatcmpl-abc123
        object:
          type: string
          example: chat.completion
        created:
          type: integer
          description: 补全创建时的 Unix 时间戳。
        model:
          type: string
          example: gemini-2.5-pro
        choices:
          type: array
          items:
            type: object
            properties:
              index:
                type: integer
              message:
                type: object
                properties:
                  role:
                    type: string
                    example: assistant
                  content:
                    type: string
                    example: 你好！有什么我可以帮助你的吗？
              finish_reason:
                type: string
                enum:
                  - stop
                  - length
                  - content_filter
                  - null
        usage:
          type: object
          properties:
            prompt_tokens:
              type: integer
            completion_tokens:
              type: integer
            total_tokens:
              type: integer
    Error:
      type: object
      properties:
        error:
          type: object
          properties:
            code:
              type: string
            message:
              type: string
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer

````