Skip to content

GPT Image 2 Official

Call GPT Image 2 through the official OpenAI native API format for an experience identical to OpenAI's image generation service.

Quick Start

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)

Endpoint

ItemValue
MethodPOST
Path/v1/images/generations
Base URLhttps://open.dieyuyun.com
ProtocolOpenAI Images API (Official)

Authentication

Bearer Token: Authorization: Bearer YOUR_API_KEY

Standard Request Fields

FieldTypeRequiredDefaultDescription
modelstringYesModel identifier: gpt-image-2-official
promptstringYesImage description text, up to 32,000 characters
sizestringNo1024x1024Image size: 1024x1024, 1536x1024 (landscape), 1024x1536 (portrait), auto
qualitystringNoautoGeneration quality: auto, low, medium, high
nintegerNo1Number of images to generate, 1–10
response_formatstringNourlResponse format: url or b64_json
backgroundstringNoautoBackground type: auto, opaque, transparent
moderationstringNoautoContent moderation level: auto, low
output_compressionintegerNoOutput image compression level, 0–100
output_formatstringNoOutput format: png, jpeg, webp

Differences from the Compatible API

GPT Image 2 Official uses the OpenAI native API format. Key differences from the compatible API (gpt-image-2):

FeatureCompatible API (gpt-image-2)Official API (gpt-image-2-official)
Protocol FormatOpenAI-compatible adaptationOpenAI native format
Async TasksSupports async pollingSynchronous response
Use CaseGeneral integrationScenarios requiring native OpenAI behavior

Request Examples

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)

Response Format

Success Response

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"
    }
  ]
}
FieldTypeDescription
createdintegerUnix timestamp
dataarrayArray of generated results
data[].urlstringImage URL (when response_format is url)
data[].b64_jsonstringBase64-encoded image data (when response_format is b64_json)
data[].revised_promptstringThe revised/optimized prompt used for generation

Error Response

See Error Codes for details.

Best Practices

  • Migration from OpenAI: If you're migrating from OpenAI, use gpt-image-2-official to ensure fully consistent API behavior.
  • Prompt optimization: GPT Image 2 automatically optimizes prompts (returned in revised_prompt), so complex manual tuning is usually unnecessary.
  • Transparent backgrounds: Supports background: "transparent" for generating images with transparent backgrounds, ideal for logos and design assets.
  • Quality tiers: Use high for commercial final output, low or medium for rapid prototyping.

Rate Limits

See Rate Limits for details.