OpenAI Image Format (DALL·E)
OpenAI Image Formats (Dall·E)
Section titled “OpenAI Image Formats (Dall·E)”Page Overview
Official Documentation
OpenAI Images
📝 Introduction
Section titled “📝 Introduction”Given a text prompt and/or input images, the model will generate new images. OpenAI provides a range of powerful image generation models that can create, edit, and modify images from natural language descriptions. The currently supported models include:
| Model | Description |
|---|---|
| DALL·E series | Includes DALL·E 2 and DALL·E 3, which differ significantly in image quality, creative expression, and precision |
| GPT-Image-1 | OpenAI’s latest image model, which supports multi-image editing and can create new composite images based on multiple input images |
💡 Request Examples
Section titled “💡 Request Examples”Create Images ✅
Section titled “Create Images ✅”# Basic image generationcurl https://4All API地址/v1/images/generations \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $4All API_API_KEY" \ -d '{ "model": "dall-e-3", "prompt": "A cute sea otter", "n": 1, "size": "1024x1024" }'
# High-quality image generationcurl https://4All API地址/v1/images/generations \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $4All API_API_KEY" \ -d '{ "model": "dall-e-3", "prompt": "A cute sea otter", "quality": "hd", "style": "vivid", "size": "1024x1024" }'
# Use base64 response formatcurl https://4All API地址/v1/images/generations \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $4All API_API_KEY" \ -d '{ "model": "dall-e-3", "prompt": "A cute sea otter", "response_format": "b64_json" }'Response example:
{ "created": 1589478378, "data": [ { "url": "https://...", "revised_prompt": "A cute sea otter playing in the water, with round eyes and fluffy fur" } ]}Edit Images ✅
Section titled “Edit Images ✅”curl https://4All API地址/v1/images/edits \ -H "Authorization: Bearer $4All API_API_KEY" \ -F image="@otter.png" \ -F mask="@mask.png" \ -F prompt="A cute sea otter wearing a beret" \ -F n=2 \ -F size="1024x1024"Response example:
{ "created": 1589478378, "data": [ { "url": "https://..." }, { "url": "https://..." } ]}Generate Image Variations ✅
Section titled “Generate Image Variations ✅”curl https://4All API地址/v1/images/variations \ -H "Authorization: Bearer $4All API_API_KEY" \ -F image="@otter.png" \ -F n=2 \ -F size="1024x1024"Response example:
{ "created": 1589478378, "data": [ { "url": "https://..." }, { "url": "https://..." } ]}📮 Request
Section titled “📮 Request”Endpoints
Section titled “Endpoints”Create Images
Section titled “Create Images”POST /v1/images/generationsCreate images from a text prompt.
Edit Images
Section titled “Edit Images”POST /v1/images/editsCreate edited or extended images based on an original image and a prompt.
Generate Variations
Section titled “Generate Variations”POST /v1/images/variationsCreate variations of a given image.
Authentication
Section titled “Authentication”Include the following header to authenticate with your API key:
Authorization: Bearer $4All API_API_KEYWhere $OPENAI_API_KEY is your API key.
Request Body Parameters
Section titled “Request Body Parameters”Create Images
Section titled “Create Images”prompt
Section titled “prompt”- Type: string
- Required: yes
- Description: A text description of the image you want to generate.
- dall-e-2 maximum length: 1000 characters
- dall-e-3 maximum length: 4000 characters
- Tips:
- Use specific and detailed descriptions
- Include key visual elements
- Specify the desired artistic style
- Describe composition and perspective
- Type: string
- Required: no
- Default: dall-e-2
- Description: The model used for image generation.
- Type: integer or null
- Required: no
- Default: 1
- Description: The number of images to generate. Must be between 1 and 10. dall-e-3 supports only n=1.
quality
Section titled “quality”- Type: string
- Required: no
- Default: standard
- Description: The quality of the generated image. The hd option produces more detailed and consistent images. This parameter is supported only by dall-e-3.
response_format
Section titled “response_format”- Type: string or null
- Required: no
- Default: url
- Description: The format used to return the generated image. Must be either url or b64_json. URLs are valid for 60 minutes after generation.
- Type: string or null
- Required: no
- Default: 1024x1024
- Description: The size of the generated image. dall-e-2 must be one of 256x256, 512x512, or 1024x1024. dall-e-3 must be one of 1024x1024, 1792x1024, or 1024x1792.
- Type: string or null
- Required: no
- Default: vivid
- Description: The style of the generated image. Must be either vivid or natural. vivid tends to produce surreal and dramatic images, while natural tends to produce more natural, less surreal images. This parameter is supported only by dall-e-3.
- Type: string
- Required: no
- Description: A unique identifier representing the end user, which can help OpenAI monitor and detect abuse.
Edit Images
Section titled “Edit Images”- Type: file
- Required: yes
- Description: The image to edit. Must be a valid PNG file, smaller than 4MB, and square. If no mask is provided, the image must include transparency, which will be used as the mask.
prompt
Section titled “prompt”- Type: string
- Required: yes
- Description: A text description of the image you want to generate. Maximum length: 1000 characters.
- Type: file
- Required: no
- Description: An additional image whose fully transparent regions (for example, regions with alpha equal to zero) indicate where edits should be applied. Must be a valid PNG file, smaller than 4MB, and the same dimensions as image.
Other parameters are the same as the Create Images endpoint.
Generate Variations
Section titled “Generate Variations”- Type: file
- Required: yes
- Description: The image used as the basis for variations. Must be a valid PNG file, smaller than 4MB, and square.
Other parameters are the same as the Create Images endpoint.
📥 Response¶
Section titled “📥 Response¶”Successful Response
Section titled “Successful Response”All three endpoints return a response containing a list of image objects.
created
Section titled “created”- Type: integer
- Description: The timestamp when the response was created
- Type: array
- Description: A list of generated image objects
Image Object
Section titled “Image Object”b64_json
Section titled “b64_json”- Type: string
- Description: Contains the generated image as base64-encoded JSON if response_format is b64_json
- Type: string
- Description: Contains the URL of the generated image if response_format is url (default)
revised_prompt
Section titled “revised_prompt”- Type: string
- Description: Contains the revised prompt used to generate the image if the prompt was modified in any way
Example image object:
{ "url": "https://...", "revised_prompt": "A cute sea otter playing in the water, with round eyes and fluffy fur"}🌟 Best Practices
Section titled “🌟 Best Practices”Prompt Writing Tips
Section titled “Prompt Writing Tips”- Use clear, specific descriptions
- Specify important visual details
- Describe the desired artistic style and mood
- Pay attention to composition and perspective
Parameter Selection Tips
Section titled “Parameter Selection Tips”- Model selection
- dall-e-3: Suitable for scenarios that require high quality and precise details
- dall-e-2: Suitable for rapid prototyping or simple image generation
- Size selection
- 1024x1024: The best choice for general-purpose use cases
- 1792x1024/1024x1792: Suitable for landscape/portrait scenarios
- Smaller sizes: Suitable for thumbnails or quick previews
- Quality and style
- quality=hd: For images that need fine detail
- style=vivid: Suitable for creative and artistic effects
- style=natural: Suitable for realistic scene rendering
Common Issues
Section titled “Common Issues”- Image generation failed
- Check whether the prompt complies with content policies
- Confirm file format and size limitations
- Verify API key permissions
- Results do not match expectations
- Improve the prompt description
- Adjust the quality and style parameters
- Consider using image editing or variation features