Use GPT Image 2 in Codex, Claude Code and other coding agents
Let Codex, Claude Code or another coding agent make images with GPT Image 2 through your API key, with a reusable prompt that asks before every paid request.
Read as MarkdownA coding agent such as Codex or Claude Code can generate GPT Image 2 images by calling the API directly. Put your API key in an environment variable, give the agent the prompt below, and it will build the request, show it to you, submit it after you approve, poll the task, and save the images into your project. No plugin is required: an agent that can run a shell command or a short script can call the API.
SeedRouter does not ship an MCP server or a packaged skill. The prompt in this guide is the whole integration. You can save it as a reusable instruction in whichever agent you use.
What does the agent need before it starts?
Three things:
- An API key in the environment. Create one on the API keys page and export it in the shell the agent runs in. The agent reads it from there; it should never ask you to paste it.
- Network access. The agent calls
https://api.seedrouter.ai, so its sandbox must allow outbound requests for this task. - Credits. Requests are paid from your balance, so top up before the first run.
export SEEDROUTER_API_KEY="your-key"Which prompt should you give the agent?
Paste this at the start of the task, then fill in the bracketed goal. It lists the exact fields the API accepts, so the agent does not invent parameters, and it makes the agent stop for your approval before anything is charged:
Use the SeedRouter API to generate a gpt-image-2 image for me.
Security: read SEEDROUTER_API_KEY from my local environment. Never ask me to paste it and never expose it in code, prompts, logs, or output.
Goal:
- Use case: [product / social / concept art / UI mockup]
- Subject and style: [subject, composition, lighting, style]
- Size: [auto | 1024x1024 | 1536x1024 | 1024x1536 | WIDTHxHEIGHT]
- Quality: [auto | low | medium | high]
- Number of images: [1-10]
- Acceptance criteria: [e.g. no text in the image, consistent product, clean background]
Request fields this endpoint accepts, and nothing else:
model (required, "gpt-image-2"), prompt (required, up to 32000 chars),
n (1-10, default 1), size (default auto; a custom WIDTHxHEIGHT must have
both sides divisible by 16, neither edge over 3840, total pixels between
655360 and 8294400, and keep a ratio between
1:3 and 3:1), quality (auto|low|medium|high, default auto),
background (auto|opaque|transparent, default auto; transparent requires
output_format png), output_format (png|jpeg, default png),
output_compression (0-100, default 100, jpeg only),
moderation (auto|low, default auto), user (your own identifier).
For editing use /v1/images/generations with images: [{image_url: "https://..."}]
(up to 16) and optional mask: {image_url: "https://..."}. Mask requires images.
Inputs must be URLs, not base64 or multipart files. stream and partial_images
are not supported because delivery is asynchronous.
Before any paid request, show me the model id, the exact request body and the
estimated cost, then wait for my explicit approval.
After approval:
1. POST https://api.seedrouter.ai/v1/images/generations with the body above and
an Authorization: Bearer $SEEDROUTER_API_KEY header.
2. Save the task id from the response "id" field. The response is
{"id": "...", "status": "processing"} — the image is not in it.
3. Poll https://api.seedrouter.ai/v1/tasks/{task_id} with the same header every
5-10 seconds until status is "completed" or "failed". Do not retry forever;
if you stop waiting, preserve the task id and report that it is still pending.
A polling timeout is not a failed task. Never submit a duplicate just to check status.
4. On success, download every URL in output.data[].url, return the local paths,
the task id, and the parameters used. The response carries no cost field.
5. On failure, keep the task id, explain the reason and what to change, and do
not retry without my approval. A task that ends failed is not charged.The approval step matters most. An agent that retries on its own can submit the same paid request several times. Keep that instruction in place even once you trust the setup.
How do you use it in Codex?
Open Codex in your project and paste the prompt with your goal filled in. To reuse it, add the prompt to the project's AGENTS.md, the instruction file Codex reads for the repository, under a heading such as "Generating images". Then a request like "make a hero image for the pricing page" is enough; Codex follows the saved steps.
If Codex runs in a sandbox without network access, it cannot reach the API. Allow network access for that session before asking it to generate.
How do you use it in Claude Code?
The same prompt works in Claude Code. For reuse, save it in the project's CLAUDE.md, or as a skill: a folder with a SKILL.md file whose instructions contain the prompt. Claude Code then loads it when you ask for an image. Make sure SEEDROUTER_API_KEY is exported in the terminal you start Claude Code from.
What does a good agent run look like?
- You describe the image and where it should go.
- The agent shows the model ID, the exact request body and an estimated cost, and waits.
- You approve. The agent submits once and reports the task ID.
- It polls until the task completes, downloads the images into the project and tells you the file paths.
If a run stops partway, the task ID is still valid. Ask the agent to resume polling that ID instead of generating again; a second submission is a second charge. A task that ends failed is not charged.
Frequently asked questions
Is there a GPT Image 2 MCP server or skill from SeedRouter?
No. The API itself is the integration, and the prompt above gives an agent everything it needs to call it. Save the prompt as a skill or instruction file in your own agent if you want it reusable.
Can the agent edit existing images in my project?
Yes, if the images are reachable at public HTTPS URLs. The API takes reference images and masks as URLs, not local files, so upload them first or tell the agent where they are hosted.
Which model should the agent use?
gpt-image-2 for one flat price per delivered image, or gpt-image-2-official to pay by the tokens each render reports. Replace the model in the prompt to switch. Current prices are on the model page.
Keep the human in the loop
Give the agent the key through the environment, the fields through the prompt, and the final say through the approval step. That combination lets Codex or Claude Code produce images inside your project without surprise charges. The GPT Image 2 API reference has every field if you want to extend the prompt.



