curl --request POST \
--url https://api.omniall.ai/v1/chat/completions \
--header 'Authorization: <authorization>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "gemini-3.1-flash-image-preview",
"messages": [
{
"role": "user",
"content": "一只在樱花树下睡觉的橘猫,日系插画,柔和光线"
}
],
"stream": false,
"extra_body": {
"google": {
"image_config": {
"aspect_ratio": "1:1",
"image_size": "2K"
}
}
}
}
'{}Gemini绘图
Chat 生图
Gemini 生图(OpenAI Chat Completions)。文生图与图生图为同一接口。
路径: POST https://api.omniall.ai/v1/chat/completions
- 文生图:
content为纯文本字符串,或仅含type: text - 图生图 / 多图参考:
content数组含text+ 一条或多条image_url - PDF / 短视频参考(香蕉 2.1):再加
type: file/type: video_url
推荐使用非流式 stream: false。鉴权:Authorization: Bearer sk-...
POST
/
v1
/
chat
/
completions
curl --request POST \
--url https://api.omniall.ai/v1/chat/completions \
--header 'Authorization: <authorization>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "gemini-3.1-flash-image-preview",
"messages": [
{
"role": "user",
"content": "一只在樱花树下睡觉的橘猫,日系插画,柔和光线"
}
],
"stream": false,
"extra_body": {
"google": {
"image_config": {
"aspect_ratio": "1:1",
"image_size": "2K"
}
}
}
}
'{}同一接口,多种用例
POST /v1/chat/completions 同时覆盖 文生图 与 图生图(以及多图 / PDF / 短视频参考)。区别只在 messages 里放什么,不是两个 API。
| 用例 | messages[].content |
|---|---|
| 文生图 | 纯文本字符串,或仅 type: text |
| 图生图 | text + image_url(可多张) |
| PDF 参考(香蕉 2.1) | text + file |
| 短视频参考(香蕉 2.1) | text + video_url(字符串) |
messages → 下载 URL / 解码 data URL → Gemini inlineData → 上游 generateContent。
远程 PDF / 视频 URL 可以传;不会以 fileUri 原样透传给上游。
| 媒体 | content 类型 | 取值 |
|---|---|---|
| 图片 | image_url | HTTPS URL 或 data:image/...;base64,... |
file | filename + file_data(HTTPS URL 或 data:application/pdf;base64,...) | |
| 视频 | video_url | 字符串 HTTPS URL 或 data:video/mp4;base64,... |
PDF URL(完整)
{
"model": "gemini-nano-banana-2.1",
"stream": false,
"extra_body": {
"google": {
"image_config": {
"aspect_ratio": "3:2",
"image_size": "1K"
}
}
},
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "读取该 PDF,按页列出编号、颜色和形状,再生成一张白底参考图。"
},
{
"type": "file",
"file": {
"filename": "reference.pdf",
"file_data": "https://example.com/reference.pdf"
}
}
]
}
]
}
视频 URL(完整)
{
"model": "gemini-nano-banana-2.1",
"stream": false,
"extra_body": {
"google": {
"image_config": {
"aspect_ratio": "3:2",
"image_size": "1K"
}
}
},
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "观看视频,按场景顺序列出元素,再生成一张参考图。"
},
{
"type": "video_url",
"video_url": "https://example.com/clip.mp4"
}
]
}
]
}
curl --fail-with-body --max-time 180 \
"https://api.omniall.ai/v1/chat/completions" \
-H "Authorization: Bearer sk-xxx" \
-H "Content-Type: application/json" \
--data-binary @request.json
video_url 请用字符串,不要写成 { "url": "..." }。
可选:Thinking
香蕉 2.1 支持思考档位minimal / medium(默认)/ high。写在 extra_body.google.thinking_config(snake_case):
"extra_body": {
"google": {
"image_config": { "aspect_ratio": "3:2", "image_size": "1K" },
"thinking_config": {
"thinking_level": "high",
"include_thoughts": false
}
}
}
include_thoughts 只控制是否返回思考正文;常规接入可省略整段 thinking_config。详见 概述 · Thinking。请求头
Bearer API Key,例如 Bearer sk-...。
示例:
"Bearer sk-..."
请求体
application/json
Gemini Chat 生图请求体(POST /v1/chat/completions)。
Gemini 图像模型 ID。示例:gemini-nano-banana-2.1、gemini-3.1-flash-image-preview。
示例:
"gemini-3.1-flash-image-preview"
对话消息。文生图多为一条 user 文本;图生图在 content 中同时放文本与媒体部件。
Show child attributes
Show child attributes
是否流式返回。Chat 生图推荐 false(非流式,一次返回完整结果)。
示例:
false
提供方扩展。Gemini 配置放在 extra_body.google 下。
Show child attributes
Show child attributes
响应
Chat Completions 响应(流式为 SSE)。图像通常出现在 assistant 消息的多模态内容中。
The response is of type object.