4
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?

IBM Cloud: Red Hat AI Inference on IBM Cloud を使ってみた(OpenCode/Claude Code からも接続してみた)

4
Last updated at Posted at 2026-05-23

1. はじめに

Red Hat AI Inference on IBM Cloud が2026/5/22付でリリースされたので、試してみました。
Red Hat AI Inference on IBM Cloud では、推論環境(OpenAI互換API)を提供します。GA段階で選択できるモデルは以下の通りです。

一般的に推論環境にはGPUが必要ですが、Red Hat AI Inference on IBM Cloudはマネージドサービスであり、こうしたHW資源を利用者が気にすることなく利用可能です。

現時点では以下の制約・注意点があります。

  • リージョンはWDCのみ
  • Private Network経由ではアクセスできない(VPE経由でアクセスできない)。Public経路のみ。
  • 元々このサービスは、Red Hat AI InstructLabとして、Model Alignment機能(モデルをカスタマイズする機能)のみが提供されていましたが、推論環境を提供する機能が追加されて、Red Hat AI Inferenceに名称変更されました。そのため、InstructLabの機能もこのサービス名称の中で引き続き提供はされていますが、メンテナンスモードになっており、今後機能拡張はされない予定のようです。

2. Red Hat AI Inference on IBM Cloud の注文

  1. https://cloud.ibm.com/inference にアクセスし、Create ProjectからProjectを作成します。なお、Projectごとにアクセス権の設定や課金が実施され、専用のendpointが提供されます。
    image.png
  2. Project作成画面。Project名を入力してCreateを押下。image.png
  3. Project作成後の状況。https://us-east.rhai.ibm.com/v1/projects/<Project ID>/inferenceというAPI Endpointが割り当てられています。image.png
  4. Model Catalogを選択すると、利用可能なモデルの一覧が表示されます。image.png
    • granite-4-0-h-smallを選択した際の例
      • How to Use(利用方法) image.png

      • Model Card(モデル情報) image.png

      • Pricing(価格) image.png

モデルごとに購入するといったサービスではないため、Projectごとに提供されるendpointを使って、どのモデルも呼び出すことができます。

3. 動作確認

3.1: Customer Portalに用意されているPlaygroundからの実行

Customer Portalからモデルの回答を簡易的に試すことができる機能です。

  • 以下でPlaygroundを押下 image.png
  • モデルを選択。今回はgpt-oss-120bを選択してみます。image.png
  • System Promptの設定(オプション)image.png
  • Inference settingsにおけるパラメーター設定(オプション)image.png
  • 実際に問い合わせをした例。image.png

3.2: APIからの実行

ファイルにIBM CloudのAPI Keyが保管されているという前提
syasuda@MacBook-Pro ~ % cat ibmcloud_apikey
<API KEY>
API_KEYを環境変数に設定
syasuda@MacBook-Pro ~ % export IBM_CLOUD_API_KEY=`cat ibmcloud_apikey`
curlでの呼び出し
syasuda@MacBook-Pro ~ % curl https://us-east.rhai.ibm.com/v1/projects/<projectID>/inference/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $IBM_CLOUD_API_KEY" \
  -d '{
    "model": "gpt-oss-120b",
    "messages": [
      { "role": "user", "content": "空はどうして青いの?" }
    ]
  }' | jq
{
  "choices": [
    {
      "finish_reason": "stop",
      "index": 0,
      "logprobs": null,
      "message": {
        "annotations": null,
        "audio": null,
        "content": "空が青く見えるのは、主に「レイリー散乱(Rayleigh scattering)」という光の散乱現象によるものです。以下に、わかりやすくポイントをまとめてみました。\n\n---\n\n## 1. 太陽光は白色光\n太陽から降りてくる光は、実はさまざまな波長(色)を混ぜ合わせた白色光です。  \n- 赤や橙は長い波長  \n- 青や紫は短い波長  \n\n## 2. 大気中の分子が光を散らす\n地球の大気は窒素・酸素などの小さな分子でできています。太陽光がこれらの分子に当たると、光がさまざまな方向に散らばります。この散乱の度合いは「波長の4乗に反比例」する性質があり、**波長が短いほど強く散乱される**(=レイリー散乱)という特徴があります。\n\n- 青や紫(短波長)は強く散乱される  \n- 赤や黄(長波長)はほとんどそのまま直進\n\n## 3. 人間の目と感覚\n散乱された光は空のあらゆる方向からやってきますが、**人間の目は青と緑に対して感度が高く、紫はあまり感知しにくい**という特性があります。したがって、散乱された光の中で最も目立つのが青色に見えるわけです。\n\n## 4. 時間帯や場所で色が変わる理由\n- **正午付近**:太陽光が大気を通過する距離が最も短く、青い光が強く散乱されるので空は澄んだ青に見える。\n- **朝・夕方**:光が大気を横断する距離が長くなると、短波長(青・紫)は途中で散乱し尽くされ、残った長波長(赤・橙)が目に届くため、空が赤く染まります(これが「朝焼け・夕焼け」)。\n- **大気汚染や湿度**:エアロゾルや水滴が増えると、散乱の仕方が変わり、空が白っぽくなったり、霞んだ色になることがあります。\n\n## 5. まとめ\n- **太陽光は白色光(さまざまな波長)**  \n- **大気の分子が短波長(青)を強く散乱**(レイリー散乱)  \n- **人間の目は青に敏感**、紫はあまり感知できない  \n- **これらが合わさって、昼間の空は青く見える**  \n\n---\n\n### 少しだけ補足\n- 完全に無かったら、**空は黒**に見えるはずです(宇宙空間は光がほとんど散らないので星が黒い背景に浮かびます)。  \n- 他の惑星でも同様の原理で空の色が決まりますが、大気の組成や厚さが違うと、たとえば火星は薄い大気と塵の影響で赤みがかった色に見えます。\n\n質問があれば、ぜひ続きを聞かせてください!",
        "function_call": null,
        "reasoning": "The user asks in Japanese: \"空はどうして青いの?\" Means \"Why is the sky blue?\" We need to answer in Japanese, presumably. Should give a clear explanation about Rayleigh scattering, shorter wavelengths scattered more, human eye sensitivity, etc. Also optional mention of atmospheric composition, scattering of sunlight. Provide some details and maybe mention why it looks deeper blue at noon, reddish at sunrise. Ensure answer is in Japanese. Use polite tone.\n\nWe should be friendly and comprehensive.",
        "reasoning_content": "The user asks in Japanese: \"空はどうして青いの?\" Means \"Why is the sky blue?\" We need to answer in Japanese, presumably. Should give a clear explanation about Rayleigh scattering, shorter wavelengths scattered more, human eye sensitivity, etc. Also optional mention of atmospheric composition, scattering of sunlight. Provide some details and maybe mention why it looks deeper blue at noon, reddish at sunrise. Ensure answer is in Japanese. Use polite tone.\n\nWe should be friendly and comprehensive.",
        "refusal": null,
        "role": "assistant",
        "tool_calls": []
      },
      "stop_reason": null,
      "token_ids": null
    }
  ],
  "created": 1779681872,
  "ibm_metadata": {
    "status": "completed"
  },
  "id": "fe99876f-abc3-4b5f-ba29-81516e92b588",
  "kv_transfer_params": null,
  "model": "gpt-oss-120b",
  "object": "chat.completion",
  "prompt_logprobs": null,
  "prompt_token_ids": null,
  "service_tier": null,
  "system_fingerprint": null,
  "usage": {
    "completion_tokens": 897,
    "prompt_tokens": 77,
    "prompt_tokens_details": null,
    "total_tokens": 974
  }
}

3.3: OpenCodeからの接続

OpenCodeは、オープンソースのAIコーディングエージェントです。Documentはこちら。

Macへのインストール
syasuda@MacBook-Pro ~ % brew install anomalyco/tap/opencode

また、設定ファイルとして以下を登録しておきます。

~/.config/opencode/opencode.json
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "ibm-rhaii": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "IBM Cloud RHAI Inference",
      "options": {
        "baseURL": "https://us-east.rhai.ibm.com/v1/projects/<Project ID>/inference"
      },
      "models": {
        "gpt-oss-120b": {
          "name": "gpt-oss-120b"
        },
        "granite-4-0-h-small": {
          "name": "granite-4-0-h-small"
        },
        "llama-3-3-70b-instruct": {
          "name": "llama-3-3-70b-instruct"
        },
        "mistral-small-3-2-24b-instruct-2506": {
          "name": "mistral-small-3-2-24b-instruct-2506"
        },
        "nvidia-nemotron-3-nano-30b-a3b-fp8": {
          "name": "nvidia-nemotron-3-nano-30b-a3b-fp8"
        }
      }
    }
  },
  "model": "ibm-rhaii/gpt-oss-120b"
}

API Keyは~/.local/share/opencode/auth.jsonに初回認証時に保管されますので、特に今回は事前に編集していません。

OpenCodeの起動
syasuda@MacBook-Pro ~ % mkdir opencode-rhai
syasuda@MacBook-Pro ~ % cd opencode-rhai
syasuda@MacBook-Pro opencode-rhai % opencode
  • /connectでプロバイダーに接続 image.png
  • 先ほど作成したIBM Cloud RHAI Inferenceを選択。image.png
  • API Keyを入力 image.png
  • モデルを選択 image.png
  • 質疑応答 image.png
  • /modelsから他のモデルも選択可能です。image.png

なお、以下のように実施することでブラウザ経由でOpenCodeを利用することもできます(モデル選択もできますし、ブラウザからTerminalを使うことも可能です)

syasuda@MacBook-Pro opencode-rhaii % opencode web
  • OpenCodeをブラウザから利用した場合。image.png

3.4: Claude Codeからの接続

今回はClaude CodeをMacから利用している前提で解説します。

Claude Codeのインストール(だいぶ簡略化して要点となるコマンドだけ書いています。)
syasuda@MacBook-Pro ~ % curl -fsSL https://claude.ai/install.sh | bash
syasuda@MacBook-Pro ~ % echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc && source ~/.zshrc

Claude CodeはAnthropic APIであり、Red Hat AI Inference on IBM Cloudが提供するOpenAI互換のAPIとは互換性がありません。そのため、LiteLLM proxyというLLM Gatewayを介在させることでこの変換を行います。

LiteLLM proxyのインストール
syasuda@MacBook-Pro ~ % brew install uv
syasuda@MacBook-Pro ~ % uv tool install 'litellm[proxy]'
syasuda@MacBook-Pro ~ % litellm-proxy --version
LiteLLM Proxy CLI Version: 1.85.1
LiteLLM Proxy Server URL: http://localhost:4000
Could not retrieve server version: HTTPConnectionPool(host='localhost', port=4000): Max retries exceeded with url: /health/readiness (Caused by NewConnectionError("HTTPConnection(host='localhost', port=4000): Failed to establish a new connection: [Errno 61] Connection refused"))
config.yamlを保管するディレクトリを作成
syasuda@MacBook-Pro ~ % mkdir litellm-proxy
syasuda@MacBook-Pro ~ % cd litellm-proxy

LiteLLM proxyの設定となるconfig.yamlファイルを作成します。

  • あくまでOpen API互換であり、POST /v1/responsesはサポートしていないので、POST /v1/chat/completionsが使えるようにcustom_openaiを利用する。
  • サポートされていないパラメーターがあってもエラーにならないように、drop_params: trueを設定する。

今回は、GA段階でサポートされる全てのモデルを利用できるようにconfig.yamlを作成しました。

config.yaml
model_list:
  - model_name: gpt-oss-120b
    litellm_params:
      model: custom_openai/gpt-oss-120b
      api_base: https://us-east.rhai.ibm.com/v1/projects/<Project ID>/inference
      api_key: <API Key>
      drop_params: true
  - model_name: granite-4-0-h-small
    litellm_params:
      model: custom_openai/granite-4-0-h-small
      api_base: https://us-east.rhai.ibm.com/v1/projects/<Project ID>/inference
      api_key: <API Key>
      drop_params: true
  - model_name: llama-3-3-70b-instruct
    litellm_params:
      model: custom_openai/llama-3-3-70b-instruct
      api_base: https://us-east.rhai.ibm.com/v1/projects/<Project ID>/inference
      api_key: <API Key>
      drop_params: true
  - model_name: mistral-small-3-2-24b-instruct-2506
    litellm_params:
      model: custom_openai/mistral-small-3-2-24b-instruct-2506
      api_base: https://us-east.rhai.ibm.com/v1/projects/<Project ID>/inference
      api_key: <API Key>
      drop_params: true
  - model_name: nvidia-nemotron-3-nano-30b-a3b-fp8
    litellm_params:
      model: custom_openai/nvidia-nemotron-3-nano-30b-a3b-fp8
      api_base: https://us-east.rhai.ibm.com/v1/projects/<Project ID>/inference
      api_key: <API Key>
      drop_params: true
LiteLLM proxyの起動。セキュリティーを考慮してlocalhostからしか接続できないように --hostオプションを付ける。
syasuda@MacBook-Pro litellm-proxy % litellm --config config.yaml --host 127.0.0.1
INFO:     Started server process [90357]
INFO:     Waiting for application startup.

   ██╗     ██╗████████╗███████╗██╗     ██╗     ███╗   ███╗
   ██║     ██║╚══██╔══╝██╔════╝██║     ██║     ████╗ ████║
   ██║     ██║   ██║   █████╗  ██║     ██║     ██╔████╔██║
   ██║     ██║   ██║   ██╔══╝  ██║     ██║     ██║╚██╔╝██║
   ███████╗██║   ██║   ███████╗███████╗███████╗██║ ╚═╝ ██║
   ╚══════╝╚═╝   ╚═╝   ╚══════╝╚══════╝╚══════╝╚═╝     ╚═╝


#------------------------------------------------------------#
#                                                            #
#            'This product would be better if...'             #
#        https://github.com/BerriAI/litellm/issues/new        #
#                                                            #
#------------------------------------------------------------#

 Thank you for using LiteLLM! - Krrish & Ishaan



Give Feedback / Get Help: https://github.com/BerriAI/litellm/issues/new


LiteLLM: Proxy initialized with Config, Set models:
    gpt-oss-120b
    granite-4-0-h-small
    llama-3-3-70b-instruct
    mistral-small-3-2-24b-instruct-2506
    nvidia-nemotron-3-nano-30b-a3b-fp8
INFO:     Application startup complete.
INFO:     Uvicorn running on http://127.0.0.1:4000 (Press CTRL+C to quit)
curlでlitellm proxy経由で問い合わせできることを確認
syasuda@MacBook-Pro ~ % curl -sX POST http://localhost:4000/v1/messages -H "Content-Type: application/json" -d '{
    "model": "gpt-oss-120b",
    "max_tokens": 2000,
    "messages": [
      { "role": "user", "content": "空はどうして青いの?" }
    ]
  }' | jq
{
  "id": "f5246a23-f2ff-4347-a6cf-00b93d97d72f",
  "type": "message",
  "role": "assistant",
  "model": "gpt-oss-120b",
  "stop_sequence": null,
  "usage": {
    "input_tokens": 77,
    "output_tokens": 947,
    "total_tokens": 1024
  },
  "content": [
    {
      "type": "thinking",
      "thinking": "The user asks in Japanese: \"空はどうして青いの?\" – \"Why is the sky blue?\" We need to answer in Japanese, explaining Rayleigh scattering, etc. The user hasn't requested any policy-sensitive content. So just give a thorough explanation, perhaps with simple terms, maybe also mention at sunrise/sunset, why it's not always blue, why it's blue during the day, scattering of shorter wavelengths. Provide a friendly answer.\n\nWe can also mention that the sky appears blue due to scattering of sunlight by molecules, the shorter blue wavelengths scatter more.\n\nWe need to not violate any policy. It's a straightforward scientific explanation.\n\nWe might include mention of other factors like atmosphere's composition, path length, scattering, etc. The answer should be concise but thorough.\n\nWe might add a short bit about phenomena like why it's red at sunrise.\n\nOk final.",
      "signature": null
    },
    {
      "type": "text",
      "text": "空が青く見えるのは、太陽光が大気中の分子や微小な粒子と「散乱」するためです。これを **レイリー散乱(Rayleigh scattering)** と呼びます。\n\n### 1. 太陽光は白色光\n太陽から届く光は実はさまざまな波長(色)を混ぜ合わせた白色光です。可視光は波長が短いほどエネルギーが高く、逆に長いほどエネルギーが低くなります。\n\n| 色 | 波長 (nm) の目安 |\n|----|----------------|\n| 紫 | 380–450 |\n| 青 | 450–495 |\n| 緑 | 495–570 |\n| 黄 | 570–590 |\n| 赤 | 620–750 |\n\n### 2. 波長と散乱の関係\nレイリー散乱の強さは **波長の4乗に反比例** します。つまり、波長が短い光ほど強く散乱されます。  \n- 青(約 475 nm)や紫(≈ 400 nm)は波長が短いので、大気中の分子に当たるとたくさん散らばります。  \n- 赤や黄は波長が長く、散乱されにくいです。\n\n結果として、太陽光が地上に到達する前に、短い波長の光が全方向に拡散され、私たちの目には「空全体が青く」見えるのです。\n\n### 3. なぜ空は時々赤くなるのか\n朝日や夕日のときは、太陽光が大気中を通過する距離が長くなります。長い道のりを通る間に、青や紫の光はほとんど散乱され尽くし、残っているのは散乱しにくい長波長(赤・橙)の光です。これが「夕焼け」や「朝焼け」が赤く見える理由です。\n\n### 4. ざっくりしたイメージ\n- **昼間の空**:太陽光が短い道のりで大気を通り、青い光が強く散乱 → 空は青い  \n- **夕暮れ・夜明け**:光が長い道のりを通る → 短波長は散乱し尽くし、長波長が残る → 空は赤やオレンジ  \n\n### 5. ちょっとした実験\n透明なプラスチックボトルに水と少量のミルクを入れ、光を当ててみると、ボトルの中が青く見えることがあります。これはミルク中の微小粒子が光を散乱し、短波長(青)が強く拡散されるためです。大気の働きを簡易的に再現した実験と言えます。\n\n---\n\n**まとめ**  \n空が青く見えるのは、太陽光に含まれる短波長(青)の光が大気中の分子に散乱されやすく、全方向に広がるからです。光の波長と散乱の関係が、昼間の青い空と、朝帰り・夕暮れの赤い空を作り分けています。"
    }
  ],
  "stop_reason": "end_turn"
}
Claude Codeから接続
syasuda@MacBook-Pro ~ % mkdir claude_rhaii
syasuda@MacBook-Pro ~ % cd claude_rhaii
syasuda@MacBook-Pro claude_rhaii % export ANTHROPIC_AUTH_TOKEN=dummy
syasuda@MacBook-Pro claude_rhaii % export ANTHROPIC_BASE_URL="http://localhost:4000"
syasuda@MacBook-Pro claude_rhaii % claude --model gpt-oss-120b

image.png

当然、/model <model名>で切り替えて使うこともできます。

image.png

4
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
4
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?