cd /news/developer-tools/configure-litellm-as-a-gateway-for-a… · home topics developer-tools article
[ARTICLE · art-113936] src=dev.to ↗ pub= topic=developer-tools verified=true sentiment=· neutral

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.

read2 min views2 publishedAug 28, 2026

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://www.codex-docs.com/en/docs/config-file/config-advanced

── more in #developer-tools 4 stories · sorted by recency
── more on @litellm 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
Live at https://your-agent.zahid.host
Get free account → Pricing
from €0/mo · no card required
LIVE [news/configure-litellm-as…] indexed:0 read:2min 2026-08-28 ·