图片生成 Gemini原生
![]()
本页使用图片型号 gemini-3.1-flash-image。gemini-3.8-flash 仅输出文本,不能代替图片型号。图片结果在 candidates[].content.parts[].inlineData 中,需读取 mimeType 并解码 data。查看图片协议。
在 Header 添加参数 Authorization,其值为 Bearer 之后拼接 Token
Authorization: Bearer ********************
请求参数
完整 JSON 请求体
{
"contents": [
{
"role": "user",
"parts": [
{
"text": "Hi, can you create a 3d rendered image of a pig with wings and a top hat flying over a happy futuristic scifi city with lots of greenery?"
}
]
}
],
"generationConfig": {
"responseModalities": [
"TEXT",
"IMAGE"
]
}
}
请求示例代码
curl --fail-with-body --request POST 'https://api.apizt.com/v1beta/models/gemini-3.1-flash-image:generateContent' \
--header "Authorization: Bearer ${tokenba_API_KEY}" \
--header 'Content-Type: application/json' \
--data-raw '{
"contents": [
{
"role": "user",
"parts": [
{
"text": "Hi, can you create a 3d rendered image of a pig with wings and a top hat flying over a happy futuristic scifi city with lots of greenery?"
}
]
}
],
"generationConfig": {
"responseModalities": [
"TEXT",
"IMAGE"
]
}
}'async function main() {
const headers = {
"Authorization": "Bearer " + process.env.tokenba_API_KEY,
"Content-Type": "application/json"
};
const body = JSON.stringify({
"contents": [
{
"role": "user",
"parts": [
{
"text": "Hi, can you create a 3d rendered image of a pig with wings and a top hat flying over a happy futuristic scifi city with lots of greenery?"
}
]
}
],
"generationConfig": {
"responseModalities": [
"TEXT",
"IMAGE"
]
}
});
const response = await fetch("https://api.apizt.com/v1beta/models/gemini-3.1-flash-image:generateContent", { method: "POST", headers, body });
if (!response.ok) throw new Error("HTTP " + response.status + ": " + await response.text());
console.log(await response.text());
}
main().catch(console.error);import os
import requests
headers = {"Authorization": "Bearer " + os.environ["tokenba_API_KEY"]}
payload = {'contents': [{'role': 'user',
'parts': [{'text': 'Hi, can you create a 3d rendered image of a pig '
'with wings and a top hat flying over a happy '
'futuristic scifi city with lots of greenery?'}]}],
'generationConfig': {'responseModalities': ['TEXT', 'IMAGE']}}
response = requests.post('https://api.apizt.com/v1beta/models/gemini-3.1-flash-image:generateContent', headers=headers, json=payload, timeout=120)
response.raise_for_status()
print(response.text)返回响应
文本位于 candidates[].content.parts[].text。按 Part 类型解析;工具调用为 functionCall,图片或音频为 inlineData,思考摘要可带 thought。工具循环需保留 thoughtSignature。
生成图片位于 inlineData.data;Base64 解码后按 inlineData.mimeType 保存。结构示例中的 BASE64_IMAGE_BYTES 不是实际图片内容。
以下为结构示例,不代表实际调用结果。
{
"candidates": [
{
"content": {
"role": "model",
"parts": [
{
"text": "这是一段响应结构示例。"
},
{
"inlineData": {
"mimeType": "image/png",
"data": "BASE64_IMAGE_BYTES"
}
}
]
},
"finishReason": "STOP"
}
],
"usageMetadata": {
"promptTokenCount": 10,
"candidatesTokenCount": 8,
"totalTokenCount": 18
}
}
当前模型与版本
依据 apizt 价格页,同步于 。以下型号按目录声明的协议与本页用途筛选;不代表所有参数和功能通用。切换前请核对型号说明、令牌分组与参数差异。Gemini 原生接口需同时替换 URL 中的模型 ID。
| 模型 ID | 能力标签 | 支持分组 |
|---|---|---|
gemini-3.1-flash-image | 绘画 | 分组(9)
|
gemini-3.1-flash-image-preview | 绘画 | 分组(9)
|
gemini-3-pro-image-preview | 绘画 | 分组(9)
|
gemini-3.1-flash-lite-image | 绘画 | 分组(7)
|
gemini-3-pro-image | 绘画 | 分组(9)
|
gemini-2.5-flash-image | 绘画 | 分组(9)
|
共列入 6 个候选型号。查看完整模型、版本与接口目录。