Configuring Third-Party Model Gateways for AI Coding Tools: Two Checks, Three Configuration Layers
This article explains why configuring a third-party model gateway for an AI coding tool can succeed or fail depending on how the editor is launched. A request must pass two independent checks that read credentials from different sources: a pre-launch admission check and the actual request process. You will learn what each check reads, a three-layer configuration strategy that separates admission from requests, a three-step verification workflow, and relevant behavior changes across adjacent versions. The guidance is based on public integration documentation and should be verified against your own environment.
1. Where the Problem Comes From: Two Configurations, Two Checks
In developer communities, Chinese-language advice on getting a GUI plugin for an AI coding tool to work with a third-party model gateway tends to split into two camps.
The first camp recommends putting the gateway URL and access token in a user-level configuration file (usually in a hidden config directory under the user’s home directory), so the CLI and the plugin share the same credentials. The second camp insists the values must go into an “environment variables” field in the editor’s own user settings; otherwise the plugin stays on the login page and never reaches the workspace.
People in both camps report success, and people in both camps report failure. The failures are usually not because a tutorial is wrong, but because it only describes one segment of the whole chain. In reality, a single request must pass two independent checks in sequence, and these checks read from different configuration sources. Covering only one of them means whether the configuration works depends on incidental factors such as launch method and shell environment. That is the root cause of “same steps, different results.”
This article first clarifies what each check reads, then presents a reusable layered configuration scheme and a three-step verification process, and finally reviews a few gateway-related behavior changes in adjacent versions. Note that the following is compiled from public integration documentation and has not been tested end to end with a real token. Verify commands and paths against your own environment before running them.
2. What Each Check Reads
The first check happens before the plugin spawns a child process. It is an admission check. The plugin first looks for credentials in its own configuration, whose source is the environment variable mapping defined in the editor’s user settings. If the editor is launched from a terminal via the CLI, the process inherits the current shell’s variables, and the admission check can also pass in that case. When this check fails, the UI stays on the login page, never enters the code editing state, and sends no model requests.
The second check happens at the actual request stage. The spawned CLI process merges two sources: the environment variables inherited from its parent process, and the env block in the user-level configuration file. If the gateway URL is not found here, the request goes to the default service address. If the URL is correct but the token is missing or invalid, authentication fails (commonly 401).
A table makes the two checks easier to compare:
| Stage | Source read | Consequence if not found |
|---|---|---|
| Plugin admission check (before launch) | Environment variable mapping in editor user settings; shell variables inherited when launched from a terminal | UI stays on the login page |
| Request process (sends the actual request) | Inherited variables + env block in the user-level config file | Request goes to the default address, or authentication fails |
This explains why both camps’ advice can “work.” Someone who only writes the user-level config file, but happens to launch the editor from a terminal with the variables already exported in the shell, passes the admission check and concludes that “the config file is enough.” Someone who launches from the Dock, the Start menu, or a desktop icon inherits no shell variables and gets stuck on the login page.
There is also a frequently overlooked detail: a GUI plugin usually bundles its own CLI runtime, and the extension’s version number is the version of that built-in runtime. Upgrading the CLI tool to the latest version in a terminal does not change the version the plugin uses. This means “I verified it works in the terminal” does not prove the plugin behaves the same way.
3. Layered Configuration: Manage Admission and Requests Separately
The recommended approach is to split configuration into three layers, each with a single responsibility, which makes troubleshooting easier.
Layer 1: the environment variable mapping in the editor’s user settings. Put only the minimal set the admission check needs: the gateway base URL and the access token. This layer is not involved in business logic; it only solves “can we get in the door.”
{"claudeCode.environmentVariables": {"ANTHROPIC_BASE_URL": "https://your-gateway.example.internal/v1","ANTHROPIC_AUTH_TOKEN": "<your-token>"}}
Layer 2: the env block in the user-level configuration file. This covers the request process under all launch methods, ensuring the process that actually sends requests gets the full set of variables whether it is launched from an icon or a terminal.
{"env": {"ANTHROPIC_BASE_URL": "https://your-gateway.example.internal/v1","ANTHROPIC_AUTH_TOKEN": "<your-token>","ANTHROPIC_MODEL": "your-model-name"}}
Layer 3: project-level configuration. Use it only when a specific repository needs a different gateway or model. It has higher priority than the user level, which avoids polluting the global environment. Make sure project-level configuration is ignored by version control so tokens do not end up in the repository.
The value of layering is that when a failure occurs, you can quickly identify which layer is missing. Stuck on the login page means the problem is in Layer 1. Reaching the UI but seeing the default address or an authentication failure means the problem is in Layer 2 or Layer 3.
4. Three-Step Verification
Step 1: verify admission. Launch the editor from the GUI and observe whether it goes straight to the workspace. If it stays on the login page, check whether the field names and JSON structure in Layer 1 are valid.
Step 2: verify the request process. Print the relevant variables in the editor’s built-in terminal to confirm the base URL and token have been injected. This step consumes no token quota; it only verifies the environment.
echo "$ANTHROPIC_BASE_URL"echo "${ANTHROPIC_AUTH_TOKEN:0:6}..."
Step 3: verify end to end. Make a minimal request (for example, ask the tool to explain a function) and observe whether it hits the custom gateway rather than the default address. If authentication fails, first check the token prefix, any extra spaces or newlines, and whether the gateway requires a specific path suffix.
Only consider upgrading or switching models after all three steps pass, so you do not mix version factors with configuration factors during troubleshooting.
5. Relevant Changes Across Versions
In adjacent versions from 2.1.323 to 2.1.327, gateway-related behavior changed in three main ways: environment variable mapping fields are parsed more strictly, so spelling mistakes are no longer silently ignored; the merge order of the env block in the user-level config file is now explicit, making the rule that project-level overrides user-level more predictable; and the difference between the plugin’s built-in runtime and the CLI version is now surfaced more clearly. If a previously working configuration stops working after an upgrade, recheck it against the layers above rather than rolling back the version.
6. Practical Recommendations
For enterprises and teams, it is advisable to bring gateway URLs and tokens into a unified secrets management and configuration distribution process instead of having each person maintain them on their own machine. In CI environments, use a separate low-privilege token, and monitor call volume and failure rates with logging and alerting. If you host a self-built gateway on a container platform, inject the token via environment variables or a secrets mount rather than baking it into the image. This satisfies compliance requirements and keeps the two checks passing reliably under any launch method.
