GPT Image 2
OpenAI's latest image generation model, supporting high-quality text-to-image, transparent backgrounds, and flexible image compression options.
Try it Online
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
| Item | Value |
|---|---|
| Method | POST |
| Path | /v1/images/generations |
| Base URL | https://open.dieyuyun.com |
| Protocol | OpenAI Images API |
Authentication
Bearer Token: Authorization: Bearer YOUR_API_KEY
Standard Request Fields
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
| model | string | Yes | — | Model identifier: gpt-image-2 |
| prompt | string | Yes | — | Image description text, up to 32,000 characters |
| size | string | No | 1024x1024 | Image size: 1024x1024, 1536x1024 (landscape), 1024x1536 (portrait), auto |
| quality | string | No | auto | Generation quality: auto, low, medium, high |
| n | integer | No | 1 | Number of images to generate, 1–10 |
| response_format | string | No | url | Response format: url or b64_json |
| background | string | No | auto | Background type: auto, opaque, transparent |
| moderation | string | No | auto | Content moderation level: auto, low |
| output_compression | integer | No | — | Output image compression level, 0–100, only effective with b64_json |
| output_format | string | No | — | Output 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"
}
]
}| Field | Type | Description |
|---|---|---|
| created | integer | Unix timestamp |
| data | array | Array of generated results |
| data[].url | string | Image URL (when response_format is url) |
| data[].b64_json | string | Base64-encoded image data (when response_format is b64_json) |
| data[].revised_prompt | string | The 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
lowfor rapid prototyping and iteration,highfor final output. Useautoto let the system choose based on prompt complexity. - Pick the right size: Use
1536x1024for landscape content,1024x1536for portrait content, and1024x1024for square content. - Batch generation: Use the
nparameter to generate multiple images at once for comparison, which is more efficient than making separate requests.
Rate Limits
See Rate Limits for details.
Related Documentation
- GPT Image 2 Official - Use the official native API
- Model List & Pricing - Browse available models and pricing
- Playground - Test image generation interactively