The Codex VS Code Extension reads the shared ~/.codex/config.toml and can use a custom model provider while keeping the official Extension login. This path uses OpenAI Responses, a compatible Base URL, and a separate bearer token. Reload the VS Code window and start a new session after editing the file.
Want to keep official Codex login while using your own API key? Create a BetterToken account and verify every field in the current Codex VS Code guide. This setup does not replace OpenAI login or change Marketplace, account, or regional requirements.
Before editing
Install the current official Codex VS Code Extension, finish its supported official login, create your own BetterToken API key, copy a current Model ID, and back up an existing config file.
Codex CLI, the app, and the IDE extension share the user-level configuration. The path is ~/.codex/config.toml on macOS/Linux and %USERPROFILE%\.codex\config.toml on Windows. A stale provider can affect several Codex surfaces at once.
1. Confirm official login
Open the Codex panel and complete official login before adding the custom provider. If the authentication callback fails, fix that issue with the official Codex IDE documentation first. This keeps account errors separate from API errors.
2. Add the BetterToken provider
Add one provider table to the shared file:
model_provider = "custom"
model = "YOUR_MODEL_ID"
review_model = "YOUR_MODEL_ID"
model_reasoning_effort = "high"
[model_providers.custom]
name = "BetterToken"
base_url = "https://www.bettertoken.ai/v1"
wire_api = "responses"
requires_openai_auth = true
experimental_bearer_token = "YOUR_API_KEY"
Replace both Model ID placeholders with the current exact ID and the key placeholder with your own key. Do not commit, archive, or publish this user-level file. In this Extension path, requires_openai_auth = true preserves official login, while experimental_bearer_token authenticates model requests to BetterToken. Do not write the BetterToken key to auth.json.
3. Do not mix authentication modes
A pure custom-provider CLI/App setup may use env_key and a different requires_openai_auth mode. The official-login Extension path uses the fields above. A TOML file can contain only one [model_providers.custom] table.
If the file already has provider, profile, Base URL, or environment-based settings, review them before adding another block. Duplicate or stale state can make the Extension use an unexpected model even after a successful login.
4. Reload and verify
Save the file, open the Command Palette, and run:
Developer: Reload Window
Reopen the Codex panel, create a new session, and send:
Reply with one line: CODEX_PROVIDER_OK. Do not change files or run commands.
The setup is confirmed when the Extension remains officially authenticated, the response has no 401, 403, or model error, the selected current Model ID is used, and a matching request appears in the BetterToken Dashboard.
Troubleshooting
If the Extension asks for login again, restore official login and keep the currently documented Extension authentication mode. For 401 or 403, copy the bearer token again without overwriting auth.json. For Duplicate table, keep one provider and one authentication mode. For model not found, replace both Model ID values with the current full ID. If changes are ignored, remove stale provider/profile entries deliberately, reload the window, and start a new session.
Plugin and Remote Control behavior depends on official login and the current Codex version. BetterToken covers the model API; it does not guarantee those third-party features under every condition.