DEV Community

Adela for BetterToken.ai

Posted on Edited on Originally published at bettertoken.ai

Configure Codex in VS Code with a Custom API Provider

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.

Use your own key for the custom provider. Create a BetterToken account

Verify the custom-provider values against the current Codex VS Code guide. This setup does not replace official OpenAI sign-in or change Marketplace, account, or Extension requirements.

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:

~/.codex/config.toml
Enter fullscreen mode Exit fullscreen mode

On Windows:

%USERPROFILE%\.codex\config.toml
Enter fullscreen mode Exit fullscreen mode

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

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"
Enter fullscreen mode Exit fullscreen mode

Open the user config.toml and add one provider configuration:

The exact fields, current Model ID, and authentication method are intentionally not fixed in this article because they depend on the current Extension version. Open the current BetterToken guide for Codex VS Code, then enter only the values it specifies in your user-level config.toml.

Use your own BetterToken API key and do not commit the user-level configuration, add it to a project archive, or post it in a public gist. Do not store the BetterToken API key in auth.json.

3. Do not mix two authentication modes

CLI, Desktop App, and the VS Code Extension can use different, version-dependent authentication settings. Do not copy fields from one client to another. Follow the current client-specific guides and keep only the active provider configuration they prescribe; if you inspect an existing file, never paste any token-bearing output into an issue.

4. Reload VS Code

Save the file. Open the Command Palette and run:

Developer: Reload Window
Enter fullscreen mode Exit fullscreen mode

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:

Ответь одной строкой: CODEX_PROVIDER_OK. Не изменяй файлы и не запускай команды.
Enter fullscreen mode Exit fullscreen mode

The setup is confirmed if:

  • the Extension remains officially authenticated;
  • the response arrives without 401, 403, or model not found;
  • the selected current Model ID is 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, then compare the current Extension-specific authentication settings with the current guide. Do not replace auth.json with a BetterToken key.

401 or 403

Compare only the current Extension-specific authentication settings with the current guide and re-enter them carefully. Do not publish the complete file.

Duplicate table

Do not leave duplicate active provider configurations. If you need variants, keep separate verified configurations and switch deliberately according to the current client guide.

Model not found

Use the exact current Model ID from the current guide or workspace. 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.


Originally published on the BetterToken blog.

BetterToken provides pay-as-you-go access to AI model APIs through
OpenAI-compatible and Anthropic-compatible endpoints — useful if you are wiring
Claude Code, Codex, or your own tooling to a custom base URL.
See the docs to get started.

Top comments (0)