Use CodeBuddy CLI with Models Hub: Env Vars and settings.json
Point Tencent Cloud's CodeBuddy CLI at Models Hub's Claude models using CODEBUDDY_BASE_URL and related environment variables or settings.json, with verification and error troubleshooting.
CodeBuddy CLI is Tencent Cloud's terminal AI coding assistant, modeled on Claude Code both in protocol and configuration: it uses the same _BASE_URL / _API_KEY / _MODEL environment variable pattern, and supports the same env block inside settings.json. Point it at Models Hub, and every chat and code edit inside codebuddy uses your Models Hub balance for the model you choose. This page covers the connection only, not how to use CodeBuddy CLI itself.
Three things you need
A Models Hub API key, the base URL https://modelsok.com, and a model name. There's no one-click setup — CodeBuddy CLI isn't one of the targets the Models Hub CLI supports.
Prerequisites
- CodeBuddy CLI installed. Run
npm install -g @tencent-ai/codebuddy-code(Node.js 18.20+ required), or on macOS/Linuxcurl -fsSL https://www.codebuddy.cn/cli/install.sh | bash;codebuddy --versionshould print a version afterward. See the official install docs for details. - A Models Hub API key, created on the Tokens page. The token's group must have access to the models you plan to use.
Recommended models
| Use case | Model | Pricing | Live status |
|---|---|---|---|
| Everyday coding | claude-sonnet-4-6 | Price | Availability and latency |
| Harder refactors and long tasks | claude-opus-4-6 | Price | Availability and latency |
| Lightweight background tasks | claude-haiku-4-5 | Price | Availability and latency |
Model names are authoritative on the pricing page.
Setup
For a quick test, export the environment variables in your current shell:
export CODEBUDDY_API_KEY="your-models-hub-api-key"
export CODEBUDDY_BASE_URL="https://modelsok.com"
export CODEBUDDY_MODEL="claude-sonnet-4-6"Windows (PowerShell):
$env:CODEBUDDY_API_KEY="your-models-hub-api-key"
$env:CODEBUDDY_BASE_URL="https://modelsok.com"
$env:CODEBUDDY_MODEL="claude-sonnet-4-6"To make it persistent, edit the user-level ~/.codebuddy/settings.json (%USERPROFILE%\.codebuddy\settings.json on Windows) and add an env block:
{
"env": {
"CODEBUDDY_API_KEY": "your-models-hub-api-key",
"CODEBUDDY_BASE_URL": "https://modelsok.com",
"CODEBUDDY_MODEL": "claude-sonnet-4-6",
"CODEBUDDY_SMALL_FAST_MODEL": "claude-haiku-4-5"
}
}| Variable | Purpose |
|---|---|
CODEBUDDY_API_KEY | Your Models Hub API key |
CODEBUDDY_BASE_URL | The base URL — do not append /v1; CodeBuddy CLI builds the path itself |
CODEBUDDY_MODEL | The default model |
CODEBUDDY_SMALL_FAST_MODEL | The model used for lightweight background tasks; pick a cheap one |
CodeBuddy CLI merges configuration by priority (higher overrides lower): command-line flags > project-local ./.codebuddy/settings.local.json > project-shared ./.codebuddy/settings.json > user-level ~/.codebuddy/settings.json. For team-wide settings, use the project-shared file.
Verify
Run codebuddy in any project and ask something like "describe this directory in one sentence". A normal reply means you're connected. Two more checks: type /model to see the currently active model, and open Usage logs in the Models Hub console; a request under your configured model name appears within seconds.
Common errors
| Symptom | Cause | Fix |
|---|---|---|
401 / authentication failure | Wrong key, stray whitespace, or a disabled token | Re-copy from the Tokens page |
model not found / no available channel | Misspelled model name, or the token's group can't access it | Check the name on the pricing page |
404 on requests | CODEBUDDY_BASE_URL was set to an OpenAI-style path like /v1/chat/completions | CodeBuddy CLI speaks the Anthropic-compatible protocol — don't append a path suffix to CODEBUDDY_BASE_URL |
settings.json edits don't take effect | An already-open session doesn't reread the config | Restart codebuddy, or run /clear to start a new session |
429 | Rate limited, usually too much concurrency | Retry shortly; contact support for a higher limit if it persists |
More in Troubleshooting.
FAQ
How is it billed? Per input and output token actually consumed, at the price on each model's pricing page; every request is itemized in usage logs.
How is this different from using my Tencent Cloud account directly? Once configured, every CodeBuddy CLI request goes through Models Hub instead of your Tencent Cloud account's quota, and you don't need a separate CodeBuddy subscription.
How do I switch models? Type /model inside CodeBuddy CLI, run codebuddy config set model <model-name>, or edit CODEBUDDY_MODEL and restart.
Related
- WorkBuddy setup: the IDE version of the same product family, configured through a settings UI
- Model pricing and model status
- Claude Code setup, Codex CLI setup
Use OpenCode with Models Hub: /connect and opencode.json
Add Models Hub to OpenCode interactively with /connect, or edit opencode.json to declare Anthropic and OpenAI-compatible providers, with verification and error troubleshooting.
Use WorkBuddy with Models Hub: Custom Model in Settings
Add a custom model in WorkBuddy (CodeBuddy IDE) settings, fill in the Models Hub endpoint and API key to start chatting, with recommended models, verification, and error troubleshooting.