This doesn't seem to work right now even if you set up the baseurl and model names correctly since the agent loop requests the chat completions using the new openai /v1/responses api instead of the older /v1/chat/completions api which other providers already support.
This however seems to be a deliberate way to discourage using your own models to run codex and some work on this front would be very helpful for all.
DiegoSpinola· 1 year ago
So maybe adding something like this proxy to the mix:
Found the solution, looks like the way to use other models has been changed, one needs to refer to this doc to use other models(by using config.toml): https://github.com/openai/codex/blob/main/docs/config.md This is a working config.toml to use openrouter if anyone need `` model_provider="openrouter" model="openai/gpt-5" [model_providers.openrouter] name="openrouter" base_url="https://openrouter.ai/api/v1" env_key="OPENROUTER_API_KEY" ``
This still doesn't work for me. After setting above, you you run codex -model openrouter ?
timqian· 10 months ago
> Found the solution, looks like the way to use other models has been changed, one needs to refer to this doc to use other models(by using config.toml): https://github.com/openai/codex/blob/main/docs/config.md > This is a working config.toml to use openrouter if anyone need > `` > model_provider="openrouter" > model="openai/gpt-5" > > [model_providers.openrouter] > name="openrouter" > base_url="https://openrouter.ai/api/v1" > env_key="OPENROUTER_API_KEY" > ` This still doesn't work for me. After setting above, you you run codex -model openrouter` ?
after updating the config, just run codex works for me
BTW, you will also need the OPENROUTER_API_KEY env in your .bashrc/ .zshrc
Galileo01· 1 month ago
this config.toml ,It doesn't work for me,still need login
13 Comments
give me a hour
you can use the env var OPENAI_BASE_URL
This doesn't seem to work right now even if you set up the baseurl and model names correctly since the agent loop requests the chat completions using the new openai /v1/responses api instead of the older /v1/chat/completions api which other providers already support.
This however seems to be a deliberate way to discourage using your own models to run codex and some work on this front would be very helpful for all.
So maybe adding something like this proxy to the mix:
https://github.com/open-responses/open-responses
Should we keep this titled as OpenRouter API support, or /chat/completions instead? If the latter, it basically opens up a floodgate of options.
Is anyone still working on this? Would love to use openrouter on codex
Looks like there's a fork here https://github.com/ymichael/open-codex, but most discussion about this feature is in https://github.com/openai/codex/issues/26
Thank you for the feedback! Please try again on the latest version of Codex CLI. If the issue persists, let us know.
@codex-maintainers
This feature does not work on the latest version of codex.
<img width="534" height="122" alt="Image" src="https://github.com/user-attachments/assets/af421ac7-fb8a-4d74-a44d-9fa405a28aae" />
Found the solution, looks like the way to use other models has been changed, one needs to refer to this doc to use other models(by using
config.toml): https://github.com/openai/codex/blob/main/docs/config.mdThis is a working
config.tomlto use openrouter if anyone needThis still doesn't work for me. After setting above, you you run
codex -model openrouter?after updating the config, just run
codexworks for meBTW, you will also need the OPENROUTER_API_KEY env in your .bashrc/ .zshrc
this config.toml ,It doesn't work for me,still need login
<img width="611" height="203" alt="Image" src="https://github.com/user-attachments/assets/6deadf43-3d1f-4083-aeba-e1c14842f083" />
codex-cli 0.136.0