Command-line toolsOpenAI-compatible

How to use Codex CLI with a custom OpenAI-compatible endpoint

Point Codex CLI at a third-party Responses API with a model_providers entry in ~/.codex/config.toml, why OPENAI_BASE_URL stopped working, and 404/401 fixes.

Last updated:Codex CLI Official site

Copy-paste configuration

These are the three values the tool needs. Create the API key on the API Keys page of your CCSub dashboard.

base_url
https://www.ccsub.net/api/v1(must include /api/v1)
OPENAI_API_KEY
sk-your-ccsub-key
model
gpt-5.5(switch later with /model)
~/.codex/config.toml (Windows: %USERPROFILE%\.codex\config.toml)
model = "gpt-5.5"
model_provider = "ccsub"

[model_providers.ccsub]
name = "CCSub"
base_url = "https://www.ccsub.net/api/v1"
wire_api = "responses"
env_key = "OPENAI_API_KEY"

For model, use an ID such as claude-sonnet-5 — the full list of model IDs is on the models page. No key yet? Create an account first.

Steps at a glance

  1. 1

    Install Codex CLI

    With Node.js 18+ installed, run npm install -g @openai/codex@latest (use sudo on macOS/Linux if needed) and check codex --version.

  2. 2

    Create a CCSub API key

    Sign up for CCSub, open API Keys in the dashboard and create a key.

  3. 3

    Export the key

    Add export OPENAI_API_KEY="sk-your-key" to ~/.zshrc or ~/.bashrc (or set a Windows user variable) and open a new terminal.

  4. 4

    Add a provider to ~/.codex/config.toml

    Create [model_providers.ccsub] with base_url https://www.ccsub.net/api/v1, wire_api responses and env_key OPENAI_API_KEY, then set model_provider = "ccsub" at the top of the file.

  5. 5

    Run codex and verify

    Start codex in your project, send a message, and confirm the request appears on the Usage page of the CCSub dashboard.

Codex CLI is OpenAI's coding agent for the terminal. It talks to the OpenAI Responses API (POST /responses), so it uses CCSub's OpenAI-compatible base URL, https://www.ccsub.net/api/v1 — not the bare https://www.ccsub.net that Claude Code uses. Mixing the two up is the most common setup mistake.

This page covers the exact configuration. For why Codex needs a relay and what the relay must support, see Codex API relay.

Check your version first

Codex changed how custom endpoints are configured in 2026. Run codex --version:

Which method applies
0.118 and earlier
OPENAI_BASE_URLThe environment variable works (0.118 prints a deprecation warning).
0.119 and later
~/.codex/config.tomlOPENAI_BASE_URL is ignored; define a provider in the config file.

If you are unsure, use the config.toml method below — it works on both.

First, export your key as OPENAI_API_KEY:

echo 'export OPENAI_API_KEY="sk-your-key"' >> ~/.zshrc
source ~/.zshrc

On Windows, in PowerShell:

[System.Environment]::SetEnvironmentVariable('OPENAI_API_KEY', 'sk-your-key', 'User')

Then edit ~/.codex/config.toml (%USERPROFILE%\.codex\config.toml on Windows; create it if it does not exist):

model = "gpt-5.5"
model_provider = "ccsub"

[model_providers.ccsub]
name = "CCSub"
base_url = "https://www.ccsub.net/api/v1"
wire_api = "responses"
env_key = "OPENAI_API_KEY"

What each line does: base_url is the endpoint root, and Codex appends /responses. wire_api only accepts responses now — the chat value from older tutorials is a hard error. env_key names the environment variable that holds the key. Custom providers do not require an OpenAI account login by default, so the ChatGPT sign-in screen goes away.

TOML ordering matters. model and model_provider are top-level keys and must come before the first [model_providers.ccsub] header; anything below a header belongs to that table. Also, the provider ID (ccsub here) is yours to choose, except for the reserved names openai, ollama and lmstudio.

Older versions: environment variables only

On Codex 0.118 and earlier you can skip the config file and use the two variables from the CCSub install docs:

echo 'export OPENAI_BASE_URL="https://www.ccsub.net/api/v1"' >> ~/.zshrc
echo 'export OPENAI_API_KEY="sk-your-key"' >> ~/.zshrc
source ~/.zshrc

After upgrading to 0.119, OPENAI_BASE_URL is silently ignored and requests go back to OpenAI, which shows up as a login prompt or a 401. Switch to the config.toml method when that happens.

There is a third option: a top-level openai_base_url = "https://www.ccsub.net/api/v1" line, which re-points Codex's built-in openai provider. The built-in provider requires a login, so you would also run printenv OPENAI_API_KEY | codex login --with-api-key. It is more steps than a custom provider, so we do not recommend it.

Start Codex and choose a model

cd ~/your-project
codex

The model field takes IDs such as gpt-5.5; every available ID is on the models page. Change model in config.toml or use /model inside Codex. Once you have sent a message, the request should appear on the Usage page of your CCSub dashboard.

Gotchas

  • Project config does not count. A project-level .codex/config.toml ignores model_provider, model_providers and openai_base_url. Keep these in ~/.codex/config.toml.
  • Desktop launches miss shell variables. If you start a Codex desktop app or editor integration from the Dock or Start menu, it may not see the OPENAI_API_KEY you exported in your shell. Test from a terminal first.
  • Two tools, two URLs, one key. Claude Code uses https://www.ccsub.net; Codex uses https://www.ccsub.net/api/v1. The same CCSub key works for both.

If you switch providers often, CC Switch has a CCSub preset and writes the Codex config for you. For Anthropic's terminal agent, see the Claude Code guide.

Codex skills: where they go, how to install them, what to check

A skill is a folder with a SKILL.md file that holds instructions. Type $my-skill or pick it from /skills to run it; Codex also picks a skill on its own when your task matches its description. See the official Codex docs for details.

Where skills live

Where Codex looks for skills
User
~/.agents/skillsAvailable in every repository
Repository
.agents/skillsFrom where you start Codex up to the repository root
System
Bundled skill-creator and skill-installer, on by default
Plugins
/pluginsType this in Codex to install a plugin, then start a new session to use it

It's .agents, not .codex. Codex still reads ~/.codex/skills, which older guides use, but the Codex source marks it as deprecated. On Windows, the user-level folder is %USERPROFILE%\.agents\skills.

SKILL.md must include name and description:

---
name: my-skill
description: What it does and when to use it
---

Step-by-step instructions go here.

Under the Agent Skills spec, name uses only lowercase letters, digits and hyphens and matches the folder name.

Three ways to install

1. Copy the folder. Put it in one of the locations above. Codex picks it up automatically; if not, restart Codex:

mkdir -p ~/.agents/skills
cp -r ./my-skill ~/.agents/skills/

2. The built-in $skill-installer. Type it in Codex with a skill name to install from the .curated folder of openai/skills, or give it a link to a skill folder on GitHub:

$skill-installer linear
$skill-installer install https://github.com/owner/repo/tree/main/skills/my-skill

It needs the network, so in the sandbox it asks for your approval first. It installs into $CODEX_HOME/skills (~/.codex/skills by default), not ~/.agents/skills, and $skill-creator creates new skills there by default too; Codex still reads that older location. The openai/skills repository is marked deprecated, but .curated still installs; the .experimental folder is gone, so older guides that install create-plan from it no longer work.

3. The third-party npx skills tool. npx skills comes from Vercel Labs and isn't an official OpenAI tool. It needs Node.js 22.20 or later (Codex itself needs 18 or later). -a codex targets Codex; it installs into the current project's .agents/skills/ by default, or into ~/.agents/skills/ with -g. Don't pick universal: its global install goes to ~/.config/agents/skills/, which the Codex docs don't list.

# Into the current project's .agents/skills/
npx skills add owner/repo --skill my-skill -a codex

# Into ~/.agents/skills/, for every project
npx skills add owner/repo --skill my-skill -a codex -g

When a skill doesn't load

  1. Check the location. The path should look like .agents/skills/my-skill/SKILL.md; repository skills only load when Codex starts in that repository. If /skills doesn't list it, restart Codex.
  2. Check your version. Repository .agents/skills is read from 0.94.0 and ~/.agents/skills from 0.95.0; run codex --version and upgrade if you're behind.
  3. Check whether it's turned off. An [[skills.config]] entry with enabled = false in ~/.codex/config.toml disables the skills it matches. In a trusted project, enabled = false under [skills.bundled] in its .codex/config.toml turns off all system skills for that project; project config only ignores a few provider and auth keys, so this one works. Restart Codex after changing either.
  4. It never runs on its own. By default the startup skill list uses at most 2% of the context window (skills.max_context_tokens changes this, up to 10,000 tokens). With many skills, Codex shortens descriptions first, then may drop some with a warning. Lead the description with the key use case, or type $my-skill. A skill whose agents/openai.yaml sets allow_implicit_invocation: false under policy only runs when you call it.

Do you need to change anything for CCSub?

No. Skills are files Codex CLI reads from your own disk. They have nothing to do with this page's model_provider and base_url, and requests still go to https://www.ccsub.net/api/v1.

On cost: each skill's name, description and path enter the context at session start and go out with your requests; when a skill is used, Codex also reads its full SKILL.md. Those tokens are billed like any other conversation. Delete skills you don't use, or turn one off with an entry at the end of ~/.codex/config.toml, then restart:

[[skills.config]]
name = "my-skill"
enabled = false

Some plugins call a model on their own, such as claude-mem when it takes notes. In Claude Code, claude-mem needs the CCSub URL and key again in its own config files; the claude-mem guide shows how, but doesn't cover Codex.

Skill and plugin guides on this site

These use Claude Code as the main example and also cover Codex:

  • Superpowers setup guide: a skills library and development workflow, installed from /plugins in Codex CLI.
  • Taste Skill setup guide: a frontend design skill, installed in Codex with codex plugin commands.
  • Ponytail setup guide: a plugin with skills and hooks; in Codex, trust its hooks in /hooks after installing.
  • Graphify setup guide: a code knowledge graph tool; graphify install --platform codex registers a skill you call with $graphify.

How billing works

Codex is an agent: one task sends many requests, and each one carries the context and tool output so far. Cost tracks how long the task runs, not how much you type.

  • Reasoning effort: a higher model_reasoning_effort usually means more output tokens. low or medium is enough for small edits.
  • Long sessions: start a new session when you switch tasks, or run /compact, to cut the input tokens of every turn.
  • Pay-as-you-go: ¥1 buys $1 of credit that never expires. Each request is charged by its input and output tokens at the model's rate (see the models page).
  • Monthly plans: the day's quota is used first (it resets at 00:00 Beijing time), then your balance.
  • Not charged: requests that fail authentication (401) or hit an upstream 503 / 504.
  • Check it: every request's tokens and charge are listed on the Usage page in the dashboard.

Who it's for

  • Developers used to OpenAI tools who want an agent that edits code and runs commands in the terminal.
  • Codex CLI users who want to switch to pay-as-you-go API billing.
  • If you use both Claude Code and Codex, CC Switch manages both configs in one place.

Common errors and fixes

404 Not Found

Cause:The base_url path is off by a segment, e.g. /api/v1/v1 or only /api.

Fix:Set base_url to https://www.ccsub.net/api/v1. It differs from the Claude Code URL on purpose.

401 authentication_error: Missing or invalid API key

Cause:The variable named in env_key is empty, often because Codex was launched from a desktop icon that does not inherit your shell environment.

Fix:Run echo $OPENAI_API_KEY, then start codex from that same terminal.

wire_api = "chat" is no longer supported

Cause:An older guide told you to use the Chat Completions wire format, which current Codex rejects.

Fix:Use wire_api = "responses"; CCSub serves /api/v1/responses.

model / model_provider seem to be ignored

Cause:The top-level keys sit below a [table] header, so TOML treats them as fields of that table.

Fix:Move model and model_provider above the first [model_providers.*] header.

402 insufficient_balance

Cause:Your balance does not cover the estimated cost, or a monthly plan's daily quota is spent.

Fix:Top up; monthly quotas reset at 00:00 Beijing time (UTC+8) and requests then draw from your balance.

For more error messages and what they mean, see the error troubleshooting index. Installation and network issues are covered in the troubleshooting docs (Chinese).

FAQ

Why is OPENAI_BASE_URL ignored?

Codex deprecated the variable in March 2026: 0.118 still honours it with a warning, and from 0.119 it is no longer read. Run codex --version; on newer versions configure a provider in ~/.codex/config.toml instead.

Should base_url end in /v1 or /api/v1?

Use https://www.ccsub.net/api/v1, as in the CCSub docs. Codex appends /responses to it. Most 404s come from an extra or missing path segment such as /api/v1/v1 or just /api.

Codex keeps asking me to sign in with ChatGPT. Why?

It is still using the built-in openai provider. A custom provider with model_provider = "ccsub" reads the key from the env_key variable and skips the login screen.

Can I put this in a project's .codex/config.toml?

No. According to the Codex docs, model_provider, model_providers and openai_base_url are ignored in project-level config files. Use ~/.codex/config.toml.

What should the model be?

Use a model ID such as gpt-5.5; the full list is on the CCSub models page. Change model in config.toml or use /model inside Codex.

Further reading

Need a CCSub API key?

Sign up, create a key in the dashboard, and paste the values above into your tool. Pay-as-you-go balance does not expire — you only pay for the tokens you use.