Skip to content

GPT Image 2 Official

通过 OpenAI 官方原生接口格式调用 GPT Image 2,获得与 OpenAI 完全一致的图像生成体验。

快速开始

python
from openai import OpenAI

client = OpenAI(
    base_url="https://open.dieyuyun.com/v1",
    api_key="YOUR_API_KEY"
)

response = client.images.generate(
    model="gpt-image-2-official",
    prompt="A watercolor painting of a Japanese garden in spring",
    size="1024x1024",
    quality="high",
    n=1
)

print(response.data[0].url)

请求端点

项目
方法POST
路径/v1/images/generations
Base URLhttps://open.dieyuyun.com
兼容协议OpenAI Images API (Official)

认证

Bearer Token: Authorization: Bearer YOUR_API_KEY

标准请求字段

字段类型必填默认值说明
modelstring模型标识: gpt-image-2-official
promptstring图像描述文本,最大 32000 字符
sizestring1024x1024图像尺寸: 1024x10241536x1024(横版)、1024x1536(竖版)、auto
qualitystringauto生成质量: autolowmediumhigh
ninteger1生成数量,1~10
response_formatstringurl返回格式: urlb64_json
backgroundstringauto背景类型: autoopaquetransparent
moderationstringauto内容审核级别: autolow
output_compressioninteger输出图片压缩比例,0~100
output_formatstring输出格式: pngjpegwebp

与兼容接口的区别

GPT Image 2 Official 使用 OpenAI 官方原生接口格式,与兼容接口(gpt-image-2)的主要区别:

特性兼容接口 (gpt-image-2)官方接口 (gpt-image-2-official)
协议格式OpenAI 兼容适配OpenAI 原生格式
异步任务支持异步轮询同步返回
适用场景通用集成需要官方原生行为的场景

请求示例

bash
curl https://open.dieyuyun.com/v1/images/generations \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-image-2-official",
    "prompt": "A watercolor painting of a Japanese garden in spring",
    "size": "1024x1024",
    "quality": "high",
    "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="gpt-image-2-official",
    prompt="A watercolor painting of a Japanese garden in spring",
    size="1024x1024",
    quality="high",
    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: 'gpt-image-2-official',
  prompt: 'A watercolor painting of a Japanese garden in spring',
  size: '1024x1024',
  quality: 'high',
  n: 1,
})

console.log(response.data[0].url)

响应格式

成功响应

json
{
  "created": 1717000000,
  "data": [
    {
      "url": "https://...",
      "revised_prompt": "A delicate watercolor painting depicting a serene Japanese garden in spring, cherry blossoms in full bloom, koi pond, stone lanterns, soft pastel colors"
    }
  ]
}
字段类型说明
createdintegerUnix 时间戳
dataarray生成结果数组
data[].urlstring图像 URL(response_formaturl 时)
data[].b64_jsonstringBase64 编码的图像数据(response_formatb64_json 时)
data[].revised_promptstring优化后的提示词

错误响应

详见 错误码

最佳实践

  • 官方接口优先: 如果您从 OpenAI 官方迁移,使用 gpt-image-2-official 可确保接口行为完全一致。
  • 提示词优化: GPT Image 2 会自动优化提示词(返回在 revised_prompt 中),无需手动进行复杂调优。
  • 透明背景: 支持 background: "transparent" 生成透明背景图片,适合 logo 和素材设计。
  • 质量档位选择: 对于商业用途的最终出图使用 high,快速原型验证使用 lowmedium

速率限制

详见 速率限制

相关文档