Codex in VS Code in Russia: Official Sign-In and Your Own API
Keep the official Codex Extension sign-in while routing model requests through a custom Responses API provider and separate bearer token.
The Codex VS Code Extension reads the shared ~/.codex/config.toml file and can use a custom provider while retaining the Extension's official sign-in. This setup requires OpenAI Responses, a compatible Base URL, and a separate bearer token. After changing the file, reload the VS Code window and create a new session.
Want to keep the official Codex sign-in while routing model requests through your own API key? Create a BetterToken account and verify the values against the current Codex VS Code guide. This setup does not replace the official OpenAI sign-in or change regional requirements for Marketplace, the account, or the Extension.
Before you start
Prepare:
- the current Codex VS Code Extension from the official Marketplace;
- a completed official sign-in in the Extension or Codex App;
- your own BetterToken API key;
- a current Model ID from the BetterToken model plaza;
- a backup of the existing
config.toml, if it is already configured.
Codex CLI, the application, and the IDE Extension share one user-level file. An old custom provider can affect several interfaces at once. Open the file before editing and identify the sections already present.
If you have not decided where to run Codex, read the Codex CLI and Desktop App comparison first. It covers the terminal, application, VS Code, and custom-provider authentication differences separately.
Path on macOS and Linux:
On Windows:
1. Verify the official sign-in
Install the Extension, open the Codex panel, and complete the official sign-in. Do not add the custom provider before this step; otherwise, it is difficult to distinguish an account error from an API error.
After signing in, send a short request through a supported official mode. If the Extension does not open or the authentication callback does not complete, fix that first using the official Codex IDE documentation.
2. Add the BetterToken provider
Open the user config.toml and add one provider configuration:
Replace YOUR_MODEL_ID with the exact current identifier and YOUR_API_KEY with your own key. The file is under the user's .codex directory, but it still must not be committed to Git, added to a project archive, or posted in a public gist.
In this setup, requires_openai_auth = true retains the official sign-in, while experimental_bearer_token is used for BetterToken requests. Do not store the BetterToken API key in auth.json.
3. Do not mix two authentication modes
Documentation for a clean custom provider in Codex CLI/App may use env_key and a different requires_openai_auth mode. The VS Code Extension setup with an official sign-in uses the configuration above. A TOML file can contain only one table named [model_providers.custom].
The Codex CLI or Codex App guide explains the complete choice between these modes. Do not copy fields from one client to another without checking the current instructions.
If you configured the CLI before, locate duplicates:
This command prints only configuration lines. Do not paste its output into an issue if it exposes a real token.
4. Reload VS Code
Save the file. Open the Command Palette and run:
Open the Codex panel again and create a new session. An old session may retain the previous provider or model.
5. Verify the request
Open a test directory and send a request that does not change files:
The setup is confirmed if:
- the Extension remains officially authenticated;
- the response arrives without
401,403, ormodel not found; - the selected
YOUR_MODEL_IDis used; - the BetterToken Dashboard shows the corresponding request, status, and token charge.
Plugins and Remote Control depend on the official sign-in and current Codex version. BetterToken covers the model API and does not promise that these features will be available under all conditions.
Common errors
The Extension asks you to sign in again
Restore the official sign-in and confirm that requires_openai_auth = true remains set for this scheme. Do not replace auth.json with a BetterToken key.
401 or 403
Copy experimental_bearer_token again from your Workspace. Check spaces and quotation marks. Do not publish the complete file.
Duplicate table
TOML cannot declare [model_providers.custom] twice. Keep one provider and one authentication mode. If you need several variants, keep separate verified configurations and switch deliberately.
Model not found
Replace both YOUR_MODEL_ID values with the exact current ID. An old name from an article or screenshot is not a valid source.
Changes were not applied
Remove conflicting old provider/profile fields, save the file, run Developer: Reload Window, and start a new session. If the problem persists, quit VS Code completely and check the user file that the Extension actually reads.
The fields in this advanced setup may change with Codex. Before configuring it again, open the BetterToken Docs for Codex VS Code and the official Codex reference.