クロードコードのカスタム API セットアップ

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

クロードコードとは何ですか?

Claude Code は、リポジトリを理解し、ファイルを編集し、コマンドを実行し、複数ステップの開発タスクを完了するための Anthropic のコマンドライン コーディング エージェントです。

This guide connects Claude Code to TokenHub through the Anthropic Messages protocol while keeping the normal terminal workflow.ユーザーレベルの設定ファイル、API 認証情報、モデルの選択、接続検証、およびコーディング エージェントと基本的なチャット クライアントを区別するプロトコル要件について説明します。 Claude Code is best suited to repository-scale work where the model must inspect context, plan changes, use tools, and verify results.読み取り専用リクエストを使用してテスト リポジトリで開始し、/status が意図した構成を示していることを確認し、より広範なコマンドまたはファイル権限を付与する前に TokenHub リクエスト ログを確認します。

Claude Code は TokenHub の Anthropic Claude Messages 互換 API ゲートウェイ経由でモデルリクエストを送信できます。公式のインストール手順はそのまま使い、API key、Base URL、モデル ID だけを置き換えます。

このガイドで使う TokenHub endpoint は https://us-api.tokenhub.com/v1/messages です。

使う場面

小さなリポジトリや検証用プロジェクトから始めます。まずは読み取り、コード説明、計画作成を試し、その後で編集や自動化タスクを有効にします。

インストールまたは起動

まず Claude Code 公式ドキュメント に従ってインストールまたは起動します。画面名が違う場合は現在の公式ドキュメントを優先してください。

CLI ツールの場合、TokenHub 認証情報を追加する前に実行ファイルが使えることを確認します:

claude --version

TokenHub 認証情報を準備

TokenHub API key を作成し、TokenHub のモデル一覧からこのツールに適したモデルを選びます。

export TOKENHUB_API_KEY="sk-..."

キーはローカル shell、IDE のシークレット保存領域、またはツールの安全な API key 欄に保存します。リポジトリにはコミットしないでください。

TokenHub プロバイダーを設定

Models、Providers、API Keys、OpenAI Compatible などの設定画面で次の値を入力します。

Provider の値

項目
プロバイダーAnthropic Claude Messages
Base URLhttps://us-api.tokenhub.com
API KeyTOKENHUB_API_KEY の値
モデルclaude-sonnet-4 または別の TokenHub model ID

設定ファイルの場所

項目
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-..."
    }
  ]
}

ツールが chat、edit、apply、fast model を分けている場合、最初のテストでは同じ TokenHub モデルを使います。動作確認後にコスト、レイテンシ、推論力で分けます。

一時環境変数はデバッグ用

一時変数は key、ネットワーク、モデル名の確認にだけ使います。確認後は同じ値を上の永続設定に移してください。

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"

接続を確認

まず読み取り専用のプロンプトで、モデルが文脈を読めること、ファイルを変更しないことを確認します。その後、編集や Agent タスクを試します。

このプロジェクトの README を読み、3 文で要約してください。ファイルは変更しないでください。

プロンプトが成功したら、TokenHub のリクエストログでモデル名、endpoint、token 使用量、課金グループを確認します。

トラブルシューティング

症状対処
401 または認証失敗TOKENHUB_API_KEY が有効で、同じ terminal、IDE、クライアントプロファイルに保存されているか確認します。
404 またはモデルが見つからないTokenHub ワークスペースに存在し、選択したプロトコルに対応するモデル ID を使います。
endpoint が違う上記の Base URL と完全に一致させます。OpenAI 互換ツールは通常 /v1 が必要で、Claude 互換ツールは通常不要です。
リクエストがタイムアウトするhttps://us-api.tokenhub.com へのネットワーク、プロキシ設定、ワークスペースの allowlist を確認します。
別のモデルが使われるchat、edit、apply、fast、autocomplete など全てのモデル欄を再確認します。

モデルの選び方

用途モデルの方向性理由
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.
TokenHub のモデルを見る

Claude Code カスタム 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.

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.

ANTHROPIC_BASE_URL には /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.

どの TokenHub モデルが 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.

Claude Code カスタム 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.

参考資料

この設定は TokenHub と公式ドキュメントに基づいており、最終確認日は 2026-09-04。