NormaHub knowledge base

Connecting Claude Code

Claude Code on your own NormaHub API key: one-minute quick start, settings.json, Claude models and per-token billing.

What is Claude Code

Claude Code is Anthropic AI assistant for code. It supports only Claude models but can work through a custom gateway.

You can connect NormaHub as a provider and use Claude Opus, Sonnet, Fable and other models through the NormaHub API. Russian version: Подключение Claude Code.

1. Get an API key

Create an API key in the NormaHub dashboard. Copy it once — it is not shown again. Create a dedicated key with its own limit for Claude Code: an agent makes dozens of requests per session, and a shared unlimited key is an open budget.

2. One-minute quick start

Skip settings.json for the check: set two variables in the current terminal and run claude. If the agent answers through NormaHub, the base works and you can make the setup permanent. Important: the address has no trailing /v1.

# Linux/macOS — verify in a minute without editing settings.json
export ANTHROPIC_BASE_URL="https://api.normahub.cc"
export ANTHROPIC_API_KEY="your_api_key"
claude
# Windows (PowerShell)
$env:ANTHROPIC_BASE_URL = "https://api.normahub.cc"
$env:ANTHROPIC_API_KEY = "your_api_key"
claude

3. Find the Claude Code config

Configuration lives in:

  • Linux/macOS: ~/.claude/settings.json
  • Windows: %USERPROFILE%\.claude\settings.json

If the file does not exist, create it together with the ~/.claude/ directory.

4. Configure settings.json

Open or create settings.json and add:

{
  "env": {
    "ANTHROPIC_BASE_URL": "https://api.normahub.cc",
    "ANTHROPIC_AUTH_TOKEN": "your_api_key",
    "CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY": "1",
    "CLAUDE_CODE_DISABLE_1M_CONTEXT": "1"
  },
  "model": "claude-sonnet-4-6"
}

Replace your_api_key with the real dashboard key.

  • ANTHROPIC_BASE_URL — NormaHub API address (no /v1)
  • ANTHROPIC_AUTH_TOKEN — your API key
  • CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY — loads models from the gateway
  • CLAUDE_CODE_DISABLE_1M_CONTEXT — disables synthetic [1m] suffixes
  • model — default model

5. Restart and verify

Fully restart Claude Code after saving, then send a test request. If configured correctly, the answer comes from the selected model through NormaHub. Prefer the install script if you do not want to configure manually.

6. Model list file (optional)

To help Claude Code see the NormaHub models, create ~/.claude/cache/gateway-models.json with the IDs you use (example — take exact IDs from the catalog):

{
  "data": [
    { "id": "claude-opus-4-6" },
    { "id": "claude-sonnet-4-6" },
    { "id": "claude-fable-5-1" }
  ]
}

Keep this file in sync with the catalog: stale IDs produce model-not-found errors while the connection itself is fine.

7. Switching models

ANTHROPIC_BASE_URL changes where requests go, not which model answers — the model still has to be selected. Priority order: /model in session first, then claude --model, then ANTHROPIC_MODEL, then the model field in settings.json. Through a gateway Claude Code passes any model string through without checking it, so a typo surfaces only on the first request.

Aliases such as sonnet, opus, and haiku resolve per provider; for reproducible sessions pin the full model ID in settings.json instead of an alias.

8. Precedence and status check

When the same variable exists in both the shell and the settings.json env block, the settings file value applies. Either way the values are read at startup: export them in the same terminal you run claude from, then restart the process completely. Run /status inside Claude Code to confirm which settings source is active, and claude update to stay on a version that supports your selected model.

How much an agent session costs

Claude Code on your own key is pay-as-you-go with no subscription: zero activity means zero spend, an active session bills every token of file context, tools and answers at the model rate. So match the model to the task: Sonnet for daily work, Opus for heavy refactors, smaller models for routine. Exact input/output prices are in the catalog, the formula in the token cost guide. Balance melts faster than it looks: check request history after the first sessions.

Common errors

  • 401 Unauthorized — invalid or revoked API key
  • 402 Payment Required — insufficient balance
  • 403 Forbidden — model unavailable to your key
  • 429 Too Many Requests — rate or spend limit exceeded
  • 503 Service Unavailable — model provider temporarily down
  • This account requires login — gateway variables not visible in this terminal; export them in the same shell and restart
  • Auth fails with /v1 in the base — ANTHROPIC_BASE_URL must have no /v1 suffix, unlike Cursor and the OpenAI SDK

On errors check balance and available models in the dashboard.

Частые вопросы

Base URL with or without /v1 for Claude Code?

Without: ANTHROPIC_BASE_URL=https://api.normahub.cc. Claude Code appends the API path itself. With the /v1 suffix authentication fails — the key difference from Cursor and the OpenAI SDK.

«This account requires login» error — what now?

Claude Code did not see the environment variables and tries to log in through Anthropic directly. Make sure ANTHROPIC_BASE_URL and the key are set in the same terminal you run claude from, then restart the process.

How is Claude Code usage billed?

Pay as you go per token: every agent request (prompt, file context, tools, answer) is billed at the selected model rates. No Claude subscription is needed and it cannot be attached to a third-party endpoint anyway.

The agent spends a lot. How do I cap it?

A dedicated API key with a spend limit for Claude Code, a smaller model for routine work, short sessions instead of one endless dialog. Watch balance and history in the dashboard.

Do I need a VPN from Russia?

No. Requests go to the NormaHub infrastructure directly, billing comes from your balance. Neither the terminal nor billing needs a VPN.

How do I switch models — /model, flag, or settings?

In-session: /model with an alias or exact ID. One launch: claude --model <id>. Permanent: the model field in settings.json. A gateway passes any model string through, so the name must match an ID your gateway serves — check the catalog.

Terminal variables vs settings.json — which wins?

The settings.json env block wins over shell variables, and both apply only to processes started after the change. Set the values in one place, then fully restart Claude Code from that environment.

Model list is empty or discovery fails — what now?

Check that ANTHROPIC_BASE_URL has no /v1 suffix, the key is valid (curl the gateway), and model discovery is enabled. As a fallback, pin the model explicitly and keep the optional gateway-models.json list in sync with catalog IDs.