Claude Code Custom API Setup

Install Claude Code CLI, connect a TokenHub Anthropic-compatible endpoint, and verify the active model with /status.

What is Claude Code?

Claude Code is Anthropic's command-line coding agent for understanding repositories, editing files, running commands, and completing multi-step development tasks.

This guide connects Claude Code to TokenHub through the Anthropic Messages protocol while keeping the normal terminal workflow. It covers the user-level settings file, API credentials, model selection, connection verification, and the protocol requirements that distinguish a coding agent from a basic chat client. Claude Code is best suited to repository-scale work where the model must inspect context, plan changes, use tools, and verify results. Start in a test repository with a read-only request, confirm that /status shows the intended configuration, and review TokenHub request logs before granting broader command or file permissions.

Claude Code can route model requests through TokenHub's Anthropic Claude Messages API gateway. Keep the official installation flow, then replace only the API key, Base URL, and model ID.

The TokenHub endpoint used by this guide is https://us-api.tokenhub.com/v1/messages.

When to use it

Start in a small repository or test project. First ask the tool to read files, explain code, or produce a plan; only then enable edits, terminal commands, or agent automation.

Install or open the tool

Follow the official Claude Code documentation to install or open the tool. If menus or command names differ, prefer the current official documentation.

For CLI tools, confirm the executable works before adding TokenHub credentials:

claude --version

Prepare TokenHub credentials

Create a TokenHub API key and choose a model from the TokenHub model list that fits this tool.

export TOKENHUB_API_KEY="sk-..."

Keep the key in your local shell, IDE secret storage, or the secure API key field of the tool. Do not commit it to the repository.

Configure TokenHub persistently

Use the tool configuration file or settings page first. This avoids the common problem where a terminal sees the environment variable but the IDE, plugin, or new window does not.

Provider values

FieldValue
ProviderAnthropic Claude Messages
Base URLhttps://us-api.tokenhub.com
API KeyThe value of TOKENHUB_API_KEY
Modelclaude-sonnet-4 or another TokenHub model ID

Settings file locations

FieldValue
CLI settings~/.claude/settings.json
VS Code extensionUser settings.json, field claudeCode.environmentVariables
{
  "$schema": "https://json.schemastore.org/claude-code-settings.json",
  "model": "claude-sonnet-4",
  "env": {
    "ANTHROPIC_BASE_URL": "__API_BASE_URL__",
    "ANTHROPIC_AUTH_TOKEN": "sk-..."
  }
}
{
  "claudeCode.environmentVariables": [
    {
      "name": "ANTHROPIC_BASE_URL",
      "value": "__API_BASE_URL__"
    },
    {
      "name": "ANTHROPIC_AUTH_TOKEN",
      "value": "sk-..."
    }
  ]
}

If the tool separates chat, edit, apply, and fast models, use the same TokenHub model for the first test. Split models later by cost, latency, and reasoning strength.

Temporary environment variables for debugging

Use temporary variables only to confirm the key, network, and model name. After validation, move the same values into the persistent configuration above.

export TOKENHUB_API_KEY="sk-..."
export ANTHROPIC_BASE_URL="__API_BASE_URL__"
export ANTHROPIC_AUTH_TOKEN="$TOKENHUB_API_KEY"
export ANTHROPIC_MODEL="claude-sonnet-4"

Verify the connection

Test with a read-only prompt first, confirming that the model can read context without changing files. Then test edits, Apply, or agent tasks.

Read the project README and summarize it in three sentences. Do not modify any files.

After a successful prompt, check TokenHub request logs for model name, endpoint, token usage, and billing group.

Troubleshooting

SymptomFix
401 or authentication failureConfirm TOKENHUB_API_KEY is valid and saved in the same terminal, IDE, or client profile.
404 or model not foundUse a model ID that exists in your TokenHub workspace and matches the selected protocol.
Wrong endpointKeep the Base URL exactly as shown. OpenAI-compatible tools usually need /v1; Claude-compatible tools usually do not.
Request timeoutCheck network access to https://us-api.tokenhub.com, proxy settings, and workspace allowlists.
Tool uses another modelRecheck every chat, edit, apply, fast, and autocomplete model slot.

Choose a compatible Claude Code model

WorkloadModel choiceWhy it fits
Repository-wide implementationAnthropic Messages model with tool use and a long context windowClaude Code needs the Messages protocol, streaming, and reliable tool execution when it reads and edits across a repository.
Interactive fixes and reviewsBalanced coding model on the same compatible routePrioritize stable tool calls and response latency over a model that only performs well in plain chat.
Subagents and background workLower-cost compatible model, validated firstValidate tool use, streaming, and long-running task behavior before mapping it to background or alias workloads.
Browse TokenHub models and compatibility

Claude Code custom API FAQ

How is Claude Code different from regular Claude chat?

Claude Code is a repository and terminal agent that can inspect files, propose edits, and run approved commands. Regular chat primarily provides a conversation interface; TokenHub supplies compatible API access, not a Claude subscription.

How do I install Claude Code CLI?

Use Anthropic's current official installer or supported package-manager instructions. Run claude --version and claude doctor before adding TokenHub so installation problems are separated from API configuration problems.

Should ANTHROPIC_BASE_URL include /v1/messages?

No. Enter the TokenHub API root because Claude Code appends the Messages route itself. Adding /v1/messages twice commonly produces a 404 response.

Which TokenHub models work with Claude Code?

Choose a model explicitly verified for Anthropic Messages, streaming, and native tool use, with enough context for the repository. Chat Completions support alone is not sufficient.

How can I verify the Claude Code custom API?

Start a new terminal session, run /status, then request a read-only repository explanation. Confirm the model ID and /v1/messages request in TokenHub logs before allowing edits.

References

This setup is based on TokenHub and official documentation, last verified on 2026-09-04.