AI Coding Assistant Setup: Connect Your Terminal to Chinese LLM Providers

    Learn how to connect a terminal-based AI coding assistant to a Chinese LLM provider using an OpenAI-compatible API. This guide covers API credentials, CLI installation, model profiles, connection testing, troubleshooting, and cost control.

    1. Understand the API Protocol and Connection Settings

    A CLI coding tool does not contain the language model itself. It sends requests to a backend model service using an API protocol. A common option is the OpenAI-compatible Chat Completions API, typically available at /v1/chat/completions. A CLI tool that supports this protocol can connect to a provider offering a compatible endpoint.

    A basic chat connection requires three settings:

    1. Base URL: The API root address, usually ending in /v1. The client appends /chat/completions. Adding or omitting a path segment can cause a 404 error, so follow the provider’s documentation.
    2. API Key: The credential that determines access permissions and the billing account. Authentication typically uses the Authorization: Bearer <Key> request header.
    3. Model: The identifier specifying which model version to call.

    Some providers also require an organization or project identifier. Add these settings as described in the relevant API documentation.

    Support for function calling, streaming, and image input varies by provider. Test each capability after connecting rather than assuming that API compatibility guarantees full feature support.

    2. Create and Securely Store an API Key

    1. Create an account with the model provider and complete any required account verification.
    2. Generate an API key in the provider’s console. Use separate keys for different purposes so you can revoke them independently.
    3. Review billing rules and your available balance. Set a usage limit and start with a small testing budget.
    4. Keep the key out of project source code and version control. Store it in an environment variable.

    On Linux or macOS, add the following to your shell configuration file:

    1. export LLM_API_KEY="your-api-key"

    In Windows PowerShell, run:

    1. [Environment]::SetEnvironmentVariable("LLM_API_KEY", "your-api-key", "User")

    If a configuration file must contain a key, add that file to .gitignore and restrict its permissions, for example with chmod 600.

    If you suspect a key has been exposed, revoke it in the provider’s console immediately and generate a replacement.

    3. Install the CLI Coding Tool

    3.1 Check System Requirements

    Consult the tool’s official documentation for supported operating systems, CPU architectures, and runtime versions. An unsupported runtime version can cause installation to fail partway through.

    After installing the required runtime, check its version:

    1. <runtime> --version

    Commands containing angle-bracket placeholders in this guide are templates. Replace the placeholders with the appropriate names or values before running them.

    3.2 Choose an Installation Method

    Prefer a system package manager when an official package is available. Use an official installation script only when needed.

    • Windows: Run winget search <tool-name> in PowerShell to find the official package, then install it with winget install <package-id>.
    • macOS: Run brew search <tool-name>, then install the package with brew install <package-name>.
    • Linux: Use your distribution’s package manager. On Debian or Ubuntu, run sudo apt update, followed by apt search <tool-name> and sudo apt install <package-name>.

    If installation requires a script, download it first and compare its SHA256 hash with the value published by the official source before executing it:

    1. sha256sum install.sh

    If the download times out, check your proxy environment variables, for example:

    1. echo $HTTPS_PROXY

    After installation, verify that the command is available:

    1. <tool-name> --version

    A version number confirms that the command can run.

    4. Configure Multiple Model Profiles

    Configuration file locations and field names vary by tool. Follow the tool’s documentation.

    The following TOML example illustrates separate profiles for multiple models. It stores environment variable names rather than API keys. The endpoint addresses, model identifiers, and configuration fields are illustrative, not a ready-to-use configuration for a specific tool or provider.

    1. # Example only: check the tool documentation for the configuration file path.
    2. default_profile = "domestic-main"
    3. [profiles.domestic-main]
    4. base_url = "https://api.example-vendor.com/v1"
    5. api_key_env = "LLM_API_KEY"
    6. model = "vendor-chat-large"
    7. [profiles.domestic-backup]
    8. base_url = "https://api.backup-vendor.com/v1"
    9. api_key_env = "LLM_BACKUP_KEY"
    10. model = "vendor-chat-small"

    Select a profile when launching the tool:

    1. <tool-name> --profile domestic-backup

    Some tools also allow a temporary model override within a session. Check the available options with:

    1. <tool-name> --help

    5. Verify the Connection

    5.1 Test the API with curl First

    Before starting the CLI tool, send a request directly to the API. This helps isolate network, endpoint path, and authentication issues.

    Replace the illustrative endpoint and model identifier below with the values supplied by your provider:

    1. curl https://api.example-vendor.com/v1/chat/completions \
    2. -H "Authorization: Bearer $LLM_API_KEY" \
    3. -H "Content-Type: application/json" \
    4. -d '{"model":"vendor-chat-large","messages":[{"role":"user","content":"Reply with: Connection successful"}]}'

    For a successful request, the response JSON should contain the model’s reply in choices[0].message.content.

    The shell reads the key from the environment variable. Avoid placing the actual key directly in the command, where it could be saved in shell history.

    5.2 Test the CLI

    Send a simple prompt:

    1. <tool-name> "Explain closures in one sentence."

    The terminal should display a relevant answer. If the tool can show the active model or profile, confirm that it is using the expected configuration.

    5.3 Test the Editor Integration

    Install the editor extension according to its official instructions. Configure the same Base URL and Model, and use the environment variable for the API key where supported.

    Open a file in a test project and ask a question in the extension panel, such as “What does this function do?”

    Check whether the panel identifies the configured model and returns an answer relevant to the file. If no response appears, inspect the extension’s output logs.

    5.4 Troubleshoot Errors in Order

    Work through the following checks, confirming each layer before moving to the next.

    Step 1: Network connectivity

    Run:

    1. curl -v --max-time 30 <base-url>

    Check whether a connection can be established. Timeouts commonly involve proxy settings, firewalls, or DNS. Inspect variables such as HTTPS_PROXY and adjust the proxy configuration if necessary.

    Step 2: Endpoint path — 404

    Check whether the Base URL has an extra trailing slash or is missing /v1. Compare it with both the provider’s documentation and the client’s path-joining behavior. The same Base URL may behave differently across clients.

    Step 3: Authentication and access — 401 or 403

    • 401 usually indicates an incorrect, expired, or inactive key. After changing a persistent environment variable, open a new terminal so it can load the updated value. In a compatible shell, use echo ${#LLM_API_KEY} to check that the variable is nonempty without printing the key itself.
    • 403 usually indicates that the key lacks permission to use the requested model or that access to the model has not been enabled.

    Step 4: Rate limits or quota — 429

    A 429 response commonly indicates too many requests or an exhausted quota. Reduce concurrency, wait before retrying, and check your balance and usage in the provider’s console. Increase the delay between retries rather than repeatedly sending requests at a high rate.

    Step 5: Model identifier

    If the error says that the model does not exist, compare the Model setting with the provider’s listed identifier. It must match exactly, including capitalization and version suffixes.

    6. Control Costs and Test Capabilities Individually

    Start with a smaller model to validate the complete workflow. Once the configuration works, switch to a larger model for more complex tasks. This reduces spending during setup and troubleshooting.

    Set usage alerts and limit the context included in each request. Avoid sending an entire code repository to the model at once.

    Consult the provider’s official pages for current pricing and model capabilities; this guide does not specify prices or performance figures.

    Finally, test function calling, streaming, and image input separately. Record how each capability behaves in practice, then use those results to decide which tasks to assign to each model.