Generate image (GPT Image via Codex)
generate_imageGenerate or edit images and looping animated GIFs from prompts, optionally using reference images, and save results to disk.
Instructions
Generate or edit images with GPT Image through the local Codex CLI and return them inline, saved to disk. It also creates looping animated GIFs: pass the gif parameter. Pass reference_images to edit existing images or to use them as style/subject references. Set background: true to get a job id at once and keep working; the images then come from get_image_result. Takes about 30-90 seconds per image. There is no size parameter: put the aspect ratio in the prompt (for example "16:9 landscape", "square 1:1", "vertical 9:16"). The result lists each saved file path and size, the prompt that reached GPT Image, an alpha-channel check when a transparent background was requested, and the usage limits Codex reports.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"prompt": "<prompt>"
},
"name": "generate_image"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| gif | No | Create a looping animated GIF instead of a still image. Pass {} for the defaults (9 frames, 200 ms each). Keep the motion simple and describe it in the prompt. Needs Codex CLI 0.167.0-alpha.5 or newer. | |
| count | No | How many images to generate from the same prompt (1-4). Each one uses the ChatGPT image quota. Codex may return fewer; the result says so. | |
| model | No | Codex chat model that relays the request and, in enhance mode, rewrites the prompt. It does not choose the image model. Default: GPT_IMAGE_MODEL if set, otherwise the model in the user's Codex config. Call codex_status for the list. | |
| prompt | Yes | The image prompt. In prompt_mode "exact" Codex is told to send it to GPT Image unchanged, so make it complete: aspect ratio, subject, composition, style, lighting, colors, and any text that must appear (in quotes, exact spelling). Do not put file paths in it; use reference_images. | |
| background | No | Return immediately with a job id and keep generating in the background, so you can do other work. Collect the images later with get_image_result. | |
| output_path | No | Where to save: a directory, or a file path such as hero.png (the name is kept; the extension follows the format returned, normally PNG). Relative paths resolve against the project directory; ~ is expanded. Default: <project>/generated-images/. Existing files are never overwritten; a numeric suffix is added instead. | |
| prompt_mode | No | "exact" (default): Codex is told to pass the prompt to GPT Image unchanged; the result reports any difference. "enhance": the Codex model first rewrites it into a more detailed prompt, and the result shows the rewritten prompt. | exact |
| reasoning_effort | No | Reasoning effort for the Codex model, e.g. low, medium, high. Default: GPT_IMAGE_EFFORT if set; otherwise low in exact mode when the model supports it, else the Codex config default. Call codex_status for the values each model supports. | |
| reference_images | No | Local image files (PNG, JPEG, WebP or GIF, up to 16) to edit, to use as references, or to place in the result (for example a real logo). Absolute, relative to the project directory, or starting with ~. Images the user pasted or attached in the chat come with a file path ("[Image: source: <path>]"): pass that path. | |
| transparent_background | No | Ask for a transparent background (cutouts, icons, stickers). The result reports whether the PNG has an alpha channel. |