Use Codex with a Third-party API
Codex can connect to third-party services with an OpenAI Responses-compatible API through config.toml. Pick a provider to generate the config from the endpoint in its docs; the API key stays in an environment variable on your own machine.
By provider
These providers document their endpoint. Open one to generate the config and see what each model costs there.
Enter manually
If your provider is not listed, enter the endpoint and model name from its docs.
model_provider = "custom"
[model_providers.custom]
name = "Custom API"
base_url = "https://api.example.com/v1"
env_key = "CUSTOM_API_KEY"
wire_api = "responses"
How it works
Codex declares custom providers under model_providers in ~/.codex/config.toml: base_url is the endpoint, env_key names the environment variable that holds the key, and wire_api = "responses" makes it use the Responses API. model_provider and model then select the provider and model.
FAQ
Why is the key in an environment variable?
config.toml only holds the variable's name, so the key never goes into the config file and does not leak when you share or sync it. To keep it, add the export line to ~/.zshrc or ~/.bashrc.
How do I switch back to OpenAI?
Remove the model_provider line from config.toml, then restart Codex.
Does my key pass through this site?
No. The page only generates config text and never asks for your key; the key only goes into the terminal or environment variables on your own machine.