Gemini 3.1 Flash Image
Google Gemini 3.1 Flash 图像生成模型,以极快的生成速度和优秀的图像质量实现高效创作。
在线体验
快速开始
python
from openai import OpenAI
client = OpenAI(
base_url="https://open.dieyuyun.com/v1",
api_key="YOUR_API_KEY"
)
response = client.images.generate(
model="gemini-3.1-flash-image",
prompt="A cozy coffee shop interior with warm lighting and bookshelves",
size="1024x1024",
n=1
)
print(response.data[0].url)请求端点
| 项目 | 值 |
|---|---|
| 方法 | POST |
| 路径 | /v1/images/generations |
| Base URL | https://open.dieyuyun.com |
| 兼容协议 | OpenAI Images API |
认证
Bearer Token: Authorization: Bearer YOUR_API_KEY
标准请求字段
| 字段 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
| model | string | 是 | — | 模型标识: gemini-3.1-flash-image |
| prompt | string | 是 | — | 图像描述文本 |
| size | string | 否 | 1024x1024 | 图像尺寸 |
| quality | string | 否 | standard | 生成质量: standard、hd |
| n | integer | 否 | 1 | 生成数量 |
| response_format | string | 否 | url | 返回格式: url 或 b64_json |
| async | boolean | 否 | false | 启用异步模式,返回 taskId 用于查询结果,详见 异步任务 |
支持的尺寸
| 尺寸 | 比例 | 说明 |
|---|---|---|
1024x1024 | 1:1 | 方形 |
1536x1024 | 3:2 | 横版 |
1024x1536 | 2:3 | 竖版 |
请求示例
bash
curl https://open.dieyuyun.com/v1/images/generations \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-3.1-flash-image",
"prompt": "A cozy coffee shop interior with warm lighting and bookshelves",
"size": "1024x1024",
"n": 1
}'python
from openai import OpenAI
client = OpenAI(
base_url="https://open.dieyuyun.com/v1",
api_key="YOUR_API_KEY"
)
response = client.images.generate(
model="gemini-3.1-flash-image",
prompt="A cozy coffee shop interior with warm lighting and bookshelves",
size="1024x1024",
n=1
)
print(response.data[0].url)javascript
import OpenAI from 'openai'
const client = new OpenAI({
baseURL: 'https://open.dieyuyun.com/v1',
apiKey: 'YOUR_API_KEY',
})
const response = await client.images.generate({
model: 'gemini-3.1-flash-image',
prompt: 'A cozy coffee shop interior with warm lighting and bookshelves',
size: '1024x1024',
n: 1,
})
console.log(response.data[0].url)异步模式
在请求中添加 "async": true 即可启用异步模式。异步请求不会直接返回生成结果,而是返回一个 taskId,用于后续查询任务进度和获取结果。
json
{
"id": "task_abc123",
"status": "queued",
"progress": 0
}| 字段 | 类型 | 说明 |
|---|---|---|
| id | string | 任务 ID,用于查询任务状态 |
| status | string | 当前状态: queued / processing |
| progress | integer | 进度百分比 (0-100) |
任务完成后,通过 GET /v1/tasks/{taskId} 获取结果,返回格式与同步响应一致。
详见 异步任务 了解完整的轮询流程和最佳实践。
响应格式
成功响应
json
{
"created": 1717000000,
"data": [
{
"url": "https://...",
"revised_prompt": "A warm and inviting coffee shop interior with exposed brick walls, wooden bookshelves filled with books, pendant lighting casting a golden glow, comfortable seating areas with leather armchairs"
}
]
}| 字段 | 类型 | 说明 |
|---|---|---|
| created | integer | Unix 时间戳 |
| data | array | 生成结果数组 |
| data[].url | string | 图像 URL |
| data[].revised_prompt | string | 优化后的提示词 |
错误响应
详见 错误码。
最佳实践
- 速度优先: Gemini Flash 系列以生成速度快著称,适合需要快速迭代和大量出图的场景。
- 详细描述: Gemini 模型对场景描述的理解能力强,提供详细的环境、光照和氛围描述可获得更好的效果。
- 多语言提示词: 支持中英文等多语言提示词,可根据需要灵活选择。
- 性价比: 在图像质量和生成速度之间取得良好平衡,适合日常图像创作需求。
- 批量创作: 利用快速生成优势,通过多次生成和
n参数快速探索不同创意方向。
速率限制
详见 速率限制。
相关文档
- GPT Image 2 - OpenAI 图像生成模型
- Grok Imagine - xAI 图像生成模型
- 模型列表与定价 - 浏览可用模型和定价信息
- 使用 Playground 测试 - 交互式测试图像生成