Gemini Image
Gemini Image 通过 OpenAI 兼容的 Chat Completions 接口调用。客户端只需要请求 Cubicspaces 的 /v1/chat/completions,把 model 设置为 Gemini 图片模型即可。
请求地址
http
POST /v1/chat/completions支持模型
| 模型 | 说明 |
|---|---|
gemini-3-pro-image-preview | Gemini 3 Pro 图片预览模型 |
gemini-3.1-flash-image-preview | Gemini 3.1 Flash 图片预览模型 |
实际可用模型以账户权限和平台配置为准。
请求示例
bash
curl https://cubicspaces.cloud/v1/chat/completions \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-3.1-flash-image-preview",
"messages": [
{
"role": "user",
"content": "生成一张猫在咖啡馆里的图片,暖色调,写实摄影风格"
}
],
"stream": false
}'响应格式
图片会返回在 OpenAI Chat Completions 响应的 choices[0].message.content 中,格式为 Markdown 图片:
json
{
"id": "chatcmpl_123",
"object": "chat.completion",
"model": "gemini-3.1-flash-image-preview",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": ""
},
"finish_reason": "stop"
}
]
}如果模型同时返回文本和图片,content 中可能同时包含说明文字和 Markdown 图片。客户端可以直接渲染 Markdown,也可以从 data:image/...;base64,... 中提取图片数据。
SDK 示例
python
from openai import OpenAI
client = OpenAI(
api_key="YOUR_API_KEY",
base_url="https://cubicspaces.cloud/v1"
)
response = client.chat.completions.create(
model="gemini-3.1-flash-image-preview",
messages=[
{"role": "user", "content": "生成一张猫在咖啡馆里的图片"}
],
stream=False
)
print(response.choices[0].message.content)js
import OpenAI from "openai";
const client = new OpenAI({
apiKey: "YOUR_API_KEY",
baseURL: "https://cubicspaces.cloud/v1"
});
const response = await client.chat.completions.create({
model: "gemini-3.1-flash-image-preview",
messages: [
{ role: "user", content: "生成一张猫在咖啡馆里的图片" }
],
stream: false
});
console.log(response.choices[0].message.content);注意事项
- 使用 OpenAI Chat Completions 格式时,不需要在请求体中传 Gemini 原生字段。
- 图片结果在
message.content内以 Markdown data URL 形式返回。 - 图片生成建议使用非流式请求,便于客户端一次性读取完整图片内容。