[KongchangAI]
· 2 min read· 1,243 words

Running Claude Code on Open-Weight Models: US Hosting and Zero-Log Practices

Running Claude Code on Open-Weight Models: US Hosting and Zero-Log Practices

How to connect Claude Code to third-party open-weight model APIs via ANTHROPIC_BASE_URL.

This article explains how to redirect Claude Code to an open-weight model API from ScaledThought, which is compatible with the Anthropic Messages API, US-hosted, zero-log, and prepaid. Steps include initializing a key with the CLI and setting ANTHROPIC_BASE_URL, ANTHROPIC_AUTH_TOKEN, ANTHROPIC_MODEL, and the HAIKU model variable. Testing confirms file reading, code editing, and shell commands work. Caveats include models self-identifying as Claude, alias switching requiring Sonnet/Opus variables, and 400 errors for server-side tools and PDFs. It reflects the decoupling of coding agents from underlying models.

Claude Code communicates with models through the Anthropic Messages API, and the ANTHROPIC_BASE_URL environment variable allows users to redirect requests to any endpoint compatible with that protocol. This means that as long as the target API follows the same interface specification, Claude Code's toolchain, permission system, and workflows can remain unchanged, while the model performing inference behind the scenes can be entirely different.

This article is based on a technical share from the co-founder of ScaledThought, a service that provides an open-weight model API compatible with both OpenAI and Anthropic protocols, hosted within the United States, and committed to not storing or logging any prompts or completions—every response carries an x-st-data-retention: none header. According to the author's actual testing on Claude Code version 2.1.296, reading files, editing code, and running shell commands all work normally.

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

Configuration Steps: From Obtaining a Key to Launching Claude Code

Obtaining an API Key

It is recommended to use the CLI to initialize a key in your project directory, or you can let an AI agent do it automatically:

npx -y [email protected] init --region us --source org-devto --email "[email protected]"

This command writes ST_API_KEY and ST_BASE_URL into the ./.env file (with permission mode 0600, and automatically added to .gitignore), and does not print the key in the terminal. Billing uses a prepaid model, starting from $10, with no subscription required. Each key can have a daily budget cap to prevent runaway sessions from incurring unexpected costs. If you prefer a browser-based approach, you can also register on the ScaledThought official website and create a key in the console.

Launching Claude Code

Configure the following environment variables and then simply run claude:

set -a; . ./.env; set +a

**What is the Anthropic Messages API**

The Anthropic Messages API is the HTTP interface specification that Anthropic provides for its Claude models. The core endpoint is `/v1/messages`, using POST requests, with the request body containing fields such as `model`, `messages`, `max_tokens`, `system`, and `tools`, and the response returning `content` blocks (text, tool calls) and `usage` statistics. It is not structurally identical to OpenAI's `/v1/chat/completions`—for example, the system prompt is a separate field rather than a message role, and tool calls use `tool_use`/`tool_result` content blocks. Because this interface has clear, stable semantics, any third-party service that implements the same request and response format can be called directly by Claude Code, making redirection via `ANTHROPIC_BASE_URL` possible.

**ANTHROPIC_MODEL and HAIKU Model Environment Variables**

`ANTHROPIC_MODEL` specifies the model ID used for Claude Code's main conversation; `ANTHROPIC_DEFAULT_HAIKU_MODEL` specifies the lightweight model used for small background tasks (such as generating short titles or quick classification). Claude Code internally routes different tasks by model tier (Haiku/Sonnet/Opus), so when the main model is switched to an open-weight model, you still need to explicitly indicate the model ID corresponding to each tier, otherwise some background requests will fail or fall back to default values. Similarly, if you switch aliases via the `/model` command, you need to set `ANTHROPIC_DEFAULT_SONNET_MODEL` and `ANTHROPIC_DEFAULT_OPUS_MODEL` accordingly.
# Load ST_API_KEY into environment variables
export ANTHROPIC_BASE_URL=https://api.us.scaledthought.com
# Note: do not add /v1; Claude Code will automatically append /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
# Used for Claude Code's small background tasks
claude

After configuration is complete, Claude Code's tool calls such as reading files, editing code, and running commands will all execute normally through this API. The core value of this approach is that developers can flexibly switch the underlying inference model without changing their existing workflows.

Notes for Practical Use

Model Identity and Context Management

Claude Code's system prompt tells the model "you are Claude," so open-weight models may introduce themselves as Claude. The actual model name answering questions can be confirmed via the npx -y [email protected] usage command or the model field in each response.

Requests sent with a Claude model name (Claude Code uses Haiku for small background tasks) are also answered by the open model. If you switch models via aliases, you also need to set ANTHROPIC_DEFAULT_SONNET_MODEL and ANTHROPIC_DEFAULT_OPUS_MODEL. Additionally, Claude Code may warn that it does not recognize the model ID, but this does not affect usage—it simply assumes a 200k token context window by default for automatic compaction.

Functional Boundaries and Limitations

Anthropic's server-side tools (such as web search) are unavailable under this approach, because these tools run on Anthropic's side. PDF files and tools defined by Anthropic will return a 400 error.

Billing is metered by token, based on usage reported by the model server. Currently supported models and prices can be viewed on the ScaledThought pricing page, or you can run npx -y [email protected] models --live to get a real-time list. The full guide (including MCP servers for managing keys, budgets, and billing within Claude Code) can be found in the ScaledThought official documentation.

Server-Side Tools and the Causes of 400 Errors

Anthropic's server-side tools (such as web search and computer use) and PDF file parsing are executed by Anthropic on the backend in conjunction with its own models, and are not part of the generic request format of the Messages API. When Claude Code sends these tool definitions or PDF content blocks to a third-party endpoint, the other party's interface cannot recognize these non-standard fields and typically returns HTTP 400 (Bad Request) directly. Therefore, when connecting to open-weight models, you need to avoid triggering these server-side capabilities or disable the relevant tools in the configuration. In contrast, Claude Code's local tools (reading files, editing, running shell commands) are orchestrated by the client and round-trip as standard tool_use blocks, so they work normally.

The Significance of Open-Weight Model Access for Coding Agents

This approach reflects a trend in the AI coding tool ecosystem: coding agents are being decoupled from the underlying models. The reason Claude Code can connect to third-party models is essentially that the Anthropic Messages API has become a de facto interface standard. Once the protocol layer is unified, model selection becomes a replaceable configuration item.

For teams concerned about data sovereignty, US hosting plus a zero-log commitment provides compliance-level assurance. The prepaid and daily budget mechanisms address cost controllability. However, it should be noted that this service is not affiliated with or endorsed by Anthropic or any model publisher, and Claude and Claude Code are trademarks of Anthropic.

From a practical standpoint, this configuration allows developers to flexibly choose models based on task complexity—using lightweight models for simple tasks to control costs, and switching to stronger open-weight models for complex tasks, while the entire toolchain and permission system remain consistent.

One-line Summary

Configuration and considerations for connecting Claude Code to third-party open-weight model APIs via ANTHROPIC_BASE_URL.

Paragraph Summary

This article explains how to redirect Claude Code to an open-weight model API provided by ScaledThought, which is compatible with the Anthropic Messages API, hosted in the US, committed to zero logging, and uses prepaid billing. Configuration steps include initializing a key with the CLI, setting ANTHROPIC_BASE_URL, ANTHROPIC_AUTH_TOKEN, ANTHROPIC_MODEL, and the HAIKU model variable, then running claude. In testing, reading files, editing code, and running shell commands all work normally. The article also notes caveats: open models may identify themselves as Claude; requests with Claude model names are also answered by open models; switching aliases requires configuring Sonnet/Opus variables; and Anthropic server-side tools and PDFs return 400 errors. Finally, it points out that this approach reflects the trend of decoupling coding agents from underlying models.

#Claude Code#ANTHROPIC_BASE_URL#open-weight models#Anthropic Messages API#zero-log#US hosting#coding agent
Share:

Related articles