Skip to content

GPT Image 2

OpenAI's latest image generation model, supporting high-quality text-to-image, transparent backgrounds, and flexible image compression options.

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",
    prompt="A golden retriever on a beach at sunset, photorealistic",
    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

Authentication

Bearer Token: Authorization: Bearer YOUR_API_KEY

Standard Request Fields

FieldTypeRequiredDefaultDescription
modelstringYesModel identifier: gpt-image-2
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, only effective with b64_json
output_formatstringNoOutput format: png, jpeg, webp

Model-Specific Parameters

Transparent Background (background)

Set background to transparent to generate PNG images with a transparent background, ideal for logos, stickers, and overlays.

json
{
  "model": "gpt-image-2",
  "prompt": "A company logo of a mountain",
  "background": "transparent",
  "output_format": "png"
}

Output Compression (output_compression)

When response_format is b64_json, use output_compression to control the compression level of the output image, reducing payload size.

json
{
  "model": "gpt-image-2",
  "prompt": "A landscape painting",
  "response_format": "b64_json",
  "output_compression": 80
}

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",
    "prompt": "A golden retriever on a beach at sunset",
    "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",
    prompt="A golden retriever on a beach at sunset",
    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',
  prompt: 'A golden retriever on a beach at sunset',
  size: '1024x1024',
  quality: 'high',
  n: 1,
})

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

Transparent Background Example

bash
curl https://open.dieyuyun.com/v1/images/generations \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-image-2",
    "prompt": "A minimalist logo of a rocket",
    "size": "1024x1024",
    "background": "transparent",
    "output_format": "png",
    "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",
    prompt="A minimalist logo of a rocket",
    size="1024x1024",
    background="transparent",
    output_format="png",
    n=1
)

print(response.data[0].url)

Response Format

Success Response

json
{
  "created": 1717000000,
  "data": [
    {
      "url": "https://...",
      "revised_prompt": "A photorealistic image of a golden retriever running on a sandy beach during golden hour sunset, warm light reflecting off the ocean waves"
    }
  ]
}
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

  • Be specific in prompts: GPT Image 2 responds better to detailed descriptions. Include style, lighting, composition, and other details to significantly improve generation quality.
  • Use transparent backgrounds: When designing logos, icons, or assets that need to be composited, set background: "transparent" to skip post-processing.
  • Choose the right quality: Use low for rapid prototyping and iteration, high for final output. Use auto to let the system choose based on prompt complexity.
  • Pick the right size: Use 1536x1024 for landscape content, 1024x1536 for portrait content, and 1024x1024 for square content.
  • Batch generation: Use the n parameter to generate multiple images at once for comparison, which is more efficient than making separate requests.

Rate Limits

See Rate Limits for details.