跳到正文
DEV Community· Josh Andrews·· 3 小時前AI 評分58

如何讓 Claude Code 使用在美國託管的開放權重模型

Run Claude Code on open-weight models, hosted in the US

AI 導讀

本教學示範如何透過 ScaledThought 的 Anthropic 相容 API,讓 Claude Code 使用在美國託管的開放權重模型,同時保留其工具、權限和工作流程。

正文

Josh Andrews

Disclosure: I'm a co-founder of ScaledThought, the API used below. Drafted with AI assistance.

Claude Code talks to its model through the Anthropic Messages API, and it lets you change where those requests go with ANTHROPIC_BASE_URL. Point it at an API that speaks the same protocol and Claude Code keeps its tools, permissions and workflow while a different model does the thinking.

This walkthrough points it at ScaledThought, an OpenAI- and Anthropic-compatible API for open-weight models. It's hosted in the US, and prompts and completions are never stored or logged (every response carries x-st-data-retention: none). The Claude Code setup below was run on 2026-10-13 with Claude Code 2.1.296: reading, editing a file and running a shell command all worked.

1. Get a key

Have an agent do it, or run the CLI yourself in your project's directory:

npx -y scaledthought@0.3 init --region us --source org-devto --email "you@example.com"

It writes ST_API_KEY and ST_BASE_URL to ./.env (mode 0600, added to .gitignore) and never prints the key. Usage is prepaid: the CLI gives you a top-up link to approve (from $10, no subscription), and calls are paid from prepaid credits. You can give each key a daily budget, so a runaway session can't run up a bill.

Prefer a browser? Sign up at scaledthought.com/go/org-devto and create a key on the dashboard.

2. Start Claude Code on it

set -a; . ./.env; set +a                         # puts ST_API_KEY in the environment
export ANTHROPIC_BASE_URL=https://api.us.scaledthought.com   # no /v1: Claude Code adds /v1/messages
export ANTHROPIC_AUTH_TOKEN="$ST_API_KEY"
export ANTHROPIC_MODEL=deepseek-v4-1-flash
export ANTHROPIC_DEFAULT_HAIKU_MODEL=deepseek-v4-1-flash   # Claude Code's small background tasks
claude

That's it. Ask it to read a file, edit code or run a command; its tools work through the API like any other request.

What to expect

  • The model isn't Claude. Claude Code's system prompt tells the model it is Claude, so an open model may introduce itself that way. npx -y scaledthought@0.3 usage and each response's model field name the model that actually answered.
  • Requests sent under a Claude model name (Claude Code uses Haiku for small background tasks) are answered by an open model too. Set ANTHROPIC_DEFAULT_SONNET_MODEL and ANTHROPIC_DEFAULT_OPUS_MODEL as well if you switch models by alias.
  • Anthropic's server-side tools, such as web search, aren't available: they run on Anthropic's side. PDFs and Anthropic-defined tools return 400.
  • Claude Code may warn that it doesn't know the model id. It still works; it just assumes a 200k-token context window for auto-compaction.
  • Billing is per token from the usage the model server reports. Current models and prices: scaledthought.com/pricing, or npx -y scaledthought@0.3 models --live.

The full guide, including the MCP server for keys, budgets and billing inside Claude Code: scaledthought.com/guides/claude-code.

Not affiliated with or endorsed by Anthropic or any model publisher. Claude and Claude Code are trademarks of Anthropic; model names are trademarks of their owners.

來源:DEV Community · dev.to