Skip to main content
POST
Text-to-Image: generate an image from a text prompt
The interactive Playground on the right supports direct online testing. Enter your API Key in the Authorization field (format: Bearer sk-xxx), type a prompt, and click send.
Scope: This page is for text-to-image generation. Just enter a prompt — no image upload required. To edit or fuse existing images, use the Image Editing endpoint.
🖥️ Browser Playground limitation (default b64_json mode)This endpoint defaults to response_format: "b64_json", so the response carries a multi-MB base64 string and the browser Playground may show 请求时发生错误: unable to complete requestthe request actually succeeded; the browser just can’t render such a long base64 string.Recommended workflow:
  • Just want to view the image in the Playground? Pass "response_format": "url" explicitly — the response is a single R2 link and renders fine.
  • Want base64? Copy the code sample below and run it locally — the code will decode and save the image to a file automatically.
All image APIs are synchronous — there is no task ID to poll, and if your client disconnects the result is lost while the request is still billed. Set a generous timeout for this model; see Image API Essentials & Best Practices.
⚠️ Parameter Support
  • size: the field has no effect — sending auto or any concrete value does not error, but the value is silently ignored by the server. Dimensions are driven entirely by the prompt:
    • Prompt mentions a size/ratio (e.g., “Landscape 16:9”) → the model follows the prompt
    • Prompt has no size hints → the same prompt yields varied dimensions across calls, like “drawing different cards” — useful for exploring multiple compositions
    • For strict size locking, use gpt-image-2-vip (supports auto + 30 explicit sizes)
  • n / quality / aspect_ratio: ❌ rejected. Sending these may trigger parameter validation errors.
Write size and ratio directly into the prompt, e.g.:
  • Landscape 16:9 cinematic, old lighthouse by the sea at dusk
  • Portrait 9:16 phone wallpaper, cyberpunk city rainy night
  • 1024×1024 square logo, minimalist cat line art
Put size descriptions at the front of the prompt for better adherence.

Code Examples

Python

b64_json mode (returns base64 image data):

cURL

Node.js

Browser JavaScript (Fetch)

Parameters Quick Reference

Detailed parameter constraints and allowed values are shown in the right-hand Playground. The response_format field supports dropdown selection.

Response Format

data[0] returns either url or b64_json — never both (depends on response_format). This endpoint defaults to b64_json. b64_json mode (default):
url mode (requires explicit "response_format": "url", R2 CDN globally accelerated):
Compatibility note: verified July 2026 — the b64_json field is raw base64 without the data: prefix; decode it to write a file, or prepend the prefix yourself before rendering. Earlier versions did include the prefix, so always run a startsWith('data:') check first to handle both shapes.

Authorizations

Authorization
string
header
required

API Key from the API易 Console

Body

application/json
model
enum<string>
default:gpt-image-2-all
required

Model name, fixed to gpt-image-2-all

Available options:
gpt-image-2-all
prompt
string
required

Prompt. Include size/ratio/style here, e.g., Landscape 16:9 cinematic, old lighthouse at sunset

Example:

"Landscape 16:9 cinematic, old lighthouse at sunset"

response_format
enum<string>
default:b64_json

Response format. b64_json returns a base64 string already prefixed with a data URL header (default); url returns an R2 CDN link

Available options:
b64_json,
url

Response

Image successfully generated. Defaults to base64 in data[0].b64_jsonurl is not returned in the same response.

Image generation response. data[0] returns either url or b64_json, never both (depends on response_format; this endpoint defaults to b64_json).

data
object[]

Result array (this model returns 1 image per call)

created
integer

Unix timestamp (seconds)

usage
object

Token usage statistics