Configure LiteLLM as a gateway for a custom model provider for Codex A developer detailed how to configure LiteLLM as a gateway for a custom model provider in OpenAI's Codex coding agent. The setup involves setting an environment variable for the API key, adding provider-specific configurations to Codex's config.toml, and optionally setting custom HTTP headers to bypass security measures. The guide notes limitations, such as the inability to change models per session via the UI when using a custom provider. Recently, I've faced a need to use an LLM model through a gateway. In my case, it was LiteLLM. LiteLLM is an AI gateway where you can manage your LLMs setup in one place, track the costs, and enjoy observability tools. I've started investigating possible options. My go-to agent for daily coding is Codex, so I was trying to find a tool that supports custom model providers and which usability is the same or very similar to Codex. After checking OpenCode, Goose, and some other options, I wasn't happy with the UI, speed, and overall functionality. So I thought, is it possible to configure Codex the way I need? LiteLLM provides an OpenAI-compatible interface, so in theory it should be possible. Codex itself wasn't able to configure it, so here is how to do it in the old-fashioned way - manually . For Windows Powershell : Environment ::SetEnvironmentVariable "LITELLM API KEY", "sk-1234", "User" Restart the terminal session and validate with a command $env:LITELLM API KEY MacOS & Linux: export LITELLM API KEY="sk-1234" Note:The app resolves env key from its own environment. On macOS, apps launched from Finder or the Dock do not inherit variables exported in your shell profile, so LITELLM API KEY can be missing even though Codex works fine in your terminal. Either launch the app from a terminal or set the variable at the login session level and restart the app: launchctl setenv LITELLM API KEY sk-1234 Add the following configuration to the beginning of .codex/config.toml. Back up the original config just in case. Replace the existing sections and add the missing ones. Set the model and effort you like to use. The most important thing here is to set model provider. model = "gpt-5.6-sol" model provider = "litellm" model reasoning effort = "xhigh" Now add provider-specific configurations. env key should be the name of the environment variable we set in the previous step. In this case, base url points to a deployed instance of LiteLLM. If you have a local instance, then use localhost with the appropriate port number. model providers.litellm name = "litellm" base url = "https://litellm.mydomain.com/v1" env key = "LITELLM API KEY" wire api = "responses" stream idle timeout ms = 7200000 stream max retries = 5 There is a possibility to set custom HTTP headers. In my example, I need access headers to bypass Cloudflare security guards. http headers = { "CF-Access-Client-Id" = "abc", "CF-Access-Client-Secret" = "xyz" } Note:With a custom provider, there is no UI for changing the model of a session in the app see openai/codex 15364 . A session uses whatever model was set in config.toml when the session was created. To use a different LiteLLM model, update model in config.toml and start a new session. Restart the Codex and open a new chat session to make sure everything works as expected. You can verify if you're using LiteLLM as a gateway in the logs in the LiteLLM dashboard. Resources: https://docs.litellm.ai/docs/tutorials/openai codex https://docs.litellm.ai/docs/tutorials/openai codex https://www.codex-docs.com/en/docs/config-file/config-advanced https://www.codex-docs.com/en/docs/config-file/config-advanced