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

# Gemini 3.5 Flash - Native API - 完整参数文档

> - 使用 Google 原生 API 格式调用 gemini-3.5-flash 模型
- 可使用同步处理模式，实时返回对话内容
- **纯文本对话**：单轮或多轮上下文对话，可参考示例代码中 simple_text、multi_turn 示例
- **多模态输入**：支持文本 + 图像/音频/视频混合输入，可参考示例代码中 audio_analysis、image_understanding、multi_file 示例
- **参数调优**：通过 generationConfig 控制生成效果
- **流式**：将 URL 中 `generateContent` 替换为 `streamGenerateContent` 即可

<Tip>
  **流式调用**：将 URL 中的 `generateContent` 替换为 `streamGenerateContent`，请求体参数完全相同，响应将以流式逐块返回。响应格式参见下方「流式响应」说明。
</Tip>

<Note>
  **BaseURL 说明**：默认 BaseURL 为 `https://direct.evolink.ai`，对文本模型支持更好，支持长连接；`https://api.evolink.ai` 是多模态主力地址，对文本模型作为备用地址使用。
</Note>


## OpenAPI

````yaml cn/api-manual/language-series/gemini-3.5-flash/native-api/native-api-reference.json POST /v1beta/models/gemini-3.5-flash:generateContent
openapi: 3.1.0
info:
  title: Gemini 原生 API - 完整参数文档
  description: Google Gemini 原生 API 的完整参考文档，支持文本、图像、音频、视频等多模态输入
  license:
    name: MIT
  version: 1.0.0
servers:
  - url: https://direct.evolink.ai
    description: 生产环境（推荐）
  - url: https://api.evolink.ai
    description: 备用地址
security:
  - bearerAuth: []
tags:
  - name: 内容生成
    description: Gemini AI 内容生成相关接口
paths:
  /v1beta/models/gemini-3.5-flash:generateContent:
    post:
      tags:
        - 内容生成
      summary: Gemini 内容生成
      description: >-
        - 使用 Google 原生 API 格式调用 gemini-3.5-flash 模型

        - 可使用同步处理模式，实时返回对话内容

        - **纯文本对话**：单轮或多轮上下文对话，可参考示例代码中 simple_text、multi_turn 示例

        - **多模态输入**：支持文本 + 图像/音频/视频混合输入，可参考示例代码中
        audio_analysis、image_understanding、multi_file 示例

        - **参数调优**：通过 generationConfig 控制生成效果

        - **流式**：将 URL 中 `generateContent` 替换为 `streamGenerateContent` 即可
      operationId: generateContent
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/GenerateContentRequest'
            examples:
              simple_text:
                summary: 单轮纯文本对话
                value:
                  contents:
                    - role: user
                      parts:
                        - text: 请介绍下你自己
              multi_turn:
                summary: 多轮对话（上下文理解）
                value:
                  contents:
                    - role: user
                      parts:
                        - text: 什么是Python？
                    - role: model
                      parts:
                        - text: Python是一种高级编程语言...
                    - role: user
                      parts:
                        - text: 它有什么优点？
              audio_analysis:
                summary: 音频分析
                value:
                  contents:
                    - role: user
                      parts:
                        - text: 请分析这段歌曲音频，回答以下问题：1. 歌曲来源和歌手来源 2. 歌曲情绪 3. 歌词完整输出
                        - fileData:
                            mimeType: audio/mp3
                            fileUri: https://example.com/audio.mp3
              image_understanding:
                summary: 图像理解
                value:
                  contents:
                    - role: user
                      parts:
                        - text: 请详细描述这张图片中的场景和主要元素
                        - fileData:
                            mimeType: image/jpeg
                            fileUri: https://example.com/image.jpg
              multi_file:
                summary: 多文件输入（混合）
                value:
                  contents:
                    - role: user
                      parts:
                        - text: 对比这两张图片和这段音频的内容关联性
                        - fileData:
                            mimeType: image/jpeg
                            fileUri: https://example.com/image1.jpg
                        - fileData:
                            mimeType: image/png
                            fileUri: https://example.com/image2.png
                        - fileData:
                            mimeType: audio/mp3
                            fileUri: https://example.com/audio.mp3
      responses:
        '200':
          description: >-
            内容生成成功


            **响应格式说明**：

            - 使用 `generateContent` 端点时，返回
            `GenerateContentResponse`（等待完整响应后一次性返回）

            - 使用 `streamGenerateContent` 端点时，返回
            `StreamGenerateContentResponse`（流式响应，逐块返回内容）
          content:
            application/json:
              schema:
                oneOf:
                  - $ref: '#/components/schemas/GenerateContentResponse'
                  - $ref: '#/components/schemas/StreamGenerateContentResponse'
        '400':
          description: 请求参数错误
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                error:
                  code: 400
                  message: Invalid request parameters
                  type: invalid_request_error
        '401':
          description: 未认证、Token无效或过期
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                error:
                  code: 401
                  message: Invalid or expired token
                  type: authentication_error
        '402':
          description: 配额不足、需要充值
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                error:
                  code: 402
                  message: Insufficient quota
                  type: insufficient_quota_error
                  fallback_suggestion: https://evolink.ai/dashboard/billing
        '403':
          description: 无权限访问
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                error:
                  code: 403
                  message: Access denied for this model
                  type: permission_error
        '404':
          description: 资源不存在
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                error:
                  code: 404
                  message: Model not found
                  type: not_found_error
        '413':
          description: 请求体过大、文件过大
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                error:
                  code: 413
                  message: Request body too large
                  type: request_too_large_error
                  fallback_suggestion: reduce file size
        '429':
          description: 请求频率超限
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                error:
                  code: 429
                  message: Rate limit exceeded
                  type: rate_limit_error
                  fallback_suggestion: retry after 60 seconds
        '500':
          description: 服务器内部错误
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                error:
                  code: 500
                  message: Internal server error
                  type: internal_server_error
                  fallback_suggestion: try again later
        '502':
          description: 上游服务错误
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                error:
                  code: 502
                  message: Upstream AI service unavailable
                  type: upstream_error
                  fallback_suggestion: try again later
        '503':
          description: 服务暂时不可用
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                error:
                  code: 503
                  message: Service temporarily unavailable
                  type: service_unavailable_error
                  fallback_suggestion: retry after 30 seconds
components:
  schemas:
    GenerateContentRequest:
      type: object
      required:
        - contents
      properties:
        contents:
          type: array
          description: 对话内容列表，支持多轮对话和多模态输入
          items:
            $ref: '#/components/schemas/Content'
          minItems: 1
        systemInstruction:
          $ref: '#/components/schemas/Content'
          description: 系统指令（可选），当前以文本为主
        tools:
          type: array
          description: 模型可调用的工具列表，如函数调用或代码执行
          items:
            type: object
        toolConfig:
          type: object
          description: 工具调用配置（可选）
        safetySettings:
          type: array
          description: 安全设置列表（可选）
          items:
            type: object
        generationConfig:
          $ref: '#/components/schemas/GenerationConfig'
          description: 生成配置参数（可选）
        cachedContent:
          type: string
          description: 缓存内容名称，格式为 cachedContents/{cachedContent}
    GenerateContentResponse:
      title: 同步响应
      type: object
      properties:
        candidates:
          type: array
          description: 候选响应列表
          items:
            $ref: '#/components/schemas/Candidate'
        promptFeedback:
          $ref: '#/components/schemas/PromptFeedback'
        usageMetadata:
          $ref: '#/components/schemas/UsageMetadata'
        modelVersion:
          type: string
          description: 模型版本
          example: gemini-3.5-flash
        responseId:
          type: string
          description: 响应 ID
          example: l-LoaPu0BPmo1dkP6ZPHiQc
    StreamGenerateContentResponse:
      title: 流式响应
      type: object
      description: |-
        流式响应块

        **中间块**:
        ```json
        {
          "candidates": [
            {
              "content": {
                "role": "model",
                "parts": [{ "text": "部分文本..." }]
              }
            }
          ],
          "usageMetadata": {
            "trafficType": "ON_DEMAND"
          },
          "modelVersion": "gemini-3.5-flash",
          "createTime": "2025-10-10T10:40:23.072315Z",
          "responseId": "xxx"
        }
        ```

        **最后一块**:
        ```json
        {
          "candidates": [
            {
              "content": {
                "role": "model",
                "parts": [{ "text": "最后的文本片段" }]
              },
              "finishReason": "STOP"
            }
          ],
          "usageMetadata": {
            "promptTokenCount": 4,
            "candidatesTokenCount": 522,
            "totalTokenCount": 2191,
            "trafficType": "ON_DEMAND"
          },
          "modelVersion": "gemini-3.5-flash",
          "createTime": "2025-10-10T10:40:23.072315Z",
          "responseId": "xxx"
        }
        ```
      properties:
        candidates:
          type: array
          description: 候选响应列表（流式模式下不包含 index 和 safetyRatings）
          items:
            $ref: '#/components/schemas/StreamCandidate'
        usageMetadata:
          type: object
          description: 使用量统计（中间块只有 trafficType，最后一块才包含完整统计）
          properties:
            promptTokenCount:
              type: integer
              description: 输入内容的 token 数量（仅最后一块）
              example: 4
            cachedContentTokenCount:
              type: integer
              description: 缓存内容 token 数量（仅最后一块）
              example: 0
            candidatesTokenCount:
              type: integer
              description: 输出内容的 token 数量（仅最后一块）
              example: 522
            totalTokenCount:
              type: integer
              description: 总 token 数量（仅最后一块）
              example: 2191
            trafficType:
              type: string
              description: 流量类型
              example: ON_DEMAND
        modelVersion:
          type: string
          description: 模型版本
          example: gemini-3.5-flash
        createTime:
          type: string
          format: date-time
          description: 创建时间
          example: '2025-10-10T10:40:23.072315Z'
        responseId:
          type: string
          description: 响应ID
          example: l-LoaPu0BPmo1dkP6ZPHiQc
    ErrorResponse:
      type: object
      properties:
        error:
          type: object
          properties:
            code:
              type: integer
              description: HTTP状态错误代码
            message:
              type: string
              description: 错误描述信息
            type:
              type: string
              description: 错误类型
            fallback_suggestion:
              type: string
              description: 错误时的建议
    Content:
      type: object
      required:
        - role
        - parts
      properties:
        role:
          type: string
          description: |-
            内容角色

            - `user`: 用户输入
            - `model`: AI 模型的回复（用于多轮对话）
          enum:
            - user
            - model
          example: user
        parts:
          type: array
          description: 内容片段列表，支持文本、文件、内联数据、函数调用、函数返回和代码执行结果
          items:
            $ref: '#/components/schemas/Part'
          minItems: 1
    GenerationConfig:
      type: object
      description: 生成配置参数
      properties:
        temperature:
          type: number
          description: |-
            采样温度，控制输出的随机性

            **说明**:
            - 较低值(如 0.2): 更确定、更聚焦的输出
            - 较高值(如 1.5): 更随机、更有创意的输出
          minimum: 0
          maximum: 2
          example: 0.7
        maxOutputTokens:
          type: integer
          description: |-
            生成回复的最大 token 数量

            **说明**:
            - 此值过小可能导致回复被截断
          minimum: 1
          example: 2000
        topP:
          type: number
          description: |-
            核采样(Nucleus Sampling)参数

            **说明**:
            - 控制从累积概率前多少的token中采样
            - 例如 0.9 表示从累积概率达到90%的token中选择
            - 默认值: 1.0（考虑所有token）

            **建议**: 不要同时调整 temperature 和 topP
          minimum: 0
          maximum: 1
          example: 0.9
        topK:
          type: integer
          description: |-
            Top-K 采样参数

            **说明**:
            - 例如 10 表示限制每次采样时只考虑概率最高的 10 个 token
            - 较小的值会使输出更加聚焦
            - 默认不限制
          minimum: 1
          example: 40
        responseMimeType:
          type: string
          description: 生成候选内容的 MIME 类型，例如 text/plain 或 application/json
          example: application/json
        responseSchema:
          type: object
          description: 生成内容的输出结构定义（JSON Mode / 结构化输出）
        responseJsonSchema:
          type: object
          description: 生成内容的 JSON Schema（可选，适合更复杂的结构化输出）
        candidateCount:
          type: integer
          description: 返回候选数量
          minimum: 1
          example: 1
        thinkingConfig:
          type: object
          description: 思考配置（适用于支持 thinking 的模型）
    Candidate:
      type: object
      properties:
        content:
          $ref: '#/components/schemas/ContentResponse'
        finishReason:
          type: string
          description: 完成原因
          enum:
            - FINISH_REASON_UNSPECIFIED
            - STOP
            - MAX_TOKENS
            - SAFETY
            - RECITATION
            - LANGUAGE
            - OTHER
            - BLOCKLIST
            - PROHIBITED_CONTENT
            - SPII
            - MALFORMED_FUNCTION_CALL
            - IMAGE_SAFETY
            - IMAGE_PROHIBITED_CONTENT
            - IMAGE_OTHER
            - NO_IMAGE
            - IMAGE_RECITATION
            - UNEXPECTED_TOOL_CALL
            - TOO_MANY_TOOL_CALLS
            - MISSING_THOUGHT_SIGNATURE
          example: STOP
        index:
          type: integer
          description: 候选索引
          example: 0
        safetyRatings:
          type: array
          nullable: true
          description: 安全评分
          items:
            type: object
    PromptFeedback:
      type: object
      properties:
        safetyRatings:
          type: array
          nullable: true
          description: 提示词安全评分
          items:
            type: object
    UsageMetadata:
      type: object
      description: 使用量统计
      properties:
        promptTokenCount:
          type: integer
          description: 输入内容的 token 数量
          example: 4
        cachedContentTokenCount:
          type: integer
          description: 缓存内容 token 数量
          example: 0
        candidatesTokenCount:
          type: integer
          description: 输出内容的 token 数量
          example: 611
        totalTokenCount:
          type: integer
          description: 总 token 数量
          example: 2422
        thoughtsTokenCount:
          type: integer
          description: 推理 token 数量
          example: 1807
        promptTokensDetails:
          type: array
          description: 输入 token 详细信息（按模态分类）
          items:
            $ref: '#/components/schemas/TokenDetail'
    StreamCandidate:
      type: object
      description: 流式响应候选项（比普通响应更简化）
      properties:
        content:
          $ref: '#/components/schemas/ContentResponse'
        finishReason:
          type: string
          description: 完成原因（仅最后一块包含此字段）
          enum:
            - FINISH_REASON_UNSPECIFIED
            - STOP
            - MAX_TOKENS
            - SAFETY
            - RECITATION
            - LANGUAGE
            - OTHER
            - BLOCKLIST
            - PROHIBITED_CONTENT
            - SPII
            - MALFORMED_FUNCTION_CALL
            - IMAGE_SAFETY
            - IMAGE_PROHIBITED_CONTENT
            - IMAGE_OTHER
            - NO_IMAGE
            - IMAGE_RECITATION
            - UNEXPECTED_TOOL_CALL
            - TOO_MANY_TOOL_CALLS
            - MISSING_THOUGHT_SIGNATURE
          example: STOP
    Part:
      oneOf:
        - $ref: '#/components/schemas/TextPart'
        - $ref: '#/components/schemas/FilePart'
        - $ref: '#/components/schemas/InlineDataPart'
        - $ref: '#/components/schemas/FunctionCallPart'
        - $ref: '#/components/schemas/FunctionResponsePart'
        - $ref: '#/components/schemas/ExecutableCodePart'
        - $ref: '#/components/schemas/CodeExecutionResultPart'
      description: 内容片段联合类型。思考模型返回的 thoughtSignature 需要在下一轮原样回传。
    ContentResponse:
      type: object
      properties:
        role:
          type: string
          description: 响应角色
          enum:
            - model
          example: model
        parts:
          type: array
          description: 响应内容片段列表，支持文本、内联数据、函数调用、函数返回和代码执行结果
          items:
            $ref: '#/components/schemas/Part'
    TokenDetail:
      type: object
      description: Token 详细信息（按模态统计）
      properties:
        modality:
          type: string
          description: 内容模态类型
          enum:
            - MODALITY_UNSPECIFIED
            - TEXT
            - IMAGE
            - AUDIO
            - VIDEO
            - DOCUMENT
          example: TEXT
        tokenCount:
          type: integer
          description: 该模态的 token 数量
          example: 4
    TextPart:
      title: 文本输入
      type: object
      required:
        - text
      properties:
        text:
          type: string
          description: 文本内容
          example: |-
            你好！很高兴能向你介绍我自己。

            我是一个大型语言模型，由 Google 训练和开发...
        thought:
          type: boolean
          description: 是否为思考内容
        thoughtSignature:
          type: string
          description: 思考签名，需要在下一轮原样回传
          example: <Signature_A>
    FilePart:
      title: 多模态输入
      type: object
      required:
        - fileData
      properties:
        fileData:
          type: object
          required:
            - mimeType
            - fileUri
          properties:
            mimeType:
              type: string
              description: |-
                文件MIME类型

                **支持的类型**:

                **图像**:
                - `image/jpeg`, `image/png`
                - 单张最大: 10 MB

                **音频**:
                - `audio/mp3`
                - 单个最大: 10 MB
                - 时长建议: 不超过 10 分钟

                **视频**:
                - `video/mp4`
                - 单个最大: 50 MB
                - 时长建议: 不超过 180 秒

                **文档**:
                - `application/pdf`
                - 单个最大: 20 MB
              example: audio/mp3
            fileUri:
              type: string
              format: uri
              description: |-
                文件URI地址

                **要求**:
                - 必须是公网可访问的URL
                - URL应以文件扩展名结尾（如 .mp3, .jpg），并尽量和mimeType参数保持一致
              example: https://example.com/audio.mp3
    InlineDataPart:
      title: 内联数据
      type: object
      required:
        - inlineData
      properties:
        inlineData:
          $ref: '#/components/schemas/BlobData'
        thought:
          type: boolean
          description: 是否为思考内容
        thoughtSignature:
          type: string
          description: 思考签名，需要在下一轮原样回传
          example: <Signature_A>
    FunctionCallPart:
      title: 函数调用
      type: object
      required:
        - functionCall
      properties:
        functionCall:
          $ref: '#/components/schemas/FunctionCall'
        thought:
          type: boolean
          description: 是否为思考内容
        thoughtSignature:
          type: string
          description: 思考签名，需要在下一轮原样回传
          example: <Signature_A>
    FunctionResponsePart:
      title: 函数返回
      type: object
      required:
        - functionResponse
      properties:
        functionResponse:
          $ref: '#/components/schemas/FunctionResponse'
    ExecutableCodePart:
      title: 生成代码
      type: object
      required:
        - executableCode
      properties:
        executableCode:
          $ref: '#/components/schemas/ExecutableCode'
    CodeExecutionResultPart:
      title: 代码执行结果
      type: object
      required:
        - codeExecutionResult
      properties:
        codeExecutionResult:
          $ref: '#/components/schemas/CodeExecutionResult'
    BlobData:
      type: object
      required:
        - mimeType
        - data
      properties:
        mimeType:
          type: string
          description: IANA MIME 类型
          example: image/png
        data:
          type: string
          format: byte
          description: Base64 编码的原始媒体数据
    FunctionCall:
      type: object
      required:
        - name
        - args
      properties:
        name:
          type: string
          description: 函数名
          example: get_weather
        args:
          type: object
          description: 函数参数
    FunctionResponse:
      type: object
      required:
        - name
        - response
      properties:
        name:
          type: string
          description: 函数名
          example: get_weather
        response:
          type: object
          description: 函数返回内容
        parts:
          type: array
          description: 可选的多模态返回片段
          items:
            $ref: '#/components/schemas/FunctionResponseMediaPart'
    ExecutableCode:
      type: object
      required:
        - language
        - code
      properties:
        language:
          type: string
          description: 代码语言
          example: python
        code:
          type: string
          description: 生成的代码
    CodeExecutionResult:
      type: object
      required:
        - outcome
      properties:
        outcome:
          type: string
          description: 代码执行结果
          enum:
            - OUTCOME_UNSPECIFIED
            - OUTCOME_OK
            - OUTCOME_FAILED
            - OUTCOME_DEADLINE_EXCEEDED
          example: OUTCOME_OK
        output:
          type: string
          description: 标准输出、错误输出或其他描述
    FunctionResponseMediaPart:
      type: object
      required:
        - inlineData
      properties:
        inlineData:
          $ref: '#/components/schemas/BlobData'
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: |-
        ##所有接口均需要使用Bearer Token进行认证##

        **获取 API Key：**

        访问 [API Key 管理页面](https://evolink.ai/dashboard/keys) 获取您的 API Key

        **使用时在请求头中添加：**
        ```
        Authorization: Bearer YOUR_API_KEY
        ```

````