Generate Image
generate_imageTurn text prompts into images with OpenAI gpt-image-2 models. Saves the file locally and returns it inline for immediate review.
Instructions
Generate an image from a text prompt using OpenAI's image model family (models: "gpt-image-2.5-sunburst" (default), "gpt-image-2.5-flare", "gpt-image-2"). The image is written to disk and also returned inline so you can see it. These models handle photoreal, illustrations, infographics, multilingual text (incl. CJK), and complex structured visuals. For a transparent logo pass background="transparent" with output_format="png" — verified against this family; the origin decides, so check applied.background. Sizes accept presets or any custom "WxH" where edges are multiples of 16, max edge ≤ 3840px, aspect ratio within 1:3–3:1, and total pixels 655,360–8,294,400. Outputs above 2K are beta. Image work is slow, so this call hands off immediately: the first response carries a job_id — poll get_image_job until it reports state "completed" (the result arrives verbatim, images included). Set GPT_IMAGE_2_ASYNC_AFTER_MS to wait inline instead (below your host's tool-call timeout).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| n | No | How many images to generate (1–10). Each counts toward rate limits and cost. | |
| size | No | Output dimensions. "auto" (default), one of the presets "1024x1024", "1536x1024", "1024x1536", or a custom "WxH" where both edges are multiples of 16, max edge ≤ 3840px, aspect ratio within 1:3–3:1, and total pixels 655,360–8,294,400. Outputs above 2K are beta. | auto |
| user | No | Optional end-user identifier forwarded to OpenAI for abuse monitoring. Pass a stable hashed user ID, not PII. | |
| model | No | Model to use. One of "gpt-image-2.5-sunburst", "gpt-image-2.5-flare", "gpt-image-2"; defaults to "gpt-image-2.5-sunburst". The 2.5 variants accept the same parameters. Cost/token estimates assume gpt-image-2 pricing. | |
| prompt | Yes | Image description. gpt-image-2 handles very detailed prompts; use ALL CAPS or quote literal text you want rendered verbatim. | |
| quality | No | Generation quality. "low" for fast drafts, "medium" balanced (default when model picks), "high" for dense layouts and text, "auto" lets the model choose. | auto |
| background | No | Background behavior. "opaque" forces a filled background; "transparent" asks for alpha (PNG) — verified working for the gpt-image-2 family, and the origin still decides, so check applied.background; "auto" lets the model pick. | auto |
| moderation | No | Moderation strictness. "auto" (default) applies standard safety filtering; "low" is less restrictive (still subject to OpenAI policy). | auto |
| output_dir | No | Absolute or relative directory where generated images should be written. Defaults to $GPT_IMAGE_2_OUTPUT_DIR or a per-project subfolder under the OS config dir. The directory is created if missing. | |
| output_format | No | File format. "png" (default, lossless), "jpeg" (smaller, lossy), "webp" (best compression). When omitted on continue_edit_session, the session's current format is kept. | |
| filename_prefix | No | Short label appended to the generated filename so you can find it later (e.g. "hero-banner"). Letters/digits/hyphens only; auto-sanitized. | |
| output_compression | No | Compression level 0–100 for jpeg/webp outputs. Ignored for png. Defaults to 100 (minimal compression). |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| tool | No | ||
| model | No | ||
| notes | No | ||
| route | No | ||
| state | No | ||
| usage | No | ||
| images | No | Written image files — present once the job completed successfully. | |
| job_id | No | Present on background hand-off — pass to get_image_job. | |
| prompt | No | ||
| applied | No | ||
| poll_hint | No | ||
| requested | No | ||
| started_at | No | ||
| async_after_ms | No | ||
| prompt_preview | No | ||
| cost_usd_estimated | No |