Generate an image with gemini-2.5-flash-image
curl --request POST \
--url https://api.yingtu.ai/v1beta/models/gemini-2.5-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-2.5-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-2.5-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/png",
"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-2.5-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 2.5 Flash Image
Gemini 2.5 Flash Image 示例
使用稳定模型 ID 完成同步生成、异步提交和 Base64 图片读取。
POST
/
v1beta
/
models
/
gemini-2.5-flash-image:generateContent
Generate an image with gemini-2.5-flash-image
curl --request POST \
--url https://api.yingtu.ai/v1beta/models/gemini-2.5-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-2.5-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-2.5-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/png",
"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-2.5-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>"
}
}同步生成
curl 'https://api.yingtu.ai/v1beta/models/gemini-2.5-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"}
}
}'
{
"candidates": [{
"content": {
"role": "model",
"parts": [
{"text": "图片已生成。"},
{"inlineData": {"mimeType": "image/png", "data": "BASE64_IMAGE_DATA"}}
]
},
"finishReason": "STOP",
"index": 0
}],
"modelVersion": "gemini-2.5-flash-image",
"responseId": "response_example"
}
改为异步
请求体不变,只把方法后缀改成:asyncGenerateContent。保存 HTTP 202 返回的
task_id,再查询 /v1/tasks/{task_id}。实测任务经过 in_progress 后返回
completed 和 1024 × 1024 PNG。
import base64
for candidate in result["candidates"]:
for part in candidate["content"]["parts"]:
if "inlineData" in part:
image_bytes = base64.b64decode(part["inlineData"]["data"])
mime_type = part["inlineData"]["mimeType"]
在线测试
本页已经嵌入固定路径gemini-2.5-flash-image:generateContent 的真实 OpenAPI
试一试 表单。填入开发凭证、确认请求体后即可同步生成,不需要跳转到 API 参考。
在线测试会产生真实费用。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-2.5-flash-image"
Provider response identifier.
示例:
"response_example"
Creation time when supplied by the selected model channel.