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

# generateContent

> 使用指定模型生成文本内容



## OpenAPI

````yaml POST /v1beta/models/{model}:generateContent
openapi: 3.1.0
info:
  title: TokenOps AI API
  description: TokenOps AI API 提供了强大的AI服务能力，包括聊天对话、Gemini模型集成等功能。
  license:
    name: MIT
  version: 1.0.0
servers:
  - url: https://model-api.skyengine.com.cn
    description: TokenOps AI API 生产环境
security: []
paths:
  /v1beta/models/{model}:generateContent:
    post:
      summary: 生成内容
      description: 使用指定模型生成文本内容
      operationId: generateContent
      parameters:
        - name: model
          in: path
          required: true
          description: 模型名称，如 gemini-2.5-flash
          schema:
            type: string
            example: gemini-2.5-flash
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/GenerateContentRequest'
            examples:
              text_only:
                summary: 纯文本对话
                value:
                  contents:
                    - parts:
                        - text: 请介绍一下人工智能的发展历史
              video_understanding:
                summary: 视频理解（使用 FileUpload API）
                description: 先通过 /v1/files/upload 上传视频文件，获得 tokenops:// URI，然后用于视频内容分析
                value:
                  contents:
                    - parts:
                        - fileData:
                            mimeType: video/mp4
                            fileUri: >-
                              tokenops://bucket.example.com/file_api/20241016/video.mp4
                        - text: 这个视频里发生了什么？请详细描述视频内容。
              image_understanding:
                summary: 图片理解（使用 FileUpload API）
                description: 先通过 /v1/files/upload 上传图片文件，获得 tokenops:// URI，然后用于图片内容分析
                value:
                  contents:
                    - parts:
                        - fileData:
                            mimeType: image/jpeg
                            fileUri: >-
                              tokenops://bucket.example.com/file_api/20241016/image.jpg
                        - text: 请分析这张图片的内容，包括场景、物体、人物等。
              multiple_files:
                summary: 多文件分析
                description: 同时分析多个上传的文件
                value:
                  contents:
                    - parts:
                        - fileData:
                            mimeType: image/jpeg
                            fileUri: >-
                              tokenops://bucket.example.com/file_api/20241016/image1.jpg
                        - fileData:
                            mimeType: image/jpeg
                            fileUri: >-
                              tokenops://bucket.example.com/file_api/20241016/image2.jpg
                        - text: 请比较这两张图片的异同点。
      responses:
        '200':
          description: 成功生成内容
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GenerateContentResponse'
        '400':
          description: 请求参数错误
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '403':
          description: API密钥无效或权限不足
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
      security:
        - ApiKeyAuth: []
components:
  schemas:
    GenerateContentRequest:
      type: object
      required:
        - contents
      properties:
        contents:
          type: array
          description: 输入内容列表，表示对话历史
          example:
            - parts:
                - text: 你好，请介绍一下你自己
          items:
            $ref: '#/components/schemas/Content'
        tools:
          type: array
          description: 可用的工具列表
          items:
            $ref: '#/components/schemas/Tool'
        toolConfig:
          $ref: '#/components/schemas/ToolConfig'
          description: 工具配置选项
        safetySettings:
          type: array
          description: 安全设置
          items:
            $ref: '#/components/schemas/SafetySetting'
        systemInstruction:
          $ref: '#/components/schemas/Content'
          description: 系统指令
        generationConfig:
          $ref: '#/components/schemas/GenerationConfig'
          description: 生成配置参数
    GenerateContentResponse:
      type: object
      properties:
        candidates:
          type: array
          description: 生成的候选回答
          items:
            $ref: '#/components/schemas/Candidate'
        promptFeedback:
          $ref: '#/components/schemas/PromptFeedback'
          description: 提示词反馈信息
        usageMetadata:
          $ref: '#/components/schemas/UsageMetadata'
          description: 使用情况统计
        modelVersion:
          type: string
          description: 使用的模型版本
          example: gemini-2.5-flash
    ErrorResponse:
      type: object
      properties:
        error:
          $ref: '#/components/schemas/Status'
          description: 错误信息
    Content:
      type: object
      required:
        - parts
      properties:
        parts:
          type: array
          description: 内容部分列表
          example:
            - text: 你好，请介绍一下你自己
          items:
            $ref: '#/components/schemas/Part'
        role:
          type: string
          enum:
            - user
            - model
          description: 角色：用户或模型
    Tool:
      type: object
      properties:
        functionDeclarations:
          type: array
          description: 函数声明列表
          items:
            $ref: '#/components/schemas/FunctionDeclaration'
        codeExecution:
          $ref: '#/components/schemas/CodeExecution'
          description: 代码执行工具
    ToolConfig:
      type: object
      properties:
        functionCallingConfig:
          $ref: '#/components/schemas/FunctionCallingConfig'
          description: 函数调用配置
    SafetySetting:
      type: object
      required:
        - category
        - threshold
      properties:
        category:
          type: string
          enum:
            - HARM_CATEGORY_UNSPECIFIED
            - HARM_CATEGORY_DEROGATORY
            - HARM_CATEGORY_TOXICITY
            - HARM_CATEGORY_VIOLENCE
            - HARM_CATEGORY_SEXUAL
            - HARM_CATEGORY_MEDICAL
            - HARM_CATEGORY_DANGEROUS
            - HARM_CATEGORY_HARASSMENT
            - HARM_CATEGORY_HATE_SPEECH
            - HARM_CATEGORY_SEXUALLY_EXPLICIT
            - HARM_CATEGORY_DANGEROUS_CONTENT
          description: 安全类别
          example: HARM_CATEGORY_HARASSMENT
        threshold:
          type: string
          enum:
            - HARM_BLOCK_THRESHOLD_UNSPECIFIED
            - BLOCK_LOW_AND_ABOVE
            - BLOCK_MEDIUM_AND_ABOVE
            - BLOCK_ONLY_HIGH
            - BLOCK_NONE
          description: 阻止阈值
          example: BLOCK_MEDIUM_AND_ABOVE
    GenerationConfig:
      type: object
      properties:
        stopSequences:
          type: array
          description: 停止序列
          items:
            type: string
        responseMimeType:
          type: string
          description: 响应MIME类型
          example: text/plain
        responseSchema:
          type: object
          description: 响应模式
          additionalProperties: true
        candidateCount:
          type: integer
          description: 候选回答数量
          minimum: 1
          maximum: 8
          default: 1
        maxOutputTokens:
          type: integer
          description: 最大输出token数量
        temperature:
          type: number
          description: 温度参数，控制随机性
          minimum: 0
          maximum: 2
          default: 1
        topP:
          type: number
          description: Top-p采样参数
          minimum: 0
          maximum: 1
          default: 0.95
        topK:
          type: integer
          description: Top-k采样参数
          minimum: 1
          default: 40
        presencePenalty:
          type: number
          description: 存在惩罚
          minimum: -2
          maximum: 2
        frequencyPenalty:
          type: number
          description: 频率惩罚
          minimum: -2
          maximum: 2
        responseLogprobs:
          type: boolean
          description: 是否返回对数概率
        logprobs:
          type: integer
          description: 返回的对数概率数量
    Candidate:
      type: object
      properties:
        content:
          $ref: '#/components/schemas/Content'
          description: 生成的内容
        finishReason:
          type: string
          enum:
            - FINISH_REASON_UNSPECIFIED
            - STOP
            - MAX_TOKENS
            - SAFETY
            - RECITATION
            - LANGUAGE
            - OTHER
          description: 完成原因
        index:
          type: integer
          description: 候选项索引
        safetyRatings:
          type: array
          description: 安全评级
          items:
            $ref: '#/components/schemas/SafetyRating'
        citationMetadata:
          $ref: '#/components/schemas/CitationMetadata'
          description: 引用元数据
        tokenCount:
          type: integer
          description: 生成的token数量
    PromptFeedback:
      type: object
      properties:
        blockReason:
          type: string
          enum:
            - BLOCK_REASON_UNSPECIFIED
            - SAFETY
            - OTHER
          description: 阻止原因
        safetyRatings:
          type: array
          description: 安全评级
          items:
            $ref: '#/components/schemas/SafetyRating'
    UsageMetadata:
      type: object
      properties:
        promptTokenCount:
          type: integer
          description: 提示词token数量
        candidatesTokenCount:
          type: integer
          description: 候选回答token数量
        totalTokenCount:
          type: integer
          description: 总token数量
        cachedContentTokenCount:
          type: integer
          description: 缓存内容token数量
    Status:
      type: object
      properties:
        code:
          type: integer
          description: 错误代码
        message:
          type: string
          description: 错误消息
        details:
          type: array
          description: 错误详情
          items:
            type: object
            additionalProperties: true
    Part:
      type: object
      oneOf:
        - type: object
          required:
            - text
          properties:
            text:
              type: string
              description: 文本内容
              example: 你好，请介绍一下你自己
        - type: object
          required:
            - inlineData
          properties:
            inlineData:
              $ref: '#/components/schemas/Blob'
        - type: object
          required:
            - fileData
          properties:
            fileData:
              $ref: '#/components/schemas/FileData'
        - type: object
          required:
            - functionCall
          properties:
            functionCall:
              $ref: '#/components/schemas/FunctionCall'
        - type: object
          required:
            - functionResponse
          properties:
            functionResponse:
              $ref: '#/components/schemas/FunctionResponse'
    FunctionDeclaration:
      type: object
      required:
        - name
      properties:
        name:
          type: string
          description: 函数名称
          example: get_weather
        description:
          type: string
          description: 函数描述
        parameters:
          type: object
          description: 函数参数模式
          additionalProperties: true
    CodeExecution:
      type: object
      description: 代码执行工具配置
    FunctionCallingConfig:
      type: object
      properties:
        mode:
          type: string
          enum:
            - MODE_UNSPECIFIED
            - AUTO
            - ANY
            - NONE
          description: 函数调用模式
        allowedFunctionNames:
          type: array
          description: 允许的函数名称列表
          items:
            type: string
    SafetyRating:
      type: object
      properties:
        category:
          type: string
          description: 安全类别
        probability:
          type: string
          enum:
            - HARM_PROBABILITY_UNSPECIFIED
            - NEGLIGIBLE
            - LOW
            - MEDIUM
            - HIGH
          description: 有害概率
        blocked:
          type: boolean
          description: 是否被阻止
    CitationMetadata:
      type: object
      properties:
        citationSources:
          type: array
          description: 引用来源
          items:
            $ref: '#/components/schemas/CitationSource'
    Blob:
      type: object
      required:
        - mimeType
        - data
      properties:
        mimeType:
          type: string
          description: MIME类型
          example: image/jpeg
        data:
          type: string
          format: byte
          description: Base64编码的数据
          example: >-
            iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg==
    FileData:
      type: object
      required:
        - mimeType
        - fileUri
      properties:
        mimeType:
          type: string
          description: 文件MIME类型
          example: image/jpeg
        fileUri:
          type: string
          description: 文件URI
          example: gs://generativeai-uploads/file-abc123
    FunctionCall:
      type: object
      required:
        - name
      properties:
        name:
          type: string
          description: 函数名称
          example: get_weather
        args:
          type: object
          description: 函数参数
          additionalProperties: true
    FunctionResponse:
      type: object
      required:
        - name
        - response
      properties:
        name:
          type: string
          description: 函数名称
          example: get_weather
        response:
          type: object
          description: 函数响应
          additionalProperties: true
    CitationSource:
      type: object
      properties:
        startIndex:
          type: integer
          description: 开始索引
        endIndex:
          type: integer
          description: 结束索引
        uri:
          type: string
          description: 来源URI
        license:
          type: string
          description: 许可证
  securitySchemes:
    ApiKeyAuth:
      type: http
      scheme: bearer
      description: >-
        ModelHub API密钥认证。在 `Authorization` HTTP Header 中包含您的 API-Key，格式为 `Bearer
        {API_KEY}`

````