A Practical Guide to Connecting AI Coding Assistants with Chinese LLMs: Setup, Persistence, and Multi-Model Switching

    This guide explains how to connect AI coding assistants to leading Chinese large language models, covering environment variable setup, making configurations persistent, script-based model switching, and advanced multi-model routing. It walks through API credentials, required environment variables, shell profile persistence, lightweight switch functions, and the trade-offs of proxy-based routers, helping developers reduce cost and improve efficiency without modifying the coding tool itself.

    As large language models continue to evolve, integrating them into everyday coding tools has become an important way to boost developer productivity. However, with a wide range of models and API specifications on the market, many developers spend considerable effort on configuration and switching. This article takes a practical approach to configuring mainstream Chinese LLMs for AI coding assistants and introduces an effective multi-model management strategy, covering four areas: basic configuration, persistence, script automation, and advanced tooling.

    1. Why Chinese LLMs Are Worth Connecting

    Recently, a new generation of Chinese LLMs has shown significant performance gains in code generation, logical reasoning, and Chinese language understanding. In many everyday development tasks, their response quality and processing efficiency can now match leading international closed-source models, while their cost structure is more competitive—especially for high-frequency usage and budget-sensitive teams.

    From community activity and usage data, some Chinese models consistently rank high on general task leaderboards, reflecting their reliability and practicality in real production environments. This has led more developers to consider replacing the default model in their AI coding tools with a more cost-effective Chinese option. However, environment configuration often becomes the first obstacle during integration.

    2. Basic Setup: Configure Environment Variables in Three Steps

    Most AI coding tools are designed to be compatible with a unified API protocol. This means you can switch model providers simply by adjusting environment variables, without modifying any code in the tool itself. Using a common configuration pattern as an example, the process can be summarized in three core steps:

    Step 1: Apply for API access credentials. Go to the target model provider’s open platform, register an account, and create a dedicated API key. Note that different model types may require different permissions, so make sure the credential you apply for has access to the corresponding model.

    Step 2: Set the necessary environment variables. Using a widely adopted coding tool as an example, its runtime primarily reads the following four types of environment variables to determine how it communicates with the model:

    • ANTHROPIC_BASE_URL: Defines the request endpoint of the model service, i.e., the Base URL of the API gateway. This is the core configuration pointing to a cloud vendor’s or platform’s unified access layer. Different providers require different compliant domains.
    • ANTHROPIC_AUTH_TOKEN: The key string used for authentication, i.e., the API key applied for in the previous step. Keep it secure and never hard-code it in a repository or shared document.
    • ANTHROPIC_MODEL: Sets the default model name to invoke. The model identifier entered here must strictly match the model version on the provider’s side.
    • Three optional but recommended sub-configurations (ANTHROPIC_DEFAULT_HAIKU_MODEL, ANTHROPIC_DEFAULT_SONNET_MODEL, ANTHROPIC_DEFAULT_OPUS_MODEL): Used to override the tool’s internal strategy for assigning fast, medium, and slow models based on task complexity. It is recommended to set them all to the same model version to ensure consistent behavior.

    Step 3: Restart the tool and verify connectivity. After setting the above variables, restart the coding tool for the configuration to take effect. It is advisable to first send a simple question or code completion request and observe whether the response returns normally, confirming the connection is working.

    To illustrate further, here are complete configuration examples for two mainstream Chinese models. The first configuration targets a well-known chat and code model:

    1. export ANTHROPIC_BASE_URL=https://open.bigmodel.cn/api/anthropic
    2. export ANTHROPIC_AUTH_TOKEN=your_api_key
    3. export ANTHROPIC_MODEL=GLM-4.7
    4. export ANTHROPIC_DEFAULT_HAIKU_MODEL=GLM-4.7
    5. export ANTHROPIC_DEFAULT_SONNET_MODEL=GLM-4.7
    6. export ANTHROPIC_DEFAULT_OPUS_MODEL=GLM-4.7

    The second configuration targets another model with balanced performance on coding tasks:

    1. export ANTHROPIC_BASE_URL=https://api.moonshot.cn/anthropic
    2. export ANTHROPIC_AUTH_TOKEN=your_api_key
    3. export ANTHROPIC_MODEL=kimi-k2.5
    4. export ANTHROPIC_DEFAULT_HAIKU_MODEL=kimi-k2.5
    5. export ANTHROPIC_DEFAULT_SONNET_MODEL=kimi-k2.5
    6. export ANTHROPIC_DEFAULT_OPUS_MODEL=kimi-k2.5

    3. Persistence: Keep Configuration from Being Lost on Terminal Restart

    Executing export commands directly in a terminal session only affects the current process and its child processes. Once the terminal window is closed, all configuration is lost, and you must set it again next time—something that easily causes confusion and wasted effort in real development.

    The solution is to write the variables into your shell configuration file. Using mainstream shell environments as examples:

    • Zsh users: edit the ~/.zshrc file;
    • Bash users: edit the ~/.bashrc or ~/.bash_profile file.

    Append the export commands above to the end of the file and save it, then run source ~/.zshrc (or the corresponding file) to make the changes take effect immediately. From then on, every time you open a new terminal window, the environment variables will be loaded automatically, and the coding tool can seamlessly connect to the target model.

    Note that if multiple sets of model variable definitions with the same variable names exist in the same shell configuration file, the later definitions will override the earlier ones. Therefore, make sure only one active configuration set is retained at any given time.

    4. Script-Based Switching: Say Goodbye to Frequent Manual Edits

    However, a single fixed configuration cannot satisfy diverse task requirements. For example, when dealing with logic-heavy tasks like code refactoring and architecture design, developers may prefer a specific model; when handling repetitive text generation, they may want to switch to a lower-cost model. If each switch requires manually editing the configuration file and running source, the experience suffers significantly.

    A lightweight automation approach is to write a shell switching function. Add the following function definition to your configuration file:

    1. function switch_model() {
    2. case "$1" in
    3. glm)
    4. export ANTHROPIC_BASE_URL="https://open.bigmodel.cn/api/anthropic"
    5. export ANTHROPIC_AUTH_TOKEN="your_glm_key"
    6. export ANTHROPIC_MODEL="GLM-4.7"
    7. ;;
    8. kimi)
    9. export ANTHROPIC_BASE_URL="https://api.moonshot.cn/anthropic"
    10. export ANTHROPIC_AUTH_TOKEN="your_kimi_key"
    11. export ANTHROPIC_MODEL="kimi-k2.5"
    12. ;;
    13. *)
    14. echo "Unknown model identifier: $1"
    15. return 1
    16. ;;
    17. esac
    18. echo "Switched to model: $1"
    19. }

    Afterward, simply run switch_model glm or switch_model kimi in the terminal to complete a model switch within a second—no file reloading or tool restart required. This approach is lightweight, transparent, and has zero external dependencies, making it suitable for single-machine development environments.

    5. Advanced Management: The Value and Limitations of Multi-Model Routing Tools

    For developers who frequently switch between multiple models and have extremely high requirements for switching efficiency, a common category of multi-model routing management solutions can be used. These solutions are essentially a local proxy process that listens on a fixed port, intercepts API requests from the coding tool, and routes them to different backend model providers based on preset policies.

    The core value of such tools includes:

    1. Decoupling configuration from usage: The coding tool only needs to be configured with one fixed address (i.e., the local proxy port). All model differences are hidden behind the proxy layer, so switching models requires no changes to the tool configuration.
    2. Support for dynamic policies: Allows defining routing rules through interactive commands or configuration files, such as dynamically selecting backend models by task type, model name, or request context.
    3. Centralized key management: All provider API keys only need to be stored in the proxy tool’s configuration, reducing the risk of scattered keys and leaks.

    However, introducing such solutions comes with trade-offs. First, the intermediate proxy layer adds extra network overhead and potential latency. Second, when a provider changes its API specification, the proxy tool must be updated promptly, or compatibility issues may occur. Third, the stability and security of the tool depend on the activity of community maintenance. Therefore, developers should carefully evaluate whether to introduce this extra component based on their usage frequency, concurrency level, and sensitivity to latency.

    6. Summary and Best Practices

    Connecting AI coding tools to Chinese LLMs is a high-ROI optimization. From a practical standpoint, the core benefits are concentrated in three areas:

    • Significantly lower cost: Chinese models are generally priced lower than leading international products, making them especially suitable for high-frequency usage.
    • Data compliance friendliness: Using API endpoints from domestic service providers avoids compliance risks associated with cross-border data transfers.
    • Response speed and Chinese language capability: In Chinese-context tasks such as code comment generation, requirement understanding, and document writing, Chinese models often perform more naturally and fluently.

    Finally, developers are advised to follow a recommended practice path: first complete the basic connection using standard environment variables and verify the results; once confirmed, immediately write the configuration into the shell startup file for persistence; when model usage scenarios become more complex, introduce script-based switching functions; the final optional step—multi-model routing tools—should be evaluated only when the previous solutions can no longer meet efficiency needs. Through this progressive approach, you can maximize the productivity gains of AI coding tools while keeping complexity under control.