Codex CLI Custom Provider: Use Your Own API Key
Set up a Codex CLI custom provider in config.toml: base_url, env_key, wire_api = "responses", a --profile option, a no-cost key check and error fixes.
GoiAPI · · 15 min read
Ask AI and more

A Codex CLI custom provider is a [model_providers.<id>] block in your user-level ~/.codex/config.toml that points Codex at another API: you set base_url, name the environment variable that holds your key in env_key, keep wire_api = "responses", and select it with model_provider. With GoiAPI that means base_url = "https://api.goiapi.com/v1", a key in an environment variable, and a model name such as gpt-6.1-sol. This guide gives you a working config, a --profile setup that leaves your default Codex sign-in alone, a no-charge way to test the key, and fixes for the errors people hit most.
The Codex settings below follow OpenAI's Codex configuration reference and the GoiAPI Codex CLI integration guide, both checked on December 5, 2026 (Codex CLI 0.174.0 was the latest release on npm and Homebrew that day). The parts we ran ourselves are the model-list check in step 5 and the error messages quoted from our API.
The working config.toml (copy and paste)
If you already know Codex, this is all you need. Put it in ~/.codex/config.toml (not in a project folder):
model = "gpt-6.1-sol"
model_provider = "goiapi"
[model_providers.goiapi]
name = "GoiAPI"
base_url = "https://api.goiapi.com/v1"
env_key = "GOIAPI_API_KEY"
wire_api = "responses"Then set the key and start Codex:
export GOIAPI_API_KEY="sk-..."
codexThe rest of this guide explains each line, shows the Windows commands, and covers what to check when it does not work.
Why Codex needs the Responses API
Codex CLI is OpenAI's coding agent for the terminal. You run codex inside a project folder and give it tasks in plain English: read code, edit files, run commands. By default it signs you in with your ChatGPT account. A custom provider lets it send the same requests to any other service that speaks the right API format.
That format matters. Codex talks to providers only through the Responses API (POST /v1/responses), not the older Chat Completions API (POST /v1/chat/completions) that most "OpenAI-compatible" tools use. OpenAI's configuration reference, checked on December 5, 2026, describes wire_api like this: "responses is the only supported value, and it is the default when omitted." So the service you point Codex at must implement /v1/responses. Being OpenAI-compatible in the Chat Completions sense is not enough.

GoiAPI has a Responses-compatible endpoint at POST https://api.goiapi.com/v1/responses, built for recent Codex CLI versions and for client.responses.create() in the OpenAI SDK. According to the OpenAI Responses API docs, every model on the platform can be called through it, including Claude, DeepSeek and GLM models, not only GPT. Tools such as Cline and Roo Code keep using /v1/chat/completions under the same base URL.
When a custom provider makes sense (and when it does not)
Use your own API key with Codex if:
- Your ChatGPT plan does not include Codex, or you would rather pay per token than a monthly fee.
- You want to pay with USDT (TRC20 or BEP20) or Binance Pay instead of a credit card.
- You want a separate key just for Codex, with its own daily or monthly spending limit and a list of allowed models.
- You want to try Codex with a non-OpenAI model.
Stay with the default ChatGPT sign-in if:
- Your ChatGPT plan already includes Codex and its usage limits are enough for you. It needs less setup and is supported directly by OpenAI.
- You need a data processing agreement signed directly with OpenAI.
- You rely on Responses API features GoiAPI does not support, such as OpenAI's built-in tools (web search, code interpreter) or server-stored responses. See what is not supported below.
- You want a very large catalog of models to experiment with. Large multi-model marketplaces such as OpenRouter list far more models than GoiAPI does.
Step 1: Install Codex CLI
The Codex README lists these install methods (checked on December 5, 2026):
macOS or Linux:
curl -fsSL https://chatgpt.com/codex/install.sh | shWindows (PowerShell):
powershell -ExecutionPolicy ByPass -c "irm https://chatgpt.com/codex/install.ps1 | iex"Or with a package manager:
npm install -g @openai/codex
# or
brew install --cask codexOpen a new terminal and run codex --version to confirm it is installed. Do not start codex yet. Finish steps 2 to 4 first, so the first run goes to your provider instead of asking you to sign in with ChatGPT.
Step 2: Create an API key
- Sign up for GoiAPI with email or Google and verify your email.
- In the dashboard, open Top up and pay with USDT (TRC20 or BEP20) or Binance Pay. Each top-up is 5 to 4,000 USDT, and 1 USDT adds 1 USD to your balance. Top-ups are final and non-refundable, so add only what you plan to use. Your balance must be above 0 to make calls.
- Open API Keys, create a key and copy it right away: it is shown only once. Keys look like
sk-.... - Optional but useful: name the key "codex", restrict it to the models you want Codex to use, and set a daily or monthly spending limit. See Authentication for per-key restrictions.
Step 3: Put the key in an environment variable
Codex does not read the key from config.toml. The env_key field holds only the name of an environment variable; the key itself lives in that variable. That keeps the secret out of a file you might share or commit.
macOS / Linux (add the line to ~/.zshrc or ~/.bashrc so it survives new terminals):
export GOIAPI_API_KEY="sk-..."Windows PowerShell, current session only:
$env:GOIAPI_API_KEY = "sk-..."Windows, saved for your user account (open a new terminal window afterwards, because setx does not change the window you ran it in):
setx GOIAPI_API_KEY "sk-..."The variable name is up to you. The GoiAPI docs use GATEWAY_API_KEY; any name works as long as it matches env_key.
Step 4: Add the custom provider to config.toml
Codex keeps its settings under CODEX_HOME, which defaults to ~/.codex (on Windows, the .codex folder in your user profile). Open or create ~/.codex/config.toml and add:
model = "gpt-6.1-sol"
model_provider = "goiapi"
[model_providers.goiapi]
name = "GoiAPI"
base_url = "https://api.goiapi.com/v1"
env_key = "GOIAPI_API_KEY"
wire_api = "responses"What each line does:
| Key | Value | What it means |
|---|---|---|
model | gpt-6.1-sol | The model name sent to the API. Use the exact API name from Models, not the display name. |
model_provider | goiapi | Which provider to use. It must match the part after model_providers. |
name | GoiAPI | A display name. |
base_url | https://api.goiapi.com/v1 | The API root, including /v1. Codex calls /responses under it. |
env_key | GOIAPI_API_KEY | The environment variable that holds your key. |
wire_api | responses | The protocol. responses is the only supported value and the default, so you can also leave it out. |
Two rules from OpenAI's Codex docs that trip people up:
- Do not use a reserved ID. Codex reserves
openai,ollama,lmstudio,amazon-bedrock,amazon-bedrock-runtimeandgcpfor its built-in providers. Pick your own, such asgoiapi. - Use the user-level file. Codex ignores
model_providerandmodel_providersin a project's.codex/config.tomland prints a startup warning. Provider settings only work in~/.codex/config.toml.
The provider block also accepts optional fields such as http_headers, query_params, request_max_retries (default 4), stream_max_retries (default 5) and stream_idle_timeout_ms (default 300000). You do not need any of them for GoiAPI.
Codex also has a top-level openai_base_url key that repoints its built-in openai provider. A named custom provider is cleaner: your OpenAI sign-in stays as it is, and the key comes from its own variable.
Option: use a profile and keep your default config
If you want Codex to keep using your ChatGPT sign-in by default and only use your own key sometimes, use a profile. A profile is a separate file that Codex layers on top of config.toml only when you ask for it.
Create ~/.codex/goiapi.config.toml with the same lines as above (top-level keys, no [profiles.goiapi] table), then run:
codex --profile goiapiCodex loads ~/.codex/config.toml first, then applies goiapi.config.toml on top. Runs without --profile goiapi are unchanged.
Many older guides put profiles in config.toml as [profiles.name] tables and select them with a top-level profile = "..." line. The current docs say that since Codex 0.134.0, --profile no longer reads [profiles.name] from config.toml and the profile selector is no longer supported. If a profile from an old guide seems to do nothing, this is why.
Step 5: Check the key before running Codex
List the models your key can use. Listing models is not charged.
macOS / Linux:
curl https://api.goiapi.com/v1/models -H "Authorization: Bearer $GOIAPI_API_KEY"Windows PowerShell (type curl.exe: in Windows PowerShell, curl is an alias for a different command):
curl.exe https://api.goiapi.com/v1/models -H "Authorization: Bearer $env:GOIAPI_API_KEY"If the key and URL are right, you get HTTP 200 and a list of models. When we ran this with a test key, the list included the three GPT models gpt-6-luna, gpt-6.1-sol and gpt-6.2-sol, each in this shape:
{ "id": "gpt-6.1-sol", "object": "model", "created": ..., "owned_by": ... }If the variable is not set in the terminal you are using, the request goes out without a key and you get a 401 with this message:
Missing API key. Send your key in the Authorization: Bearer <key> header or the x-api-key header.A wrong or revoked key gives 401 with The API key is invalid or has been revoked.
Step 6: Run Codex and confirm the request
Open a terminal in your project folder, run codex (or codex --profile goiapi), and give it a small task, for example "Read the README and summarize this project in three sentences." For a one-shot test without the interactive screen, codex exec runs Codex non-interactively:
codex exec "Read the README and summarize this project in three sentences"Then open Request history in the GoiAPI dashboard. Each request shows up as soon as it happens, with token counts and cost. If nothing appears, Codex is still using a different provider; see the troubleshooting section.
To switch models for one run without editing the file, use -m:
codex -m gpt-6.2-solWhich models can you use with Codex?
GoiAPI prices per 1M tokens in USD, from GoiAPI pricing, checked on December 5, 2026:
| Model | API name | Input | Output | Cache read |
|---|---|---|---|---|
| GPT-6 Luna | gpt-6-luna | $0.0208 | $0.1248 | $0.002106 |
| GPT-6.1 Sol | gpt-6.1-sol | $0.13 | $0.78 | $0.013026 |
| GPT-6.2 Sol | gpt-6.2-sol | $0.13 | $0.78 | $0.013026 |
| Claude Haiku 5.5 | claude-haiku-5-5 | $0.0221 | $0.1105 | $0.00221 |
| Claude Opus 5.5 | claude-opus-5-5 | $0.442 | $2.21 | $0.0221 |
| DeepSeek V4 Pro | deepseek-v4-pro-0813 | $0.144144 | $0.432432 | $0.014495 |
| DeepSeek V4.1 Flash | deepseek-v4.1-flash | $0.0408408 | $0.1225224 | $0.0040664 |
| GLM 5.3 | glm-5.3 | $0.144144 | $0.432432 | $0.014495 |
| GLM 5.3 Flash | glm-5.3-flash | $0.0408408 | $0.1225224 | $0.0040664 |
Codex is built and tuned around OpenAI's GPT models, so they are the natural default. The other models accept Responses API calls too (the GoiAPI Codex guide uses claude-haiku-5-5 in its example), but how well a model handles Codex's tool calls and long agent sessions varies, so try a small task first.
Input tokens are what Codex sends (your prompt, the files it reads, the running conversation); output tokens are what the model writes. You pay for the tokens each request actually uses, and each request that returns content has a small minimum charge. A failed request that returns no content is not charged, unless you cancelled it yourself. One Codex task usually sends many requests, so watch Request history for the first few tasks, or estimate a budget with the cost calculator. If tokens are new to you, what 1M tokens costs explains how they add up.
Troubleshooting Codex custom provider errors
Codex complains that wire_api "chat" is no longer supported
Your config has wire_api = "chat", usually copied from a guide written for older Codex versions. Change it to wire_api = "responses" or delete the line. GoiAPI has the /v1/responses endpoint this needs, so there is no reason to go back to chat.
Codex still asks you to sign in with ChatGPT, or says the key is missing
- Make sure
model_provideris in~/.codex/config.toml, not in a project's.codex/config.toml. Codex ignores it there and prints a warning at startup. - If you use a profile, check that you started Codex with
--profile <name>and that the profile file uses top-level keys, not a[profiles.name]table. - Check that the variable exists in the terminal running Codex:
echo $GOIAPI_API_KEYon macOS/Linux,echo $env:GOIAPI_API_KEYin PowerShell. Aftersetxon Windows, open a new terminal window. - Check that
env_keymatches the variable name exactly, including case.
Codex in Docker or CI cannot find the config
Codex reads $CODEX_HOME/config.toml, and CODEX_HOME defaults to ~/.codex for the user running it. In a container, either create the file under that user's home or set CODEX_HOME to the folder that holds your config.toml, and pass the key in as an environment variable.
HTTP errors from the API
| Code | What it means | What to do |
|---|---|---|
| 400 | The request is invalid, for example it uses a Responses feature GoiAPI does not support | Read the message; see the unsupported list below |
| 401 | Missing, wrong or revoked key | Check the environment variable; create a new key if needed; full steps in Codex 401 Unauthorized fixes |
| 402 | Not enough balance to hold funds for the request | Top up. Before each call, funds are held based on estimated input tokens plus the maximum output tokens (max_output_tokens on /v1/responses, or a default if it is not sent), so a call can be refused when your balance is close to zero even if it is above 0 |
| 403 | The key is not allowed to use this model or to call from this IP | Check the key's model and IP restrictions in the dashboard |
| 404 | Wrong model name or wrong path | Use the exact API name; make sure base_url ends in /v1 |
| 429 | Too many requests per minute, too many at once, the key's spending limit reached, or the model is overloaded | Wait the number of seconds in Retry-After, then retry. Spending-limit errors include x-should-retry: false, so retrying right away will not help |
| 500 | Internal error | Retry; if it keeps failing, send the support ID |
| 503 | Maintenance, or the model is temporarily not responding | Retry later and check the status page |
The per-minute limit is shown in the x-ratelimit-limit-requests header of non-streaming responses. Codex streams its responses, so you will not see it there; call the API once without streaming if you need to check. A test key we checked on December 3, 2026 allowed 60 requests per minute; your key may differ. Details are in Limits and balance.
The exact messages for the most common cases, from the GoiAPI error codes:
404 The model {model} does not exist. See the list at /v1/models.
404 The path {method} {path} does not exist.
403 This API key is not allowed to use the model {model}.
402 Your balance is too low for this request (about ${amount} needs to be held). Please top up your balance.If you see the "path does not exist" message, your base_url is wrong: it should be exactly https://api.goiapi.com/v1.
Every response carries an x-request-id header. If you need help, send that ID through the contact page.
What GoiAPI does not support on /v1/responses
GoiAPI does not store responses, so every call must send the whole conversation in input. Codex CLI already works this way. According to the Responses API docs, checked on December 5, 2026:
previous_response_id,conversation,prompt,background: trueanditem_referenceitems return a400error.- OpenAI's built-in tools (
web_search,file_search,local_shell,code_interpreter,computer_use,mcp,image_generation) are ignored; the model does not see them. Tools of typefunctionandcustom(such as Codex'sapply_patch) work. reasoningitems sent back ininput, andencrypted_content, are ignored.- Images or files referenced by
file_idreturn400. Send a URL or base64 data instead. - There is no
GET /v1/responses/{id}, and responses cannot be cancelled or deleted.
If an error happens after the stream has started, it arrives as a response.failed event instead of an HTTP status code.
FAQ
What is a custom provider in Codex CLI?
It is a named entry under [model_providers.<id>] in ~/.codex/config.toml that tells Codex where to send requests (base_url), which environment variable holds the key (env_key) and which protocol to use (wire_api). You switch to it with model_provider = "<id>" or through a profile.
Can I use Codex CLI with an API key instead of a ChatGPT subscription?
Yes. Either sign in to OpenAI with an API key (codex login --with-api-key reads a key from stdin), or define a custom provider whose env_key points to your key, as in this guide. The custom provider route lets you use any service that implements the Responses API.
Does Codex CLI still support wire_api = "chat"?
No. The current configuration reference says responses is the only supported value. A provider that only offers /v1/chat/completions will not work with current Codex versions.
Where is the Codex config.toml file?
In CODEX_HOME, which defaults to ~/.codex. On macOS and Linux that is /Users/<you>/.codex or /home/<you>/.codex; on Windows it is the .codex folder in your user profile. Provider settings must go in this user-level file, not in a project's .codex/config.toml.
Can I set OPENAI_BASE_URL instead of editing config.toml?
The current Codex configuration docs do not list an OPENAI_BASE_URL environment variable. To change where the built-in OpenAI provider sends requests, they point to the openai_base_url key in config.toml. A custom provider, as shown above, is the documented way to use a different API with its own key.
Can Codex CLI use Claude, DeepSeek or GLM models?
Through a provider that serves them on the Responses API, yes. On GoiAPI every listed model works on /v1/responses, so you can set model = "claude-opus-5-5" or model = "glm-5.3". Codex is designed around GPT models, so test a short task before relying on another model for long sessions. If you mainly want Claude models in an agent, Claude Code Router covers the opposite setup: Claude Code with GPT, DeepSeek and GLM.
Is my API key stored in config.toml?
No. env_key stores only the variable name. Keep the key in your shell profile or system environment, and never commit it to a repository.
Get started with Codex on GoiAPI
- Create a GoiAPI account and top up with USDT (TRC20 or BEP20) or Binance Pay. No credit card and no monthly fee; top-ups are final, so add only what you plan to use.
- Create an API key and set it as
GOIAPI_API_KEY. - Paste the provider block from step 4 into
~/.codex/config.tomlwithbase_url = "https://api.goiapi.com/v1", then runcodex.
The short version is in the Codex CLI integration guide, and the quickstart covers your first API call. Using Cursor, Cline, Roo Code or Kilo Code as well? See one API key for Cline, Roo Code, Kilo Code and Cursor.
Disclosure: GoiAPI sells access to the models named in this article.


