How to Generate Images with Codex: The Complete 2026 Guide

Add image generation to OpenAI Codex CLI in one install. Compare 3 methods: direct API, MCP servers, or one CLI command. GPT Image 2, Seedream 5, Flux 1.1 Pro & more. Can Codex generate images? Yes — here's how.

by AnyCap

⚠️ This page has moved. The updated version of this guide is now at How to Generate Images with Codex: The Complete 2026 Guide. Please visit the new page for the most current information.


Yes — Codex can generate images. Not natively, but with a one-command CLI that plugs directly into its shell workflow.

You're building with Codex CLI. It plans the implementation, writes the code, builds the page. Then you say: "Generate a hero image for this feature."

Codex stops. Image generation isn't in its native toolkit — but adding it takes one install. The result is a full pipeline: code → image → video, all in terminal commands Codex already knows how to chain.

Here are three approaches, from manual to one-command.


Why Codex Doesn't Ship With Image Generation

Codex is OpenAI's agentic coding tool — built to plan, implement, and ship code. Image generation requires separate models (GPT Image 2, Seedream 5, Flux, Imagen 4) that run on different infrastructure, update on different cycles, and need different handling for async generation and file output.

The gap is intentional. Keep Codex focused on code. Let the capability layer handle media. The question is how cleanly that layer plugs in.


Developer at a standing desk generating product images via terminal with AnyCap

What Codex + Image Generation Unlocks

  • Hero images as part of the build. Codex implements the feature, builds the landing page, then generates the hero shot — all in one session.

  • Consistent visual assets at scale. One prompt template, multiple variants, generated in a shell loop while Codex moves to the next task.

  • Image-to-video pipeline. Generate the still with AnyCap, animate it with a second command. Codex chains them naturally.

  • UI mockups and prototypes. Explore visual concepts without leaving the terminal workflow.

  • Social content generation. Blog header, Twitter card, OG image — all generated by your agent, consistent with your brand.


Three Methods to Add Image Generation to Codex

Method 1: Wire Image APIs Directly (Manual)

Codex executes shell commands. You can configure it to call image generation APIs directly — but each model requires its own setup.

Step 1: Pick providers. GPT Image 2 (OpenAI), Imagen 4 (Google), Flux 1.1 Pro (Black Forest Labs), Seedream 5 (ByteDance). Each needs its own account.

Step 2: Get API keys. Separate developer consoles. Separate credentials. Separate billing.

Step 3: Write shell wrappers. Codex calls your scripts. Your scripts handle auth, request formatting, async polling, and file downloads. One script per model.

Step 4: Handle prompt engineering separately. Different models have different prompt dialects — what works for GPT Image 2 needs adjustment for Flux.

This works. But you're maintaining integration code instead of generating images.

Method 2: MCP Server for Image Generation

MCP servers let Codex invoke external tools through a standard protocol. Options for images:

  • Stability AI MCP — Stable Diffusion models
  • Replicate MCP — Runs hundreds of open-source image models
  • Fal.ai MCP — Fast inference for Flux, LoRA models

Configure once per server. Codex calls them like any tool. But each server covers a subset of models — mixing GPT Image 2 (OpenAI) with Flux (Replicate) still requires two separate configurations.

This is the approach where your agent calls one command regardless of which image model you want:

anycap image generate \
  --prompt "a product hero shot of a SaaS dashboard, dark theme, floating UI" \
  --model gpt-image-2 \
  -o hero.png

Change --model gpt-image-2 to --model seedream-5, --model flux-1.1-pro, or --model imagen-4 — same command, different model. Codex, Claude Code, and Cursor all call the same CLI.

What the runtime handles so your Codex agent doesn't have to:

  • Multi-model routing. One command surface reaches GPT Image 2, Seedream 5, Flux 1.1 Pro, Imagen 4, and more.
  • Authentication. One API key. The runtime manages provider credentials internally.
  • File output. Specify -o filename.png. Your agent gets a file path back, ready to embed or pass to the next command.
  • Image-to-video built in. Pass the generated image directly to anycap video generate --mode image-to-video.

Install for Codex:

npm i -g anycap
anycap login
anycap skill install --target ~/.codex/skills/anycap-cli/

After install, Codex recognizes anycap image generate as an available command. The same install also works for Claude Code and Cursor. See everything AnyCap adds to Codex.

Install AnyCap free — 250 credits for new users, no credit card required


Why Codex + AnyCap Is a Natural Fit for Image Generation

1. CLI-native design. Codex is fundamentally a CLI tool. AnyCap is also a CLI tool. anycap image generate is called the same way as npm run build or git push. No new paradigm.

2. OpenAI ecosystem alignment. GPT Image 2 is OpenAI's flagship image model. When you use AnyCap in a Codex workflow, you can stay entirely in the OpenAI ecosystem — Codex for code, GPT Image 2 for stills, Sora 2 Pro for video. But AnyCap also lets you route to Flux 1.1 Pro or Seedream 5 by changing one flag.

3. Shell command chaining. anycap image generateanycap video generateanycap drive upload is three commands in sequence. Codex already knows how to chain shell commands with &&. No new pattern to learn.


Image Generation in Codex: Generate from a Prompt

anycap image generate \
  --prompt "a clean product hero shot of a project management dashboard, dark theme, floating cards, product photography style, no people" \
  --model gpt-image-2 \
  -o dashboard-hero.png

Real Codex workflow: You've shipped a feature. Codex wrote the code and built the changelog page. Now it generates the hero image — same terminal, same session.

Model picker for Codex users:

Your Codex task Best model Speed Why it fits
Product hero, marketing GPT Image 2 ~15s (1024×1024) OpenAI-native; photorealistic with precise prompt following
Fast iteration, batch variants Seedream 5 ~8s Fast generation; consistent across a batch loop
High-detail, artistic Flux 1.1 Pro ~20s Best in class for fine detail and style control
Google ecosystem Imagen 4 ~18s GCP alignment; excellent text rendering in images
Stylized, creative Flux 1.1 Ultra ~30s Highest resolution, creative latitude

Side-by-side comparison of AI-generated product hero images in different styles

The Image-to-Video Pipeline in Codex

Codex builds the page. AnyCap generates the still. Codex animates it. All terminal commands.

# Step 1: Generate the keyframe
anycap image generate \
  --prompt "a product hero shot of a code editor, dark theme, neon green accents, product photography" \
  --model seedream-5 \
  -o codex-hero.jpg

# Step 2: Animate the still
anycap video generate \
  --prompt "gentle camera push-in, code lines highlight sequentially, subtle parallax" \
  --model veo-3.1 \
  --mode image-to-video \
  --param images=./codex-hero.jpg \
  -o codex-demo.mp4

# Step 3: Upload and share
anycap drive upload codex-demo.mp4

For a deep dive on the video step, see How to Generate Video with Codex.


The Full OpenAI-Native Image Pipeline

# 1. Research visual direction
anycap search --prompt "SaaS product hero shot styles 2026 dark theme" --citations

# 2. Generate (OpenAI-native: GPT Image 2)
anycap image generate \
  --prompt "SaaS dashboard hero, dark theme, floating cards, glassmorphism, product shot" \
  --model gpt-image-2 \
  -o hero.png

# 3. Animate (OpenAI-native: Sora 2 Pro)
anycap video generate \
  --prompt "slow push-in, cards animate into view, subtle glow pulse" \
  --model sora-2-pro \
  --mode image-to-video \
  --param images=./hero.png \
  -o hero-animated.mp4

# 4. Store
anycap drive upload hero.png hero-animated.mp4

Codex researched, generated, animated, and stored — all in one session, all OpenAI-native.

For live web research to inform your visual direction, see the Codex web search guide.


Cross-Agent: Same Command, Different Agents

Agent Skill directory Unique advantage for image generation
Codex ~/.codex/skills/ CLI-native, OpenAI ecosystem, seamless shell chaining
Claude Code ~/.claude/skills/ Subagent parallelism for generating multiple variants simultaneously
Cursor ~/.cursor/skills/ In-IDE embedding: generate, place, embed image in one agent action

Same anycap image generate command across all three. Same models. Same auth.


FAQ

Can Codex generate images natively?

No — but one install adds it. Codex is an agentic coding tool built to plan and ship code. Image generation requires separate models (GPT Image 2, Seedream 5, Flux, Imagen 4). AnyCap bundles them behind one CLI that Codex calls like any shell command.

Which image model works best with Codex?

For most Codex workflows, GPT Image 2 is the natural fit — it stays in the OpenAI ecosystem and produces photorealistic results with strong prompt following. For faster batch generation, Seedream 5 is faster and more consistent across loops. For highest-detail artistic output, Flux 1.1 Pro.

Can I generate multiple image variants in one Codex session?

Yes. Codex chains shell commands natively — loop through prompts, change the --model flag, or run parallel generation. Example: for style in product lifestyle editorial; do anycap image generate --prompt "$style shot of our dashboard" --model gpt-image-2 -o $style.png; done.

How does image generation connect to video generation in Codex?

Use --mode image-to-video in anycap video generate. Pass your generated image as --param images=./your-image.jpg. The same Codex session that generated the still can animate it. See How to Generate Video with Codex.

Do I need separate API keys for different image models?

Not with AnyCap. One key routes to GPT Image 2, Seedream 5, Flux, Imagen 4, and others. The runtime manages provider credentials internally.

Can Codex analyze images?

Via AnyCap, yes. Run anycap image analyze --input ./screenshot.png --prompt "describe the UI layout and suggest improvements" and Codex receives structured output it can act on.


The Bottom Line

Codex builds the code and the page. AnyCap generates the image in the same terminal session. The pipeline is three commands that Codex already knows how to chain.

One install. All models. No separate API keys. GPT Image 2, Seedream 5, Flux 1.1 Pro, and Imagen 4 — all behind one anycap image generate command, with 250 free credits to get started.


Give Codex image generation — install AnyCap free




Written by the AnyCap team. We build the capability runtime that gives Codex, Claude Code, and Cursor image generation through one CLI.