codex icon indicating copy to clipboard operation
codex copied to clipboard

Openrouter api support

Open Remilya opened this issue 1 year ago • 13 comments

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

Remilya avatar Apr 16 '25 17:04 Remilya

give me a hour

geogod42 avatar Apr 16 '25 17:04 geogod42

you can use the env var OPENAI_BASE_URL

DiegoSpinola avatar Apr 16 '25 18:04 DiegoSpinola

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.

KorigamiK avatar Apr 16 '25 21:04 KorigamiK

So maybe adding something like this proxy to the mix:

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

DiegoSpinola avatar Apr 16 '25 22:04 DiegoSpinola

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

codefromthecrypt avatar Apr 16 '25 23:04 codefromthecrypt

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

DD1302 avatar Apr 17 '25 19:04 DD1302

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

Soren8 avatar Apr 18 '25 02:04 Soren8

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

codex-maintainers avatar Aug 07 '25 17:08 codex-maintainers

@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
Image

timqian avatar Sep 08 '25 03:09 timqian

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"

timqian avatar Sep 08 '25 03:09 timqian

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 ?

chongdashu avatar Sep 10 '25 14:09 chongdashu

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

timqian avatar Sep 10 '25 16:09 timqian

this config.toml ,It doesn't work for me,still need login

Image codex-cli 0.136.0

Galileo01 avatar Jun 03 '26 02:06 Galileo01