OpenAI Codex Pricing (2026): Real Costs, Hidden Fees & How to Save

Complete Codex pricing breakdown for 2026 — task plans, API token rates, session cost estimates, and comparison vs Claude Code and Cursor. Includes cost control tips.

by AnyCap

Codex pricing dashboard — credit usage chart and plan tier comparison in dark SaaS UI

OpenAI Codex is now strictly token-based — not task-based. As of April 2026, OpenAI shifted from per-task billing to a credit system drawn down by token consumption. You pay for input tokens, output tokens, and cached context (cached inputs are discounted up to 90%). This guide breaks down every pricing tier, compares Codex against Claude Code and Cursor, and shows you how to control costs before they run away.


Quick Answer: Codex Pricing at a Glance

As of mid-2026, Codex is bundled into ChatGPT plans with a rolling 5-hour credit window:

Plan Monthly Cost Approx. Cloud Tasks / 5h Window
Free $0 Limited, lowest priority
Go $8/month Light access
Plus $20/month ~10–60 tasks
Pro 5x $100/month ~50–300 tasks
Pro 20x $200/month ~200–1,200 tasks
Business $25/user/month Team features, shared credits
Enterprise Custom Custom SLA

Note: OpenAI adjusts pricing periodically. Always check platform.openai.com/pricing for the current rate card before committing to a plan.


How Codex Billing Works (Token Credits)

As of April 2026, Codex measures usage by token credits, not tasks. Every delegation to the Codex agent consumes credits based on three variables:

  1. Input tokens — context, codebase files, and your prompt
  2. Cached input tokens — reused context from the same session, discounted up to 90%
  3. Output tokens — code, diffs, and explanations Codex writes

Typical credit cost per multi-step agent task (GPT-5.5): 5–45 credits

Keeping a session open in the same repository is significantly cheaper than starting a new one, because cached context costs only 10% of fresh input tokens.


Codex API Pricing (Token-Based)

If you're calling Codex programmatically via the OpenAI API (not the agent product), pricing is per token:

Model Input Tokens Output Tokens Context Window
gpt-4o $2.50 / 1M $10.00 / 1M 128K
gpt-4o mini $0.15 / 1M $0.60 / 1M 128K
o3 $10.00 / 1M $40.00 / 1M 200K
o4-mini $1.10 / 1M $4.40 / 1M 200K

For typical code generation tasks (read context + write output), a single exchange uses roughly 2,000–10,000 tokens. At gpt-4o pricing, that's $0.005–$0.025 per exchange.


The Codex CLI

The Codex CLI (codex command) is separate from the ChatGPT-based Codex agent. It bills against your OpenAI API account at token rates, not flat task rates.

Install

npm install -g @openai/codex
export OPENAI_API_KEY="sk-..."
codex

Cost estimate per session

A typical Codex CLI session (medium codebase, 30-minute session):

Activity Token estimate Cost (gpt-4o)
Reading 10 files × 500 lines ~15,000 input $0.04
Agent planning and reasoning ~5,000 input $0.01
Code generation (output) ~8,000 output $0.08
Test runs and fix iterations ~10,000 input + 5,000 output $0.08
Total ~38,000 tokens ~$0.21

A heavy day of Codex CLI usage (10+ sessions) costs roughly $2–5 at gpt-4o rates.


Codex vs Claude Code vs Cursor: Cost Comparison

Agent Pricing Model Typical Session Cost Best For
Codex CLI Per token (gpt-4o) $0.10–0.50 OpenAI ecosystem, Python
Claude Code Per token (Claude Sonnet) $0.15–0.45 Complex reasoning, long context
Cursor Pro $20/month flat ~$0.20–0.50 effective IDE-integrated development
Cursor Business $40/user/month ~$0.40 effective Teams, shared context

Key takeaways:

  • For pure code generation cost, Codex (gpt-4o) and Claude Code (Sonnet) are within 20% of each other per session
  • Cursor's flat monthly fee is cheaper if you use it heavily (10+ sessions/day) but more expensive for occasional use
  • Claude Code has a larger context window (200K vs 128K for gpt-4o), which matters for large codebases

What Isn't Included: The Hidden Costs

Codex (and all code agents) are text-in / text-out by default. To add media generation, web access, or cloud storage, you need additional tools. These are priced separately:

Capability Add-On Tool Cost
Image generation AnyCap 3–18 credits/image (~$0.03–0.18)
Video generation AnyCap 8–25 credits/second (~$0.08–0.25/sec)
Music generation AnyCap 15–30 credits/minute (~$0.15–0.30/min)
Web search AnyCap 1 credit/search (~$0.01)
Web crawl AnyCap 2 credits/page (~$0.02)
Cloud storage AnyCap Drive Included with AnyCap account

AnyCap new accounts start with 250 free credits. Install free →


How to Control Codex Costs

1. Use gpt-4o mini for planning, gpt-4o for execution

Route lightweight tasks (summarizing, planning, listing) to gpt-4o mini. Reserve gpt-4o or o3 for complex reasoning and generation.

# Lightweight planning task
codex --model gpt-4o-mini -p "List all files that need to be updated to add dark mode"

# Heavy execution task
codex --model gpt-4o -p "Implement dark mode across all listed files"

2. Be specific — vague prompts cost more

Vague prompt (costs more — multiple iterations):

Fix the bugs in my app

Specific prompt (costs less — fewer iterations):

The test "UserService > createUser > should hash password" is failing with
"TypeError: bcrypt.hash is not a function". Fix src/services/user.service.ts
to import bcrypt correctly and re-run the test.

3. Use CLAUDE.md / project context files

Both Codex and Claude Code support project context files. Putting permanent project info in these files means the agent doesn't have to discover it from scratch every session — fewer tokens spent on exploration.

4. Set a spending limit

In your OpenAI account dashboard, set a hard monthly spend cap. The API stops responding when you hit the cap — no surprise bills.

Set spending limits → platform.openai.com/account/limits

5. Compact context during long sessions

For Codex CLI sessions running 30+ minutes, periodically tell the agent to summarize:

Summarize what we've done so far and what's remaining. Then continue with the next step.

This resets context to a shorter summary, cutting input tokens for subsequent calls by 40–60%.


Real Cost Example: Building a Feature End-to-End

Task: Add Stripe payment integration to a Next.js app (new feature, no existing Stripe code)

Session breakdown:

Step Token cost USD (gpt-4o)
Read existing codebase (15 files) 20,000 input $0.05
Plan the integration (reasoning) 5,000 input + 3,000 output $0.04
Write 8 new files 12,000 output $0.12
Read Stripe docs via web crawl (AnyCap) 0 tokens + 2 credits $0.02
Fix 3 TypeScript errors 8,000 input + 4,000 output $0.06
Write tests 6,000 input + 5,000 output $0.07
Total ~63,000 tokens ~$0.36

A complete Stripe integration in one session for 36 cents.


FAQ

Q: Is Codex (the agent) the same as the old Codex code completion model?
A: No. The original Codex model (code-davinci-002) was deprecated in 2023. "Codex" now refers to OpenAI's agentic coding product, powered by o3 / o4-mini / gpt-4o depending on the task type.

Q: Does Codex use my code to train OpenAI's models?
A: By default, API-accessed content is not used for training under OpenAI's API terms. The ChatGPT Codex product (web interface) follows separate terms — review them at openai.com/policies.

Q: Can I use Codex for free?
A: ChatGPT Plus ($20/month) includes a limited Codex agent allowance. The Codex CLI requires an API key with pay-as-you-go billing (no free tier, but new accounts get $5 of free credits).

Q: How does Codex compare to GitHub Copilot Workspace?
A: Copilot Workspace is GitHub-integrated and charges per seat ($19–39/month). Codex CLI is standalone and charges per token — better for scripted automation, worse for interactive development. They target different workflows.

Q: What happens if my session hits a token limit?
A: The session context is truncated, which can cause the agent to "forget" earlier parts of the task. Use periodic compact/summarize prompts in long sessions to avoid this.

Q: Can I set a per-session token budget?
A: Not natively in the Codex CLI, but you can set overall account spending limits in the OpenAI dashboard. For finer control, wrap CLI calls in a script that monitors usage via the OpenAI usage API.