Openrouter api support

Resolved 💬 13 comments Opened Apr 16, 2025 by Remilya Closed Aug 7, 2025

It would be awesome if we can use different api services.

View original on GitHub ↗

13 Comments

geogod42 · 1 year ago

give me a hour

DiegoSpinola · 1 year ago

you can use the env var OPENAI_BASE_URL

KorigamiK · 1 year ago
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.

DiegoSpinola · 1 year ago

So maybe adding something like this proxy to the mix:

https://github.com/open-responses/open-responses

codefromthecrypt · 1 year ago

Should we keep this titled as OpenRouter API support, or /chat/completions instead? If the latter, it basically opens up a floodgate of options.

DD1302 · 1 year ago

Is anyone still working on this? Would love to use openrouter on codex

Soren8 · 1 year ago

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

codex-maintainers · 11 months ago

Thank you for the feedback! Please try again on the latest version of Codex CLI. If the issue persists, let us know.

timqian · 10 months ago

@codex-maintainers
This feature does not work on the latest version of codex.

> sudo npm i -g @openai/codex
> codex --version
codex-cli 0.30.0

<img width="534" height="122" alt="Image" src="https://github.com/user-attachments/assets/af421ac7-fb8a-4d74-a44d-9fa405a28aae" />

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"
chongdashu · 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 ?

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

<img width="611" height="203" alt="Image" src="https://github.com/user-attachments/assets/6deadf43-3d1f-4083-aeba-e1c14842f083" />
codex-cli 0.136.0