Add Router One models to CodeBuddy with models.json
CodeBuddy, Tencent Cloud's AI coding assistant, reads custom models from a models.json file in both the CodeBuddy Code CLI and the CodeBuddy IDE. Each entry names a model ID, an API key and a url that must be the full request path, and custom models currently support only the OpenAI API format. Set url to https://api.router.one/v1/chat/completions and id to a Router One catalog ID, and CodeBuddy sends that model's requests to Router One on your key: every chat model in the catalog, Claude and GPT included, is served on that endpoint. Checked against CodeBuddy Code 2.158.0 (released 2026-09-24) and CodeBuddy's models.json documentation on 2026-09-27.
Where models.json lives, and which CodeBuddy product reads it
CodeBuddy merges up to two files over its built-in configuration: a project file overrides a user file for entries with the same id, and a project availableModels list replaces the user one instead of merging. Both files reload about one second after you save, and models added this way carry a custom tag in the model list. The CLI and the IDE read the same paths but differ in one field: the CLI resolves ${VAR} references in apiKey and url when it starts, while the IDE documentation says apiKey takes the key value itself, not an environment variable name. Install the CLI with npm install -g @tencent-ai/codebuddy-code (Node.js 18.20 or newer), create a dedicated Router One key with a maxSpend cap, and copy chat model IDs from /models.
| File | Scope | Read by |
|---|---|---|
| ~/.codebuddy/models.json | User level: every project | CodeBuddy Code and CodeBuddy IDE |
| <project>/.codebuddy/models.json | Project level: overrides user entries with the same id | CodeBuddy Code and CodeBuddy IDE |
Add a Router One entry to models.json: url is the full /v1/chat/completions path
Add one entry per Router One model under models: id is the exact catalog ID, url is https://api.router.one/v1/chat/completions, and apiKey is the dedicated key (in the CLI, a reference such as ${ROUTER_ONE_API_KEY} keeps it out of the file). Set maxInputTokens and maxOutputTokens yourself, set supportsToolCall and supportsImages to true only where the model page lists tool calling and image input, and leave temperature out. Save the file; in the CLI, start with codebuddy --model anthropic/claude-sonnet-5 or pick the model in /model, and in the IDE choose it from the model dropdown. This example pairs a main model with a cheaper lite model for background work (see the relatedModels section below):
{
"models": [
{
"id": "anthropic/claude-sonnet-5",
"name": "Claude Sonnet 5 (Router One)",
"url": "https://api.router.one/v1/chat/completions",
"apiKey": "sk-your-router-one-key",
"maxInputTokens": 200000,
"maxOutputTokens": 16000,
"supportsToolCall": true,
"supportsImages": true,
"relatedModels": { "lite": "anthropic/claude-haiku-4.5" }
},
{
"id": "anthropic/claude-haiku-4.5",
"name": "Claude Haiku 4.5 (Router One)",
"url": "https://api.router.one/v1/chat/completions",
"apiKey": "sk-your-router-one-key",
"maxInputTokens": 200000,
"maxOutputTokens": 8000,
"supportsToolCall": true,
"supportsImages": true
}
]
}What the url field accepts
CodeBuddy's documentation requires url to be the full request path, usually ending in /chat/completions, and lists base URLs such as https://api.openai.com/v1 as wrong examples. The CodeBuddy Code 2.158.0 source normalizes a custom model's url so that it ends in exactly one /chat/completions, trimming a trailing slash or a repeated suffix first; it does not add /v1, so the host root alone, https://api.router.one, becomes https://api.router.one/chat/completions, which is not a documented Router One endpoint. Since 2.155.0, a custom model without a url fails before any request is sent and asks you to fill it in, instead of going to CodeBuddy's own gateway. Only the OpenAI API format is supported, which is all Router One needs: every chat model in the catalog, including Claude, GPT, Gemini, Grok and DeepSeek IDs, is served on POST /v1/chat/completions. Image-generation IDs such as gpt-image-2 are not chat models, so leave them out of models.json.
Background and subagent requests: set relatedModels
CodeBuddy Code switches models inside a session: the lite variant handles background extraction and summaries and serves the Agent tool when it asks for lite, and the reasoning variant handles deep reasoning. Built-in subagents such as Explore are declared to use lite. Per CodeBuddy's docs, custom models from models.json do not inherit the product's defaultRelatedModels: if your main model declares no relatedModels and no environment variable or variantModels setting overrides them, lite and reasoning fall back to the main model, so those background and Explore requests all run and bill at its rate. Point relatedModels.lite at a cheaper Router One ID defined in the same file, such as anthropic/claude-haiku-4.5, whose model page lists tool calling. The same mapping can come from CODEBUDDY_SMALL_FAST_MODEL (lite) and CODEBUDDY_BIG_SLOW_MODEL (reasoning), which take precedence, or from /model:lite and /model:reasoning, which save variantModels in settings.json; CODEBUDDY_CODE_SUBAGENT_MODEL overrides the model of every built-in subagent. The docs mark the subagent, vision and longContext variants as reserved and not yet used. After a session, Dashboard → Logs shows each request's model, tokens, cost, status, total time and, for streamed requests that produced output, time to first token (TTFT), so you can see how many requests ran on the lite model.
Token limits, temperature and capability flags
These fields shape every request CodeBuddy sends for the model:
- maxInputTokens: the context window CodeBuddy Code compacts against. Per its changelog, a custom model without it falls back to a default auto-compact window, 200k tokens since 2.98.0. Set a value at or below the model page's context window (1,048,576 tokens for anthropic/claude-sonnet-5, 200,000 for anthropic/claude-haiku-4.5); a larger value lets each request carry more billed input before compaction.
- maxOutputTokens: a per-request output cap you choose. Since 2.119.1, CodeBuddy Code no longer fills in its built-in catalog's ceiling as the per-request limit when a custom model has none, so set the cap you want.
- temperature: leave it out. Since 2.128.0, CodeBuddy sends no temperature for a custom model that has none configured, which avoids 400 errors from models such as GPT-5 that accept only their default.
- supportsToolCall and supportsImages: set them to true only when the model page lists tool calling and image input. Prefer IDs whose page lists tool calling; for other IDs, test one tool call first.
Which model ID should CodeBuddy send?
Copy the exact model ID from /models, preserving case, hyphens, and version suffixes; do not substitute a display name. Open its detail page and match the supported API endpoints, context window, and capabilities such as tool calling to the provider and features selected in CodeBuddy. A catalog listing does not mean the client can use every feature of that model. Give each client or application a dedicated API key with a maxSpend cap.
Which API protocol is CodeBuddy using?
OpenAI-compatible describes an interface format; it does not make Chat Completions (/v1/chat/completions), Responses (/v1/responses), and Anthropic Messages (/v1/messages) interchangeable. Check the installed client version, provider configuration, and actual request path against the model detail page and API compatibility fact sheet. A successful plain-text chat does not establish support for hosted tools, conversation state, or file-editing features.
Verify the CodeBuddy call in your request trace
Send a simple text request from CodeBuddy, then match its trace in Dashboard → Logs by time, model, and request_id: tokens, cost, latency, and status. Next, test streaming, tool calls, and multi-turn history separately. For failures, retain the actual request path, full error message, and request_id. If there is no matching log, check client configuration and connectivity before attributing the error to the gateway or upstream.
FAQ
Can CodeBuddy use Router One's Anthropic Messages endpoint for Claude?
Not through models.json. CodeBuddy's documentation states that custom models currently support only the OpenAI API format, with url set to a full /chat/completions path. That is enough for Claude: Router One serves Claude-family IDs such as anthropic/claude-sonnet-5 on POST /v1/chat/completions, alongside GPT, Gemini, Grok and DeepSeek IDs. Router One's Messages endpoint, POST https://api.router.one/v1/messages, is for clients built on the Anthropic format, such as Claude Code.
Can I use CODEBUDDY_BASE_URL and CODEBUDDY_API_KEY instead of models.json?
This guide doesn't, because the environment-variable docs don't pin down the protocol or path form. CODEBUDDY_BASE_URL is described as overriding the API endpoint; one example uses a base ending in /v1, while a DeepSeek example labelled as the Anthropic protocol uses a host root. models.json documents its format and its url field exactly, so it is the dependable route for Router One. Model settings still combine with it: codebuddy --model selects a main model defined in models.json, and CODEBUDDY_SMALL_FAST_MODEL and CODEBUDDY_BIG_SLOW_MODEL override the lite and reasoning variants.
My Router One model is missing from CodeBuddy's model list. What should I check?
Check the JSON syntax and the file path first, then availableModels: once it is set, only the IDs it lists appear, and a project file's list replaces the user file's entirely. An entry with the same id in the project file overrides the user entry. In the CLI, an environment variable referenced in apiKey or url that is not set stays as the literal placeholder, so requests fail; in the IDE, apiKey must be the key itself. Saved changes reload after about one second. If the model shows up but requests fail with 401, re-copy the key; a 400 with must be called via means that ID is not served on Chat Completions, so pick one whose model page lists POST /v1/chat/completions.
Which models can CodeBuddy use through the gateway?
Choose a current catalog model that supports both the endpoint and the features CodeBuddy uses. Check /models and the model detail page for the exact ID, current rates, and capabilities; a family name such as GPT or Claude is not a compatibility guarantee. A client that lists a model has only read the ID, from its own configuration or from GET /v1/models; verify an actual request too.
Models are listed, but requests fail with 400 or 404. What should I check?
Record the actual request path and error message, then check the exact model ID. A 400 can indicate invalid parameters, unsupported tools, or a model/endpoint mismatch; a 404 can indicate an incorrect path or missing resource, so it does not by itself establish that a model was retired. If the error says must be called via, use the named endpoint or select a model supported on the current endpoint. Do not add or remove /v1 or /chat/completions across all clients indiscriminately.
Does this work from Mainland China?
Yes. The gateway is reachable from Mainland China without a VPN, and the configuration is identical to the global setup.
How do I debug a 401/402/403/429?
Match the request and error message in Dashboard → Logs. For 401, check whether the key was sent and is valid; for 402, check wallet balance and maxSpend; for 403, check key permissions and access restrictions. For 429, distinguish request/token limits from upstream throttling using the error details. Keep the request_id and follow the error-codes reference.