Qwen 3.8 Max in Codex CLI 2026: Config, 258K Fix, Real Cost
Yes, Codex CLI runs Qwen 3.8 Max — through a gateway using the Responses API protocol. Codex has no built-in support for the model, so it takes a custom provider declaration: six lines of TOML.
Model slug: bailian/qwen3.8-max
Wire protocol: responses
Default context: 258,400 tokens (below the model's 1M)
Measured cost: $0.08 for 3 tasks vs $0.54 on GPT-5.5 (2026-08-06)
Pricing: $2/$6 per 1M in/out, cache read $0.25/M
What Works and What Does Not
Works: the complete agent loop — reading files, applying patches via Codex's apply_patch, running Python verification, reporting results. Unlike Claude Sonnet 5 and DeepSeek, it handles Codex's freeform tool shape without rejection errors.
Does not:
- Capped at 258,400 tokens instead of the full 1M context
- Unlocking the full window replaces Codex's compiled system prompt with your own
- The
tokens useddisplay under-reports cached tokens (up to 85% of input in testing) - Separate API-key billing path from your ChatGPT subscription
How Do You Configure It?
Step 1: Install and set your key
npm i -g @openai/codex
export OFOX_API_KEY="sk-of-..."
codex --version # expect 0.146.x
Do not use codex login --with-api-key — it writes OpenAI credentials unsuitable for custom providers.
Step 2: Write the provider block
~/.codex/config.toml:
model = "bailian/qwen3.8-max"
model_provider = "ofox"
[model_providers.ofox]
name = "ofox"
base_url = "https://api.ofox.ai/v1"
env_key = "OFOX_API_KEY"
wire_api = "responses"
requires_openai_auth = false
Three fields matter: wire_api = "responses" is now mandatory ("chat" triggers a hard startup error), env_key names the environment variable Codex reads, and requires_openai_auth = false bypasses ChatGPT login.
Step 3: Run it
codex exec --sandbox workspace-write "median() is wrong for even-length input. Fix it in stats.py."
Why Does Codex Cap My Context at 258,400 Tokens?
Codex ships a compiled-in catalog covering only OpenAI models. Unknown models get fallback defaults:
grep -o '"model_context_window":[0-9]*' \
~/.codex/sessions/2026/08/06/rollout-*.jsonl | tail -1
# "model_context_window":258400
Three approaches tested on 0.146.1, only one works:
| Attempt | Warning gone? | Reported window |
|---|---|---|
| Default (no override) | No | 258,400 |
model_context_window in config.toml |
No | 258,400 |
-c model_context_window=... CLI flag |
No | 258,400 |
model_catalog_json with custom entry |
Yes | 1,131,072 |
The catalog JSON requires all 39 ModelInfo fields. One caveat worth weighing: base_instructions in that entry replaces Codex's system prompt. For sessions comfortably under 258K, skipping this step is defensible.
What Errors Will You Hit?
| Error | Real cause | Fix |
|---|---|---|
Missing bearer or basic authentication in header |
No key reached the gateway | Set the variable named in env_key
|
| 401 saying the key is invalid (works elsewhere) |
env_key missing, wrong key sent |
Add env_key to the provider block |
You didn't provide an API key |
Trailing newline in the key | Strip it |
wire_api = "chat" is no longer supported |
Deprecated before 0.146 | Set wire_api = "responses"
|
| 404 on every request | Missing /v1 on base_url |
Use https://api.ofox.ai/v1
|
Model metadata not found |
Slug outside the built-in catalog | See the 258K section |
missing field 'display_name' |
Incomplete ModelInfo entry | All 39 fields required |
What Does It Actually Cost?
Three real coding tasks, same CLI, same gateway, same repo, 2026-08-06:
| Task | Qwen 3.8 Max | GPT-5.5 | Gap |
|---|---|---|---|
Fix median() bug |
$0.0244 | $0.1223 | 5.0x |
| Add type hints and unittest coverage | $0.0373 | $0.2017 | 5.4x |
| Explain repo and flag risks | $0.0187 | $0.2146 | 11.5x |
| Total | $0.0804 | $0.5387 | 6.7x |
Is the 6.7x real? Partially. Rate-card differences justify 2.5x on input and 5x on output. The rest comes from configuration and task variance:
-
System prompt difference. GPT-5.5 gets OpenAI's full instruction set; Qwen under a custom catalog gets your one-line
base_instructions. - Turn count. Models choose their own round-trip counts. On "explain repo," GPT-5.5 took 8 API calls with 7 tool invocations; Qwen took 4 calls with 3 — that alone explains the 11.5x on that task.
Treat 6.7x as measured for this configuration on this date. 2.5x/5x is the rate-card floor.
Why is the token count in Codex lower than my bill?
The tokens used line subtracts cached input from the total. One task displayed 5,859 while the session log showed:
{"input_tokens": 37401, "cached_input_tokens": 32512,
"output_tokens": 970, "total_tokens": 38371}
38,371 − 32,512 = 5,859. Cached tokens are billed at cache-read rates, not free.
Does reasoning effort change the bill much?
Surprisingly little. Same task, same model, only model_reasoning_effort changed:
| Effort | Reasoning tokens | Total tokens | Cost |
|---|---|---|---|
| low | 200 | 26,094 | $0.0244 |
| high | 493 | 26,884 | $0.0252 |
Reasoning output tripled; the bill rose 3.3%. In agent loops, conversation replay dominates and reasoning is a thin overlay. This pattern holds for short agentic tasks — a single long reasoning-heavy request with minimal tool use reverses it.
Which Models Can Replace Qwen Here?
Not everything behind an OpenAI-compatible gateway survives Codex's Responses requirement. Six models tested on 2026-08-06:
| Model | Result in Codex |
|---|---|
bailian/qwen3.8-max |
Works, full agent loop |
openai/gpt-5.5 |
Works |
anthropic/claude-sonnet-5 |
Fails on apply_patch tool shape |
deepseek/deepseek-v4-pro |
Encrypted content is not supported |
x-ai/grok-4.3 |
Same encrypted-content failure |
z-ai/glm-5.2 |
503, no Responses support upstream |
Encrypted-content failures are unfixable — Codex hard-codes that field with no disable option.
Frequently Asked Questions
Does this affect my ChatGPT or Codex plan limits?
No. Custom providers use a separate API-key billing path, leaving weekly Codex caps untouched.
Will the 258K cap be fixed upstream?
Codex resolves metadata from a compiled catalog, so third-party slugs keep falling back until that design changes. The catalog JSON is the supported workaround today.
Is Qwen 3.8 Max worth switching to just for the price?
Rate-card advantages (2.5x input, 5x output) justify it for routine agent work. For tasks where errors cost debugging time, evaluate quality first.
Originally published on ofox.ai/blog.
Top comments (0)