主题
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 参数
| 参数名 | 类型 | 必需 | 说明 | 示例 |
|---|---|---|---|---|
Authorization | string | 必需 | API Key 鉴权 | Bearer {{YOUR_API_KEY}} |
Content-Type | string | 必需 | application/json |
Body 参数 (application/json)
| 参数名 | 类型 | 必需 | 说明 |
|---|---|---|---|
model | string | 必需 | 模型名称,固定值 gemini-3.1-flash-image |
input | array | string | 必需 | 输入内容。数组形式下每一项是带 type 的内容片段;也可以直接传字符串作为纯文本提示 |
└ type | string | 必需 | 内容片段类型,文本为 text |
└ text | string | 必需 | 提示词文本,描述要生成的图片内容 |
response_format | object | 可选 | 输出图片格式配置 |
└ type | string | 可选 | 输出类型,固定值 image |
└ mime_type | string | 可选 | 输出图片 MIME 类型,如 image/jpeg、image/png |
└ aspect_ratio | string | 可选 | 宽高比,如 1:1、16:9、9:16、4:3、3:4 |
└ image_size | string | 可选 | 图片尺寸级别,如 1K、2K |
tools | array | 可选 | 可启用的工具列表,例如 [{"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
| 参数名 | 类型 | 必需 | 说明 |
|---|---|---|---|
id | string | 必需 | 本次交互的唯一标识,可在下一轮请求中作为 previous_interaction_id 传入以实现多轮迭代 |
output | array | 必需 | 输出内容数组 |
└ type | string | 必需 | 输出片段类型,如 image |
└ mime_type | string | 必需 | 输出图片的 MIME 类型 |
└ data | string | 必需 | 输出图片的 Base64 编码数据 |
响应示例
json
{
"id": "<INTERACTION_ID>",
"output": [
{
"type": "image",
"mime_type": "image/jpeg",
"data": "<base64...>"
}
]
}