Models Hub
Agent Tools

Use Claude Code with Models Hub: Base URL and API Key Setup

Run Claude Code on Models Hub's Claude models: one-command setup or manual ANTHROPIC_BASE_URL and API key configuration, with verification steps and error troubleshooting.

Edit this page

Claude Code is Anthropic's official terminal coding assistant. Point it at Models Hub and it uses your Models Hub balance for the Claude model family, with the same request format, streaming and tool calls. This page covers the connection only, not how to use Claude Code itself.

Three things you need

A Models Hub API key, the base URL https://modelsok.com, and a model name. Pick either method below; the one-command path takes about 30 seconds.

Prerequisites

  • Claude Code installed. If not, follow the official setup guide: on macOS / Linux run curl -fsSL https://claude.ai/install.sh | bash; on Windows run irm https://claude.ai/install.ps1 | iex in PowerShell. claude --version should print a version.
  • A Models Hub API key, created on the Tokens page. The token's group must have access to the models you plan to use.
Use caseModelPricingLive status
Everyday coding, best balance of speed and qualityclaude-sonnet-4-6PriceAvailability and latency
Complex refactors and long tasksclaude-opus-4-6PriceAvailability and latency
Background lightweight tasks (file search, summaries)claude-haiku-4-5PriceAvailability and latency

Model names are authoritative on the pricing page. Names change as new models ship; don't copy stale names from elsewhere.

The Models Hub CLI merges your API key, base URL and default model into the env block of ~/.claude/settings.json, keeping any other settings you already have.

macOS / Linux:

curl -fsSL https://modelsok.com/cli/install.sh | sh

Windows (PowerShell):

powershell -ExecutionPolicy Bypass -c "irm https://modelsok.com/cli/install.ps1 | iex"

After installing the models command the script opens an interactive menu. Choose claude, paste your API key and pick a model. To change the model or key later, run models again. Full CLI reference: CLI one-command setup.

Models Hub CLI configuring Claude Code

Option 2: manual setup

Edit ~/.claude/settings.json (%USERPROFILE%\.claude\settings.json on Windows); create it if missing. Put four variables in the env block:

{
  "env": {
    "ANTHROPIC_BASE_URL": "https://modelsok.com",
    "ANTHROPIC_AUTH_TOKEN": "sk-your-models-hub-api-key",
    "ANTHROPIC_MODEL": "claude-sonnet-4-6",
    "ANTHROPIC_SMALL_FAST_MODEL": "claude-haiku-4-5"
  }
}

What each variable does:

VariablePurpose
ANTHROPIC_BASE_URLBase URL. Do not append /v1; Claude Code builds the path itself
ANTHROPIC_AUTH_TOKENYour Models Hub API key, sent as a Bearer token
ANTHROPIC_MODELDefault model, i.e. the current selection in /model
ANTHROPIC_SMALL_FAST_MODELModel for Claude Code's background helper tasks; pick a cheap one

For a quick test you can also export these variables in the current shell and run claude; they disappear when the terminal closes.

Account login vs. environment variables

If you previously signed in to Claude Code with a claude.ai account, setting these variables routes requests through Models Hub instead and stops using your claude.ai subscription. Remove the variables to switch back.

Verify

Run claude in any project and ask something like "describe this directory in one sentence". A normal reply means you're connected. Two extra checks:

  1. Type /status inside Claude Code; the API base URL should point to modelsok.com.
  2. Open Usage logs in the Models Hub console; a request under your configured model name appears within seconds.

Common errors

SymptomCauseFix
401 / authentication_errorWrong key, stray whitespace, or a disabled tokenRe-copy from the Tokens page; make sure the sk- prefix is present
model not found / no available channelMisspelled model name, or the token's group can't access that modelCheck the name on the pricing page; switch to a group that includes the model
429 / rate_limitRate limited, usually too much concurrencyRetry shortly; contact support for a higher limit if it persists
Insufficient balanceToken quota or account balance exhaustedTop up in the console, or raise the token's quota
Replies still come from your claude.ai accountsettings.json not picked upConfirm the file path and that the JSON is valid; /status shows the active base URL

More in Troubleshooting.

FAQ

How is it billed? Per input and output token actually consumed, at the price on each model's pricing page; cached tokens are discounted. Every request is itemized in usage logs.

How is this different from the Anthropic API directly? The request format is identical; only the base URL changes. You don't need an Anthropic account, and the same key also works for other vendors' models.

How do I switch models? Type /model inside Claude Code, or change ANTHROPIC_MODEL and restart.

On this page