CodeBuddy

Connect CodeBuddy Code to CoffeeRouter with an OpenAI Chat Completions-compatible models.json configuration.

Before You Begin

  • Install Node.js 18.20 or later.
  • Create an active token under Token Management in CoffeeRouter.
  • Confirm that the token can use your target chat model, and note the exact model ID.
  • Prepare the CoffeeRouter Chat Completions endpoint: https://www.coffeerouter.ai/v1/chat/completions.

Configuration Steps

1. Install CodeBuddy Code

npm install -g @tencent-ai/codebuddy-code
codebuddy --version

2. Create the Model Configuration

The user-level configuration is ~/.codebuddy/models.json. On Windows, this is %USERPROFILE%\.codebuddy\models.json. You can instead create .codebuddy/models.json in the project root; project-level configuration takes priority.

{
    "models": [
        {
            "id": "your-model-id",
            "name": "CoffeeRouter Model",
            "vendor": "CoffeeRouter",
            "url": "https://www.coffeerouter.ai/v1/chat/completions",
            "apiKey": "${COFFEEROUTER_API_KEY}",
            "supportsToolCall": true
        }
    ],
    "availableModels": ["your-model-id"]
}

Replace your-model-id with the model ID shown in CoffeeRouter. Set supportsToolCall to true only when the selected model actually supports tool calling.

3. Set the API Key

Linux / macOS:

export COFFEEROUTER_API_KEY="sk-your-api-key"

Windows PowerShell:

$env:COFFEEROUTER_API_KEY="sk-your-api-key"

CodeBuddy resolves the environment variable when it starts. For persistent use, store the key in your operating system's credential manager or a protected shell configuration, and never commit a real key to Git.

4. Select the Model

Start CodeBuddy with the model you just added:

codebuddy --model your-model-id

You can also select the CoffeeRouter model from the interactive model selector. The configuration supports hot reload; if the list does not refresh after saving, reopen the model selector.

Verify the Integration

Start CodeBuddy in a project directory and send a test task that needs to read code or call a tool. The integration is working when the model responds normally and recognizes the current project.

FAQ

Why Does the Model Not Appear?

Check that availableModels contains the exact model ID, the JSON is valid, and the configuration file is in the expected path.

Why Do I Get 401 or an Invalid API Key Error?

Copy the complete token again, confirm that the environment variable is set in the same shell that starts CodeBuddy, and check the token's status, quota, and access restrictions.

Why Must the URL End in chat/completions?

The url field requires the complete endpoint https://www.coffeerouter.ai/v1/chat/completions. Do not stop at /v1.

Can I Add the Provider in the Graphical Interface?

Yes. Current CodeBuddy IDE / WorkBuddy versions support adding a custom API from the model settings page. models.json remains useful for the CLI, repeatable setup, and project-level configuration.

Security

  • An API key is an access credential. Do not share configuration files, terminal output, or screenshots that contain it.
  • Create a dedicated CodeBuddy token so you can limit models and quota, or revoke access independently.
  • Do not commit a models.json containing a real key. Restrict the file to the current user where possible.
  • CodeBuddy sends task content and the necessary code context to the configured CoffeeRouter service.

Official Resources