0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Claude Code CLI から Databricks の Claude モデルを利用する

0
Posted at

はじめに

本記事では、VS Code の WSL 環境から Claude Code を実行し、推論モデルとして Azure Databricks の Unity AI Gateway 経由で提供される Claude モデルを利用する手順を整理します。

構成は以下のとおりです。

VS Code
  └─ WSL
      └─ Claude Code CLI
          └─ Unity AI Gateway
              └─ Databricks の Claude モデル

前提

環境セットアップ

Node.jsをインストール

# nvm をインストール
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh | bash

# nvm を読み込む
source ~/.bashrc

# nvm を使って Node.js をインストール
nvm install --lts

# バージョン確認
node --version
npm --version

Claude Code CLI をインストール

# Claude Code CLI をインストール
npm install -g @anthropic-ai/claude-code

# バージョン確認
claude --version

Databricks CLI をインストール

# unzip をインストール
sudo apt update && sudo apt install -y unzip

# Databricks CLI をインストール
curl -fsSL https://raw.githubusercontent.com/databricks/setup-cli/main/install.sh | sudo sh

# バージョン確認
databricks -v

Databricksワークスペースへの認証

databricks auth login --host https://adb-xxxxxxxxxxxxxxxx.x.azuredatabricks.net

証明書エラー

以下のようなエラーが発生した場合、社内 CA 証明書を WSL へコピーして登録する必要があります。

curl failed to verify the legitimacy of the server and therefore could not establish a secure connection to it. To learn more about this situation and how to fix it, please visit the webpage mentioned above.

# WSL へコピー
sudo cp /mnt/c/Users/<Windowsユーザー名>/Downloads/company-root-ca.cer \
  /usr/local/share/ca-certificates/company-root-ca.crt

# 証明書の登録
sudo chmod 644 /usr/local/share/ca-certificates/company-root-ca.crt
sudo update-ca-certificates

# 環境変数を設定
export SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt
export CURL_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt
export REQUESTS_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt
export NODE_EXTRA_CA_CERTS=/usr/local/share/ca-certificates/company-root-ca.crt

モデルのアクセストークンを取得

AI ゲートウェイで使用するモデルを選択して、アクセストークンを生成してメモしておきます。

image.png

Claude Code 設定を作成

~/.claude フォルダに設定ファイルを作成します。

nano ~/.claude/settings.json

設定値は以下のようにします。

{
  "env": {
    "ANTHROPIC_MODEL": "system.ai.claude-sonnet-4-5",
    "ANTHROPIC_DEFAULT_SONNET_MODEL": "system.ai.claude-sonnet-4-5",
    "ANTHROPIC_BASE_URL": "https://<workspace>.azuredatabricks.net/ai-gateway/anthropic",
    "ANTHROPIC_AUTH_TOKEN": "dapi...",
    "CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS": "1"
  }
}

image.png

ANTHROPIC_BASE_URL について

ANTHROPIC_BASE_URL に OpenAI 互換の Chat Completions URL ( https://<workspace>/ai-gateway/mlflow/v1/chat/completions ) を設定すると以下のエラーが発生しました。

API Error: 400 Request path '/ai-gateway/mlflow/v1/chat/completions/v1/messages?beta=true' doesn't match any known API type and is classified as an unmanaged api request. Set the Databricks-Model-Provider-Service header to the name of the model provider service to forward this request to.

Anthropic Messages API 互換の URL ( https://<workspace>.azuredatabricks.net/ai-gateway/anthropic ) を設定する必要があります。

CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS について

Claude Code が自動付与する anthropic-beta ヘッダーを、Databricks の Anthropic 互換エンドポイントが認識できずに以下のエラーが発生しました。

API Error: 400 {"message":"invalid beta flag"}

"CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS": "1" を追記することで解決しました。

動作確認

以下で claude を起動します。

claude

テスト と打ち込み、回答が返ってくることが確認できました。

image.png

Databricks ワークスペース側で使用したトークン数を確認できます。

image.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?