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.
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-official",
prompt="A watercolor painting of a Japanese garden in spring",
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 (Official) |
Authentication
Bearer Token: Authorization: Bearer YOUR_API_KEY
Standard Request Fields
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
| model | string | Yes | — | Model identifier: gpt-image-2-official |
| 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 |
| output_format | string | No | — | Output 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):
| Feature | Compatible API (gpt-image-2) | Official API (gpt-image-2-official) |
|---|---|---|
| Protocol Format | OpenAI-compatible adaptation | OpenAI native format |
| Async Tasks | Supports async polling | Synchronous response |
| Use Case | General integration | Scenarios 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"
}
]
}| 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
- Migration from OpenAI: If you're migrating from OpenAI, use
gpt-image-2-officialto 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
highfor commercial final output,lowormediumfor rapid prototyping.
Rate Limits
See Rate Limits for details.
Related Documentation
- GPT Image 2 Compatible API - Use the compatible API
- Model List & Pricing - Browse available models and pricing
- Playground - Test image generation interactively