> ## 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.

# 生成内容

> 根据输入的 GenerateContentRequest 生成模型回复。



## OpenAPI

````yaml zh/api-reference/endpoints/openapi/gemini-native/openapi.yaml POST /v1beta/models/{model}:generateContent
openapi: 3.1.0
info:
  title: Gemini 原生端点
  description: 通过 Anyfast 调用 Google Gemini 原生 generateContent 接口
  version: 1.0.0
servers:
  - url: https://www.anyfast.ai
security:
  - bearerAuth: []
paths:
  /v1beta/models/{model}:generateContent:
    post:
      summary: 生成内容
      description: 根据输入的 GenerateContentRequest 生成模型回复。
      operationId: generateContent
      parameters:
        - name: model
          in: path
          required: true
          schema:
            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: 用于生成的模型名称。
          example: gemini-2.5-pro
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - contents
              properties:
                contents:
                  type: array
                  minItems: 1
                  description: 与模型的当前对话内容。
                  items:
                    type: object
                    required:
                      - parts
                    properties:
                      role:
                        type: string
                        enum:
                          - user
                          - model
                        description: 内容作者的角色。
                      parts:
                        type: array
                        items:
                          type: object
                          properties:
                            text:
                              type: string
                              description: 文本内容。
                            inlineData:
                              type: object
                              properties:
                                mimeType:
                                  type: string
                                data:
                                  type: string
                              description: 内联媒体字节。
                  example:
                    - role: user
                      parts:
                        - text: 你好，Gemini！
                systemInstruction:
                  type: object
                  properties:
                    parts:
                      type: array
                      items:
                        type: object
                        properties:
                          text:
                            type: string
                  description: 开发者设置的系统指令。
                generationConfig:
                  type: object
                  properties:
                    temperature:
                      type: number
                      minimum: 0
                      maximum: 2
                      description: 控制输出的随机性。
                    topP:
                      type: number
                      minimum: 0
                      maximum: 1
                      description: 采样时考虑的 token 最大累积概率。
                    topK:
                      type: integer
                      description: 采样时考虑的最大 token 数。
                    maxOutputTokens:
                      type: integer
                      description: 响应候选中包含的最大 token 数。
                    stopSequences:
                      type: array
                      items:
                        type: string
                      description: 停止输出生成的字符序列集合。
                    responseMimeType:
                      type: string
                      enum:
                        - text/plain
                        - application/json
                      description: 生成的候选文本的 MIME 类型。
                    responseSchema:
                      type: object
                      description: 当 responseMimeType 为 application/json 时，生成的候选文本的输出模式。
                  description: 模型生成和输出的配置选项。
                tools:
                  type: array
                  items:
                    type: object
                    properties:
                      functionDeclarations:
                        type: array
                        items:
                          type: object
                          required:
                            - name
                          properties:
                            name:
                              type: string
                            description:
                              type: string
                            parameters:
                              type: object
                  description: 模型可用于生成响应的工具列表。
                toolConfig:
                  type: object
                  properties:
                    functionCallingConfig:
                      type: object
                      properties:
                        mode:
                          type: string
                          enum:
                            - AUTO
                            - ANY
                            - NONE
                        allowedFunctionNames:
                          type: array
                          items:
                            type: string
                  description: 请求中指定的任何工具的工具配置。
                safetySettings:
                  type: array
                  items:
                    type: object
                    properties:
                      category:
                        type: string
                        enum:
                          - HARM_CATEGORY_HARASSMENT
                          - HARM_CATEGORY_HATE_SPEECH
                          - HARM_CATEGORY_SEXUALLY_EXPLICIT
                          - HARM_CATEGORY_DANGEROUS_CONTENT
                      threshold:
                        type: string
                        enum:
                          - BLOCK_NONE
                          - BLOCK_LOW_AND_ABOVE
                          - BLOCK_MEDIUM_AND_ABOVE
                          - BLOCK_ONLY_HIGH
                  description: 用于阻止不安全内容的安全设置列表。
      responses:
        '200':
          description: 内容生成成功
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GenerateContentResponse'
        '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:
    GenerateContentResponse:
      type: object
      properties:
        candidates:
          type: array
          items:
            type: object
            properties:
              content:
                type: object
                properties:
                  parts:
                    type: array
                    items:
                      type: object
                      properties:
                        text:
                          type: string
                  role:
                    type: string
                    example: model
              finishReason:
                type: string
                enum:
                  - STOP
                  - MAX_TOKENS
                  - SAFETY
                  - RECITATION
                  - OTHER
              index:
                type: integer
              safetyRatings:
                type: array
                items:
                  type: object
                  properties:
                    category:
                      type: string
                    probability:
                      type: string
        usageMetadata:
          type: object
          properties:
            promptTokenCount:
              type: integer
            candidatesTokenCount:
              type: integer
            totalTokenCount:
              type: integer
        modelVersion:
          type: string
    Error:
      type: object
      properties:
        error:
          type: object
          properties:
            code:
              type: integer
            message:
              type: string
            status:
              type: string
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer

````