Generate an image with gemini-3.1-flash-image
curl --request POST \
--url https://api.yingtu.ai/v1beta/models/gemini-3.1-flash-image:generateContent \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"contents": [
{
"role": "user",
"parts": [
{
"text": "A single yellow ceramic banana on a matte white background, soft studio lighting, no text."
}
]
}
]
}
'import requests
url = "https://api.yingtu.ai/v1beta/models/gemini-3.1-flash-image:generateContent"
payload = { "contents": [
{
"role": "user",
"parts": [{ "text": "A single yellow ceramic banana on a matte white background, soft studio lighting, no text." }]
}
] }
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
contents: [
{
role: 'user',
parts: [
{
text: 'A single yellow ceramic banana on a matte white background, soft studio lighting, no text.'
}
]
}
]
})
};
fetch('https://api.yingtu.ai/v1beta/models/gemini-3.1-flash-image:generateContent', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));{
"candidates": [
{
"content": {
"role": "model",
"parts": [
{
"inlineData": {
"mimeType": "image/jpeg",
"data": "BASE64_IMAGE_DATA"
}
}
]
},
"finishReason": "STOP",
"index": 0
}
],
"usageMetadata": {
"promptTokenCount": 37,
"candidatesTokenCount": 1846,
"totalTokenCount": 1883,
"promptTokensDetails": [
{
"modality": "TEXT",
"tokenCount": 37
}
],
"candidatesTokensDetails": [
{
"modality": "IMAGE",
"tokenCount": 1680
}
]
},
"modelVersion": "gemini-3.1-flash-image",
"responseId": "response_example"
}{
"error": {
"message": "<string>",
"type": "invalid_request_error",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "invalid_request_error",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "invalid_request_error",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "invalid_request_error",
"code": "<string>"
}
}Gemini 3.1 Flash Image
Gemini 3.1 Flash Image 示例
用 Nano Banana 2 生成 2K 图片、提交 1K 异步任务并正确读取 JPEG 响应。
POST
/
v1beta
/
models
/
gemini-3.1-flash-image:generateContent
Generate an image with gemini-3.1-flash-image
curl --request POST \
--url https://api.yingtu.ai/v1beta/models/gemini-3.1-flash-image:generateContent \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"contents": [
{
"role": "user",
"parts": [
{
"text": "A single yellow ceramic banana on a matte white background, soft studio lighting, no text."
}
]
}
]
}
'import requests
url = "https://api.yingtu.ai/v1beta/models/gemini-3.1-flash-image:generateContent"
payload = { "contents": [
{
"role": "user",
"parts": [{ "text": "A single yellow ceramic banana on a matte white background, soft studio lighting, no text." }]
}
] }
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
contents: [
{
role: 'user',
parts: [
{
text: 'A single yellow ceramic banana on a matte white background, soft studio lighting, no text.'
}
]
}
]
})
};
fetch('https://api.yingtu.ai/v1beta/models/gemini-3.1-flash-image:generateContent', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));{
"candidates": [
{
"content": {
"role": "model",
"parts": [
{
"inlineData": {
"mimeType": "image/jpeg",
"data": "BASE64_IMAGE_DATA"
}
}
]
},
"finishReason": "STOP",
"index": 0
}
],
"usageMetadata": {
"promptTokenCount": 37,
"candidatesTokenCount": 1846,
"totalTokenCount": 1883,
"promptTokensDetails": [
{
"modality": "TEXT",
"tokenCount": 37
}
],
"candidatesTokensDetails": [
{
"modality": "IMAGE",
"tokenCount": 1680
}
]
},
"modelVersion": "gemini-3.1-flash-image",
"responseId": "response_example"
}{
"error": {
"message": "<string>",
"type": "invalid_request_error",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "invalid_request_error",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "invalid_request_error",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "invalid_request_error",
"code": "<string>"
}
}生成 2K 图片
curl 'https://api.yingtu.ai/v1beta/models/gemini-3.1-flash-image:generateContent' \
-H 'Authorization: Bearer YOUR_YINGTU_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"contents": [{"role": "user", "parts": [{"text": "建筑杂志风格的现代台灯摄影"}]}],
"generationConfig": {
"responseModalities": ["TEXT", "IMAGE"],
"imageConfig": {"aspectRatio": "1:1", "imageSize": "2K"}
}
}'
{
"candidates": [{
"content": {"role": "model", "parts": [{
"inlineData": {"mimeType": "image/jpeg", "data": "BASE64_IMAGE_DATA"}
}]},
"finishReason": "STOP",
"index": 0
}],
"usageMetadata": {
"promptTokenCount": 37,
"candidatesTokenCount": 1846,
"totalTokenCount": 1883
},
"modelVersion": "gemini-3.1-flash-image",
"responseId": "response_example"
}
提交 1K 异步任务
把imageSize 改为 1K,并使用 :asyncGenerateContent。实测提交返回 HTTP 202,
任务在第四次查询时完成。完成响应位于 result 中,结构与同步响应一致。
图片编辑同样使用 contents[].parts[];某次编辑响应先返回文字,再返回 JPEG,
因此解析器不能固定读取 parts[0]。
在线测试
嵌入的 OpenAPI operation 已固定到gemini-3.1-flash-image:generateContent。确认 imageSize、填入开发凭证后,
可直接在当前示例页发送请求。
所选尺寸决定真实计费档位。Mintlify 会在生成的 cURL 中显示已输入的 Key,请勿分享带凭证的截图。
授权
YingTu API key.
请求体
application/json
响应
Complete Gemini response
Show child attributes
Show child attributes
Show child attributes
Show child attributes
The model version that produced the response.
示例:
"gemini-3.1-flash-image"
Provider response identifier.
示例:
"response_example"
Creation time when supplied by the selected model channel.