Running AI CLI Tools with Domestic LLM API Endpoints on Windows: Configuration Guide

    Access to overseas AI coding tools can be unstable in some network environments, and teams often need a long-term alternative. A common approach is to keep the command-line AI workflow you already use, but route model requests to an API endpoint compatible with the protocol your tool expects. This reduces workflow interruptions, provided the interface protocol is compatible and the quota and rate limits meet your actual usage. This article covers what to confirm before switching, walks through installation and environment variable setup on Windows, and provides compatibility verification and troubleshooting guidance. Actual availability depends on the provider's service and your network environment; this article makes no availability guarantees.

    Running AI CLI Tools with Domestic LLM API Endpoints on Windows: Configuration Guide

    1. Use Cases and Prerequisites for Switching

    Developers typically rely on AI tools for three kinds of work. The first is code generation, code review, and bug investigation, which depend on the model’s code understanding. The second is terminal-based workflows, such as asking questions directly in a project directory, reading context files, and executing commands—interactions that CLI tools generally preserve. The third is team management: when everyone configures their own environment, versions and API keys become inconsistent and hard to maintain centrally.

    The goal of an alternative setup is to keep these workflows intact. Since output quality varies across models, you should run a round of testing with real tasks after switching to confirm the output meets your requirements. A verification checklist is provided at the end of this article.

    2. Three Conditions to Confirm Before Switching

    1. Is the interface protocol compatible? A CLI tool sends requests according to a specific protocol. If the protocol doesn’t match the server side, environment variables will save fine, but requests will return errors. Most domestic model providers offer OpenAI-compatible endpoints, and some offer Anthropic Messages-compatible endpoints; the configuration differs between the two.

    2. Does the tool support custom endpoints? Only tools that allow a custom base URL and authentication variables can be pointed at another model service. Check the tool’s official documentation to confirm which environment variables it supports.

    3. Do quota, rate limits, and data compliance meet your needs? Code content is sent to the model service with each request. Before using a service, review its data processing terms, as well as the plan’s concurrency limits, token caps, and pricing. Code involving customer data or internal secrets should not be sent to an unevaluated service.

    The following table compares the configuration differences between the two protocols:

    Item Anthropic Messages-compatible endpoint OpenAI-compatible endpoint
    Tool requirement Tool supports ANTHROPIC_BASE_URL Tool supports OPENAI_BASE_URL, or adaptation via a middleware layer
    Common variables ANTHROPIC_BASE_URL, ANTHROPIC_AUTH_TOKEN or ANTHROPIC_API_KEY OPENAI_BASE_URL, OPENAI_API_KEY
    Request path Usually /v1/messages Usually /v1/chat/completions
    Applicable to the Windows example below Yes No—use the corresponding tool’s variables or an adapter instead

    Refer to the provider’s documentation for the exact paths and variable names.

    3. Windows Configuration Steps

    The examples in this section apply only when both conditions hold: the model provider offers an Anthropic Messages-compatible endpoint, and the CLI tool supports ANTHROPIC_BASE_URL. The example uses Claude Code (npm package @anthropic-ai/claude-code). If your provider only offers an OpenAI-compatible endpoint, do not use the variable names below.

    3.1 Check and Set the Script Execution Policy

    First, check the current policy:

    1. Get-ExecutionPolicy -List

    You only need to change it if the current user’s policy is Restricted or Undefined. Setting it to RemoteSigned affects only the current user:

    1. Set-ExecutionPolicy RemoteSigned -Scope CurrentUser -Force

    This relaxes restrictions on running local scripts, so only do it if needed. On company devices managed by Group Policy, this command may be blocked—in that case, contact your IT department and do not attempt to bypass security policies.

    3.2 Install the CLI Tool

    First confirm your Node.js version meets the tool’s official requirements. This example assumes Node.js 18 or later. Then run:

    1. npm install -g @anthropic-ai/claude-code
    2. claude --version

    If the second command prints a version number, installation succeeded. If it reports that the command is not found, continue to the next step.

    3.3 Add the npm Global Directory to the User Path

    On Windows, npm’s global command directory defaults to %APPDATA%\npm. Before modifying the Path, back up your current user Path to a file. The script below only appends the directory if it’s missing and skips empty entries, avoiding extra semicolons or duplicate paths:

    1. $npmPath = "$env:APPDATA\npm"
    2. $userPath = [Environment]::GetEnvironmentVariable("Path", "User")
    3. $backup = "$env:USERPROFILE\path-backup-$(Get-Date -Format yyyyMMdd-HHmmss).txt"
    4. $userPath | Out-File -FilePath $backup -Encoding utf8
    5. $entries = @()
    6. if ($userPath) {
    7. $entries = $userPath -split ';' | Where-Object { $_ -ne '' }
    8. }
    9. if ($entries -notcontains $npmPath) {
    10. $newPath = (@($entries) + $npmPath) -join ';'
    11. [Environment]::SetEnvironmentVariable("Path", $newPath, "User")
    12. }

    After writing the new Path, close all terminal and IDE windows and reopen them for the change to take effect.

    3.4 Set User-Level Environment Variables

    The script below reads the endpoint and API key via interactive prompts, so the key never appears in command history or script files. The variables are written to the current user’s environment, not to the $PROFILE file.

    1. # The endpoint address should follow the provider's documentation; usually the domain root, with no trailing slash
    2. $baseUrl = Read-Host "Enter the Anthropic-compatible endpoint URL provided by your vendor"
    3. [Environment]::SetEnvironmentVariable("ANTHROPIC_BASE_URL", $baseUrl, "User")
    4. # Read the API key without echoing it to the screen
    5. $secure = Read-Host "Enter your API key" -AsSecureString
    6. $plain = [System.Net.NetworkCredential]::new("", $secure).Password
    7. [Environment]::SetEnvironmentVariable("ANTHROPIC_API_KEY", $plain, "User")
    8. $plain = $null
    9. $secure = $null

    After setting the variables, restart your terminal so they are loaded, then run a simple prompt through the tool to confirm requests reach the endpoint successfully. If you get protocol or authentication errors, double-check the endpoint URL, variable names, and the provider’s documentation. Verify that the model’s output quality on your real tasks meets your team’s requirements before rolling out the setup to everyone.