Skip to content

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 URLhttps://open.dieyuyun.com
兼容协议OpenAI Images API

认证

Bearer Token: Authorization: Bearer YOUR_API_KEY

标准请求字段

字段类型必填默认值说明
modelstring模型标识: gemini-3.1-flash-image
promptstring图像描述文本
sizestring1024x1024图像尺寸
qualitystringstandard生成质量: standardhd
ninteger1生成数量
response_formatstringurl返回格式: urlb64_json
asyncbooleanfalse启用异步模式,返回 taskId 用于查询结果,详见 异步任务

支持的尺寸

尺寸比例说明
1024x10241:1方形
1536x10243:2横版
1024x15362: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
}
字段类型说明
idstring任务 ID,用于查询任务状态
statusstring当前状态: queued / processing
progressinteger进度百分比 (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"
    }
  ]
}
字段类型说明
createdintegerUnix 时间戳
dataarray生成结果数组
data[].urlstring图像 URL
data[].revised_promptstring优化后的提示词

错误响应

详见 错误码

最佳实践

  • 速度优先: Gemini Flash 系列以生成速度快著称,适合需要快速迭代和大量出图的场景。
  • 详细描述: Gemini 模型对场景描述的理解能力强,提供详细的环境、光照和氛围描述可获得更好的效果。
  • 多语言提示词: 支持中英文等多语言提示词,可根据需要灵活选择。
  • 性价比: 在图像质量和生成速度之间取得良好平衡,适合日常图像创作需求。
  • 批量创作: 利用快速生成优势,通过多次生成和 n 参数快速探索不同创意方向。

速率限制

详见 速率限制

相关文档