同步生成图片(真实计费)
curl --request POST \
--url https://api.yingtu.ai/v1beta/models/{model}:generateContent \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"contents": [
{
"role": "user",
"parts": [
{
"text": "日出时分安静的阅览室,纪实摄影风格"
}
]
}
]
}
'import requests
url = "https://api.yingtu.ai/v1beta/models/{model}:generateContent"
payload = { "contents": [
{
"role": "user",
"parts": [{ "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: '日出时分安静的阅览室,纪实摄影风格'}]}]})
};
fetch('https://api.yingtu.ai/v1beta/models/{model}: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",
"param": "<string>",
"code": "insufficient_user_quota"
}
}{
"error": {
"message": "<string>",
"type": "invalid_request_error",
"param": "<string>",
"code": "insufficient_user_quota"
}
}{
"error": {
"message": "Insufficient balance for this request",
"type": "new_api_error",
"param": "",
"code": "insufficient_user_quota"
}
}{
"error": {
"message": "Request body exceeds the current limit",
"type": "new_api_error",
"param": "",
"code": "read_request_body_failed"
}
}{
"error": {
"message": "<string>",
"type": "invalid_request_error",
"param": "<string>",
"code": "insufficient_user_quota"
}
}{
"error": {
"message": "<string>",
"type": "invalid_request_error",
"param": "<string>",
"code": "insufficient_user_quota"
}
}Gemini API
同步生成图片
查看并测试 YingTu generateContent 接口,包括 Gemini 原生请求、响应 Part 互斥结构和错误状态。
POST
/
v1beta
/
models
/
{model}
:generateContent
同步生成图片(真实计费)
curl --request POST \
--url https://api.yingtu.ai/v1beta/models/{model}:generateContent \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"contents": [
{
"role": "user",
"parts": [
{
"text": "日出时分安静的阅览室,纪实摄影风格"
}
]
}
]
}
'import requests
url = "https://api.yingtu.ai/v1beta/models/{model}:generateContent"
payload = { "contents": [
{
"role": "user",
"parts": [{ "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: '日出时分安静的阅览室,纪实摄影风格'}]}]})
};
fetch('https://api.yingtu.ai/v1beta/models/{model}: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",
"param": "<string>",
"code": "insufficient_user_quota"
}
}{
"error": {
"message": "<string>",
"type": "invalid_request_error",
"param": "<string>",
"code": "insufficient_user_quota"
}
}{
"error": {
"message": "Insufficient balance for this request",
"type": "new_api_error",
"param": "",
"code": "insufficient_user_quota"
}
}{
"error": {
"message": "Request body exceeds the current limit",
"type": "new_api_error",
"param": "",
"code": "read_request_body_failed"
}
}{
"error": {
"message": "<string>",
"type": "invalid_request_error",
"param": "<string>",
"code": "insufficient_user_quota"
}
}{
"error": {
"message": "<string>",
"type": "invalid_request_error",
"param": "<string>",
"code": "insufficient_user_quota"
}
}调用方能够保持连接直到完整 Gemini 响应返回时,使用本接口。
通用 schema 会显示整个家族的尺寸和宽高比并集,发送前必须再看所选模型的参数页:2.5 不能传
imageSize,Lite 只能使用 1K,只有 Flash 支持 1:4、4:1、1:8、8:1。
“试一试”会从浏览器直接发送真实请求并可能产生费用。请使用开发密钥,确认模型与尺寸,
不要分享包含密钥的生成 cURL 或鉴权截图。
先选模型
根据生命周期、尺寸和相对成本选择。
理解同步方式
设置连接超时并正确读取所有 parts。
根据状态码处理失败
分清参数、密钥、余额、限流和服务端错误。
授权
YingTu API Key。
路径参数
Current public image model ID.
可用选项:
gemini-2.5-flash-image, gemini-3.1-flash-lite-image, gemini-3.1-flash-image, gemini-3-pro-image, gpt-image-2-web, gpt-image-2-vip 请求体
application/json
发送给模型的消息。
Minimum array length:
1Show child attributes
Show child attributes
可选 Gemini 工具;是否可用取决于所选图片模型。
在 tools 中声明的工具配置。
Show child attributes
Show child attributes
Show child attributes
Show child attributes
所选模型支持时使用的可选缓存内容资源名称。
Show child attributes
Show child attributes
最后修改于 2026年9月2日