#Codex contexttokens
22 messages · Page 1 of 1 (latest)
Not a dumb question at all.
For openai-codex/gpt-5.4, OpenClaw treats these separately:
- native
contextWindow:1050000 - default runtime cap
contextTokens:272000
So the thing you want to change is contextTokens, not contextWindow.
Add this to your openclaw.json:
{
models: {
providers: {
"openai-codex": {
models: [{ id: "gpt-5.4", contextTokens: 1000000 }],
},
},
},
}
A few notes:
- This works fine with Codex OAuth
- The lower default is intentional for better latency/quality
maxTokensis output cap, not context window
Docs:
If you want, paste openclaw --version and I can give you the exact openclaw config set ... command too.
2026.4.12 currently but will update today
Yep, 2026.4.12 is recent enough, so contextTokens should work.
Safest way is still editing openclaw.json and adding:
{
models: {
providers: {
"openai-codex": {
models: [{ id: "gpt-5.4", contextTokens: 1000000 }],
},
},
},
}
If you want the CLI version, and you do not already have a custom models.providers.openai-codex.models block, this should do it:
openclaw config set models.providers.openai-codex.models '[{"id":"gpt-5.4","contextTokens":1000000}]' --strict-json
A couple gotchas:
- change
contextTokens, notcontextWindow - if you already have custom
openai-codexmodel entries, merge it manually instead of replacing the whole array
Docs currently list Codex OAuth gpt-5.4 as native contextWindow: 1050000, with the lower 272000 cap being just OpenClaw’s default runtime limit:
https://docs.openclaw.ai/providers/openai
If you want, paste your current models.providers.openai-codex block and I can sanity check it before you change it.
There isn’t one right now.
models.providers.openai-codex is not present in the current config.
CLI result:
Config path not found: models.providers.openai-codex
So there is no block for me to paste.
Yep, that part is expected, config get is complaining because the path does not exist yet.
config set will create the missing block for you. So this should work:
openclaw config set models.providers.openai-codex.models '[{"id":"gpt-5.4","contextTokens":1000000}]' --strict-json
openclaw gateway restart
Then you can verify it with:
openclaw config get models.providers.openai-codex.models --json
So the short version is:
path not foundonconfig get= normal
config set= creates itgateway restart= apply it
Reference: https://docs.openclaw.ai/providers/openai
I dry-ran your exact command and it fails schema:
Error: Dry run failed: config schema validation failed.
- models.providers.openai-codex.baseUrl: expected string, received undefined
- models.providers.openai-codex.models.0.name: expected string, received undefined
So:
- that command does not apply cleanly
- I did not change config
- I did not restart the gateway
openclaw gateway restart
Important part: when I previously forced a fuller models.providers.openai-codex block to satisfy schema, it shadowed the built-in Codex OAuth provider and broke new Codex sessions.
So my recommendation is:
- do not set
models.providers.openai-codex.modelsdirectly like this - we need a safe override path for Codex runtime context that does not replace/shadow the built-in provider
Yep, you’re right, and I’m glad you caught that.
My previous models.providers.openai-codex... suggestion was wrong for this case. The schema requires a fuller provider block there, and that can shadow the built-in Codex OAuth provider.
The safe current workaround is to set the agent-level context cap instead:
openclaw config set agents.defaults.contextTokens 1000000 --strict-json
openclaw gateway restart
Why this one is safer:
- it does not replace/shadow the built-in
openai-codexprovider - code path prefers
agents.defaults.contextTokensover provider model metadata - downside: it applies to that agent generally, not just Codex
So right now the practical answer is:
- single/default agent → use
agents.defaults.contextTokens - Codex-only agent → set
contextTokenson that specific agent instead - do not use
models.providers.openai-codex.modelsfor this right now
This also looks like a docs/schema mismatch, honestly. If you want to get it fixed properly, please file it here:
https://github.com/openclaw/openclaw/issues
If you test the agents.defaults.contextTokens path, I’d love to hear whether it behaves cleanly.
Please create the issue for me to copy paste
Yep, here’s a copy-paste draft:
Title: Docs/schema mismatch for `openai-codex` `contextTokens` override, documented config path fails and can shadow built-in Codex OAuth provider
## Summary
The docs currently say that for `openai-codex/gpt-5.4`, the runtime context cap can be overridden with:
```json5
{
models: {
providers: {
"openai-codex": {
models: [{ id: "gpt-5.4", contextTokens: 160000 }],
},
},
},
}
However, on my setup this does not validate cleanly, and trying to satisfy schema by defining a fuller `models.providers.openai-codex` block appears to shadow/replace the built-in Codex OAuth provider and breaks new Codex sessions.
## Version
`openclaw --version`: 2026.4.12
## Docs that appear affected
- <https://docs.openclaw.ai/providers/openai>
- <https://docs.openclaw.ai/concepts/model-providers>
## Reproduction
1. Use OpenClaw with Codex OAuth configured (`openai-codex/gpt-5.4`).
2. Try the documented override path, for example:
```bash
openclaw config set models.providers.openai-codex.models '[{"id":"gpt-5.4","contextTokens":1000000}]' --strict-json --dry-run
- Validation fails with:
Error: Dry run failed: config schema validation failed.
- models.providers.openai-codex.baseUrl: expected string, received undefined
- models.providers.openai-codex.models.0.name: expected string, received undefined
4. If I try to force a fuller `models.providers.openai-codex` block to satisfy schema, it appears to shadow the built-in Codex OAuth provider and breaks creation of new Codex sessions.
## Expected
One of these should be true:
1. The documented `models.providers.openai-codex.models[].contextTokens` override should work safely for the built-in Codex OAuth provider, **without** requiring users to redefine/shadow the provider, or
2. The docs should point to the real safe override path.
## Actual
- The documented path fails schema validation as shown above.
- Defining a fuller custom `openai-codex` provider block is risky because it can interfere with the built-in provider behavior.
## Additional context
The docs currently describe `openai-codex/gpt-5.4` as having:
- native `contextWindow = 1050000`
- default runtime `contextTokens = 272000`
There does seem to be a safe **agent-level** workaround using `agents.defaults.contextTokens`, but that is broader than a model-specific Codex override and does not solve the documented per-provider/per-model override path.
## Suggested fix
Either:
- make `models.providers.openai-codex.models[].contextTokens` a safe overlay for the built-in provider, or
- document a different supported override path for built-in Codex OAuth models, ideally model-specific and not agent-global.