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?

Kong Gateway経由でAzure FoundryのClaudeモデルを呼び出す

0
Posted at

Microsoft Foundry上の Claude モデルを Kong Gateway経由で呼ぶためのメモ。

Microsoft Foundry(旧 Azure AI Foundry)

Microsoft FoundryとはMicrosoftが提供するエンタープライズ向けのAI統合プラットフォームで、生成AIを活用したアプリケーションやAIエージェントを大規模かつ安全に構築・テスト・運用・管理するための環境として機能するらしい。
似たようなものにAzure OpenAI Serviceがあるが、ざっくり以下のような違いがある。

  • Azure OpenAI — OpenAI 系モデル(GPT 等)を API で叩くだけのシンプルなサービス
  • Microsoft Foundry — モデル管理・デプロイ・評価・ガバナンスまで含む AI アプリ基盤。OpenAI 以外のモデル(Anthropic Claude など)もここから提供される

Claude は Azure OpenAI には存在せず、Foundry の「パートナーモデル」として提供されているため、Claudeを使いたいならFoundryを使うことになる。

利用手順

最初に利用可能なモデルを準備する。
https://ai.azure.com/にアクセスし、Microsoft Foundryのプロジェクトを作成する。
作成後、左サイドバーの「モデル+エンドポイント」を選択し、「モデルのデプロイ」→「基本モデルをデプロイする」からモデルをデプロイする。
image.png

今回は「claude-sonnet-4-5」をデプロイした。
デプロイ後、ターゲットURI、キー、配置情報の名前を控えておく。
image.png

次にKongの設定用のYAMLを作成する。
以下は検証に使ったYAMLとなる。

_format_version: "3.0"

services:
- name: azure-claude-sonnet-45
  url: https://this.url.is.not.used
  routes:
  - name: azure-claude-sonnet-45
    paths:
    - /azure-claude-sonnet-45
    strip_path: true
  plugins:
  - name: ai-proxy-advanced
    config:
      llm_format: anthropic
      targets:
      - route_type: "llm/v1/chat"
        auth:
          header_name: "x-api-key"
          header_value: "1XJ1r494..."
        logging:
          log_statistics: true
          log_payloads: true
        model:
          provider: "azure"
          name: claude-sonnet-4-5
          options:
            azure_instance: ippei-mpxuxxx-eastus2
            azure_deployment_id: claude-sonnet-4-5
            max_tokens: 1024
            temperature: 1.0

少し解説する。

services:
- name: azure-claude-sonnet-45
  url: https://this.url.is.not.used

AI Proxy Advanced Pluginを利用する際はServiceの宛先は使われないので、ダミーの値を入れている。

        auth:
          header_name: "x-api-key"
          header_value: "1XJ1r494..."

header_valueでAPIキーを渡している。
ベタ書きしてしまっているが、実際に使う場合はKonnectのVault機能などで隠蔽するとよい。
header_nameはFoundryでRESTを指定してcurlのコマンドを表示させても確認できる。

        model:
          provider: "azure"
          name: claude-sonnet-4-5
          options:
            azure_instance: ippei-mpxuxxx-eastus2
            azure_deployment_id: claude-sonnet-4-5

model.nameはFoundaryでデプロイしたモデル名、options内のパラメータはFoundryの以下を設定する。

  • azure_instance:ターゲットURIからservices.ai.azure.comを取り除いた値を設定
  • azure_deployment_id:配置情報の名前

上記のYAMLをdeck gateway syncなどでKong Gatewayに設定し、アクセスしてみる。

export KONG_PROXY="http://localhost:8000"
curl -X POST "$KONG_PROXY/azure-claude-sonnet-45" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-sonnet-4-5",
    "max_tokens": 1024,
    "messages": [
      {"role": "user", "content": "Hello"}
    ]
  }'

問題なければ以下のような応答が得られる。

{"model":"claude-sonnet-4-5-20250929","id":"msg_01Cu7mdUVvph2EHk5FJi1XQZ","type":"message","role":"assistant","content":[{"type":"text","text":"Hello! How can I help you today?"}],"stop_reason":"end_turn","stop_sequence":null,"stop_details":null,"usage":{"input_tokens":8,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":12,"service_tier":"standard","inference_geo":"not_available"}}

ということで、設定方法さえ分かってしまえば簡単にKong Gateway経由で利用できる。

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?