Skip to content

gemini-3.1-flash-image-preview 文生图

POST https://az.gptplus5.com/v1beta/modles/gemini-3.1-flash-image-preview:generateContent

官方文档: https://ai.google.dev/gemini-api/docs/image-generation?hl=zh-cn#rest

使用文本提示生成图片。可通过 response_format 控制输出图片的 MIME 类型、宽高比以及尺寸级别。

请求参数

Header 参数

参数名类型必需说明示例
Authorizationstring必需API Key 鉴权Bearer {{YOUR_API_KEY}}
Content-Typestring必需application/json

Body 参数 (application/json)

参数名类型必需说明
modelstring必需模型名称,固定值 gemini-3.1-flash-image
inputarray | string必需输入内容。数组形式下每一项是带 type 的内容片段;也可以直接传字符串作为纯文本提示
  └ typestring必需内容片段类型,文本为 text
  └ textstring必需提示词文本,描述要生成的图片内容
response_formatobject可选输出图片格式配置
  └ typestring可选输出类型,固定值 image
  └ mime_typestring可选输出图片 MIME 类型,如 image/jpegimage/png
  └ aspect_ratiostring可选宽高比,如 1:116:99:164:33:4
  └ image_sizestring可选图片尺寸级别,如 1K2K
toolsarray可选可启用的工具列表,例如 [{"type": "google_search"}] 可让模型在生成前先联网检索

请求示例

json
{
  "model": "gemini-3.1-flash-image",
  "input": [
    {
      "type": "text",
      "text": "Create a picture of a nano banana dish in a fancy restaurant with a Gemini theme"
    }
  ],
  "response_format": {
    "type": "image",
    "mime_type": "image/jpeg",
    "aspect_ratio": "16:9",
    "image_size": "2K"
  }
}

cURL 示例

bash
curl --location --request POST 'https://az.gptplus5.com/v1beta/modles/gemini-3.1-flash-image-preview:generateContent' \
  --header 'Content-Type: application/json' \
  --header 'Authorization: Bearer sk-xxx' \
  --data-raw '{
    "model": "gemini-3.1-flash-image",
    "input": [
      {
        "type": "text",
        "text": "Create a picture of a nano banana dish in a fancy restaurant with a Gemini theme"
      }
    ]
  }'

多轮迭代生成

继续以对话方式优化图片。通过响应中返回的 id,下一次请求把它作为 previous_interaction_id 传入,并附上新的文本指令,即可基于上一轮的图片继续修改。

bash
curl --location --request POST 'https://az.gptplus5.com/v1beta/modles/gemini-3.1-flash-image-preview:generateContent' \
  --header 'Content-Type: application/json' \
  --header 'Authorization: Bearer sk-xxx' \
  --data-raw '{
    "model": "gemini-3.1-flash-image",
    "input": "Update this image to use a warmer color palette. Do not change any other elements of the image.",
    "previous_interaction_id": "<PREVIOUS_INTERACTION_ID>",
    "response_format": {
      "type": "image",
      "mime_type": "image/jpeg",
      "aspect_ratio": "16:9",
      "image_size": "2K"
    }
  }'

返回响应

🟢200成功

响应 Body

参数名类型必需说明
idstring必需本次交互的唯一标识,可在下一轮请求中作为 previous_interaction_id 传入以实现多轮迭代
outputarray必需输出内容数组
  └ typestring必需输出片段类型,如 image
  └ mime_typestring必需输出图片的 MIME 类型
  └ datastring必需输出图片的 Base64 编码数据

响应示例

json
{
  "id": "<INTERACTION_ID>",
  "output": [
    {
      "type": "image",
      "mime_type": "image/jpeg",
      "data": "<base64...>"
    }
  ]
}