You point Codex at an AI API relay, ask the codex model to generate an image, and… it either throws a 502, or loops back with a paragraph that starts "Here's how I'd suggest designing it…" — but no actual image ever shows up.
Don't second-guess your config just yet. This usually isn't your fault: the relay simply never wired up the codex model's image-generation path. This guide keeps it short — first we'll get you generating images in a few minutes, then explain why most relays fail.
Get an image out first (just follow along)
One-click setup with the client (recommended)
If you'd rather not touch the command line or config files, this is the easiest route:
- Download the Teamo client
- Log in, find Codex inside the client, and click "Download & Install" (or install Codex yourself from OpenAI's site);
- Click "One-click connect" — the client automatically wires Codex up to TeamoRouter and configures everything, so the codex model just works;
- Once it's done, ask codex to generate an image — say, "a flat-style weather app icon in blue." A few seconds later, the image should appear.
You don't write a single line of config. The spots people trip over most — wire_api, the image-gen toggle — are all set for you.
Advanced: edit config.toml manually
Prefer the command line and full control? You can wire it up by hand (see the Codex setup guide for the full walkthrough).
First, set your API key as an environment variable:
export TEAMOROUTER_API_KEY="your-teamorouter-key"
Then edit ~/.codex/config.toml:
model = "gpt-5-codex" # use the exact codex model name from your dashboard
model_provider = "teamorouter"
[model_providers.teamorouter]
name = "TeamoRouter"
base_url = "https://api.teamorouter.com/v1" # confirm the exact URL on the site/dashboard
env_key = "TEAMOROUTER_API_KEY"
wire_api = "responses" # critical: image gen must go through responses, not chat
[features]
image_generation = true # enable built-in image generation
Two traps to watch for: wire_api must be responses (on chat there's no image_generation tool), and [features].image_generation needs to be true. Once set, ask codex to generate an image to confirm.
Got your image? Here's why it fails elsewhere
If you kept failing on another API relay, you probably hit one of the traps below. Anyone who's run the codex model through a relay knows the feeling — coding, chatting, and debugging all run smooth, and then image generation alone falls apart. Three classic failure modes:
- A flat 502 — the request never even lands;
- The request goes through, but the model degrades to plain text — your "image" comes back as a written description;
- The spookiest one — the logs look like it's generating,
partial_imageis even ticking along, but the final aggregated result is empty.
They look different, but the root cause is the same: the codex model's image generation doesn't go through the standard /v1/images/generations endpoint.
It goes through the built-in image_generation tool in the Responses API, which calls a gpt-image–series model (e.g. gpt-image-2) under the hood. The image data streams back over SSE as partial_image_b64 chunks, and those chunks must be aggregated correctly to reconstruct the full image. That path demands far more of a relay than plain text does. At minimum, the relay has to do three things at once:
- Fully implement the
/responsesendpoint — not just the far more common/v1/chat/completions; - Faithfully pass through the
image_generationtool call — no model swapping, no downgrading; - Correctly aggregate the streamed image chunks — don't drop the
partial_image_b64fragments.
Most relays fall down on one of these three: some only proxy the text endpoint and never implement /responses; some quietly swap codex for a cheaper substitute to cut costs, which kills the tool call outright; others implement the endpoint but write the stream aggregation sloppily, so the image is generated fine upstream yet lost at the relay layer. TeamoRouter works out of the box precisely because of this one point — it proxies that whole path completely and faithfully, without cutting corners or swapping the model, so codex image generation just works and you never have to stitch the chunks together yourself.
Still no image? Check these three things
If the image still won't come out, don't switch services yet — run through this list in order and you'll usually pin it down:
- Is
wire_apiset toresponses? The most common trap. Plenty of people copy an old config wherewire_apiis stillchat— and on that path theimage_generationtool simply doesn't exist, so codex can't generate images. (Skip this one if you used the client's one-click connect.) - Does your key have image permissions? Some relays enable only text models by default, and images need a separate request or a dashboard toggle. On TeamoRouter it's on by default; if you're using an old key from elsewhere, confirm first.
- Has codex been swapped out? If the first two are fine and text works but image generation silently fails, the upstream may have swapped codex for a cheaper model with no tool-call support. This is exactly why "is the model genuine" matters — it affects not just image generation, but whether every call you make is even hitting the real model.
FAQ
Why does Codex return a 502 — or just text — when I ask it to generate an image on a relay?
Image generation doesn't go through the regular chat endpoint; it uses the Responses API's image_generation tool. If a relay hasn't implemented /responses, swaps the model, or fails to aggregate the SSE image chunks, you'll see a 502, a plain-text "description," or an empty image.
Does Codex image generation use the /v1/images/generations endpoint?
No. It uses the built-in image_generation tool in the Responses API, backed by a gpt-image–series model. The image streams back as partial_image_b64 chunks over SSE and has to be reassembled.
What's the most overlooked config setting?
wire_api. It must be responses — on chat the image_generation tool doesn't exist, so images never generate. The client's one-click connect sets this for you.
Does my key need a separate image permission?
Some relays enable only text models by default, and images need a separate request or a dashboard toggle. On TeamoRouter it's on by default; if you're using an old key from elsewhere, confirm first.
How can I tell if the model was swapped out?
If text works fine but image generation silently fails, the upstream may have swapped codex for a cheaper model with no tool-call support. Choosing a service that keeps models genuine and un-downgraded is the most direct way to avoid this. For more on picking a trustworthy gateway, see our AI relay platform guide.
Wrapping up
If a relay's codex has ever put you through "can't generate images" hell, it's probably not your fault — the relay just didn't finish the job. Follow the steps above to get images working and save yourself the headache.
Note: TeamoRouter offers direct access from mainland China with no VPN, RMB payment (Alipay / WeChat Pay), and one entry point for Claude / GPT / Gemini alike; it works with Claude Code, Codex, Cursor, and Cline. For teams there's also high QPM, SLA, invoices, and contracts. Site teamorouter.com, client on the download page.