How to Use Codex CLI with a Custom API Endpoint (OriginCoder Setup Guide)
Published 2026-11-11
Codex CLI can use a custom model provider, so it can talk to any gateway that implements the OpenAI Responses API. This guide shows how to point it at OriginCoder, the AI API gateway, with a config.toml provider block and an environment variable, or with CC-Switch one-click import. If you searched for "Codex API", this is the practical version: where the Base URL goes, which wire format to set, and where the key lives.
The Claude Code equivalent is in How to use Claude Code with a custom API endpoint. The two tools use different request formats, so their Base URL rules differ, as noted below.
What you need
- Codex CLI installed (for example
npm install -g @openai/codex; follow OpenAI's own instructions if they differ for your system). - An OriginCoder account with a balance or an active subscription. Create an account. Per-model prices are on the model pricing page.
- An API key in a group that serves OpenAI models (the OpenAI platform group). A key from a Claude-only group will not work for Codex.
Step 1: create an API key
Sign in, open API Keys in the console, create a key, and choose a group that serves OpenAI models. Copy it and treat it like a password. The group decides which models the key can call and at what rate.
Step 2, option A: one-click import with CC-Switch
CC Switch manages provider settings for Claude Code, Codex and Gemini CLI. For a key in an OpenAI group, the Import to CCS button in the console creates a Codex provider.
- Install and start CC Switch once.
- In the console, click Import to CCS on your key and confirm in the browser prompt.
- Select the new provider in CC Switch and restart Codex.
Some deployments hide the import button. If nothing happens, use option B.
Step 2, option B: config.toml and an environment variable
First, export the key. The variable name is your choice, as long as env_key below matches it:
export ORIGINCODER_API_KEY="sk-xxxx"
Then edit ~/.codex/config.toml (on Windows, %userprofile%\.codex\config.toml):
model_provider = "origincoder"
model = "a-model-from-your-group"
[model_providers.origincoder]
name = "OriginCoder"
base_url = "https://origincoder.com/v1"
env_key = "ORIGINCODER_API_KEY"
wire_api = "responses"
requires_openai_auth = false
Points that matter:
- Use
/v1inbase_url. Codex appends/responsesand does not add/v1itself. This is the opposite of Claude Code, whereANTHROPIC_BASE_URLmust not end in/v1. wire_api = "responses". Current Codex versions use the Responses API for custom providers, which is what the gateway's/v1/responsesendpoint serves.requires_openai_auth = falsetells Codex not to ask for an OpenAI sign-in for this provider.modelmust be a model your key's group serves. Pick one from the model pricing page rather than guessing.- Keep the key in an environment variable and out of files you commit. The config generated by the console's Use Key dialog may use a different variable name or embed the key; both work as long as the pieces agree. Use the dialog's output as the authority for your account's exact Base URL and values.
Codex versions change their configuration options over time. If a field is rejected, check OpenAI's current Codex documentation and the output of the console's Use Key dialog.
Step 3: verify
Start codex in a project and ask for something short. Then open Usage in the OriginCoder console: the request should appear with token counts and cost. To test the endpoint without Codex:
curl https://origincoder.com/v1/responses \
-H "Authorization: Bearer sk-xxxx" \
-H "Content-Type: application/json" \
-d '{"model": "a-model-from-your-group", "input": "ping"}'
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| 401 or "invalid API key" | Wrong key, or the environment variable is not set in this shell | echo the variable name (not its value) to check it is set, then restart the terminal |
| 404 on every request | base_url is missing /v1 or has it twice |
Use exactly https://origincoder.com/v1 |
| "model not found" or 403 | The key's group does not serve that model | Choose a listed model, or use a key from the right group |
| Codex asks you to sign in to OpenAI | requires_openai_auth is not false, or the provider is not selected |
Set model_provider to your provider's name |
| Config ignored | Wrong file location, or a TOML syntax error | Check ~/.codex/config.toml and the quotes |
| Balance errors | No balance or an expired subscription | Top up or renew in the console |
Cost and safety notes
- Each request is billed from your balance or subscription quota and recorded with tokens and cost.
- A gateway is a third party in the request path, so your code context passes through it. Read the terms first.
- OriginCoder is independent and not affiliated with OpenAI.
Next: Claude Code alternative: official subscription vs. API gateway, or what a gateway is in AI gateway explained.