Important
ベータ版では、新しい Unity AI Gateway エクスペリエンスを利用できます。 新しい Unity AI ゲートウェイは、強化された機能を備えた LLM エンドポイントとコーディング エージェントを管理するためのエンタープライズ コントロール プレーンです。 Unity AI Gateway を使用した AI ガバナンスに関する説明をご覧ください。
この記事では、推論タスク用に最適化され、 Unity AI Gateway によって提供される基礎モデルのクエリ要求を記述する方法について説明します。
Tip
Genie Code (エージェント モード) でこれを行うことができます。 次のプロンプトの例を試してください。
Query the databricks-claude-sonnet-4-5 model using the OpenAI client with extended thinking enabled (budget_tokens set to 10240). Send a reasoning question and print both the thinking summary and the final answer.
Databricks Foundation Model API には、推論モデルを含むすべての Foundation Models と対話するための統合 API が用意されています。 推論により、基礎モデルは複雑なタスクに取り組むための強化された機能を提供します。 一部のモデルでは、最終的な回答を提供する前に、段階的な思考プロセスを明らかにすることで、透明性も提供されます。
推論モデルの種類
推論専用とハイブリッドの 2 種類のモデルがあります。 次の表では、さまざまなモデルでさまざまな方法を使用して推論を制御する方法について説明します。
| 推論モデルの種類 | 詳細 | モデルの例 | パラメーター |
|---|---|---|---|
| ハイブリッド推論 | 必要に応じ、迅速かつ迅速な返信とより深い推論の両方をサポートします。 |
databricks-claude-sonnet-4-6、databricks-claude-sonnet-4-5、databricks-claude-sonnet-4、databricks-claude-opus-4-8、databricks-claude-opus-4-7、databricks-claude-opus-4-6、databricks-claude-opus-4-5、databricks-claude-opus-4-1などのモデルをクロードします。 |
ハイブリッド推論を使用するには、次のパラメーターを含めます。
|
| 推論のみ | これらのモデルは、常に応答で内部推論を使用します。 |
databricks-gpt-oss-120bやdatabricks-gpt-oss-20bなどの GPT OSS モデル。 |
要求で次のパラメーターを使用します。
|
クエリのサンプル
Note
次の例は、Unity AI Gateway とモデル サービスに基づいています。 モデル サービスの代わりにモデル サービスのエンドポイントを使用する場合は、モデル サービス名をエンドポイント名に置き換えます。 使用可能な基礎モデルとそのモデル サービスとエンドポイント名の一覧については、 Foundation Model API で使用できる Databricks でホストされる 基礎モデルを参照してください。
すべての推論モデルは、 チャット完了 エンドポイントを介してアクセスされます。
クロード モデルの例
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ.get('YOUR_DATABRICKS_TOKEN'),
base_url=os.environ.get('YOUR_DATABRICKS_BASE_URL')
)
response = client.chat.completions.create(
model="system.ai.claude-sonnet-4-5",
messages=[{"role": "user", "content": "Why is the sky blue?"}],
max_tokens=20480,
extra_body={
"thinking": {
"type": "enabled",
"budget_tokens": 10240
}
}
)
msg = response.choices[0].message
reasoning = msg.content[0]["summary"][0]["text"]
answer = msg.content[1]["text"]
print("Reasoning:", reasoning)
print("Answer:", answer)
GPT-5.1
GPT-5.1 の reasoning_effort パラメーターは既定で none に設定されていますが、要求ではオーバーライドできます。 推論作業が多いほど、より思慮深く正確な応答が得られますが、待機時間とトークンの使用が増加する可能性があります。
curl -X POST "https://<workspace_host>/ai-gateway/mlflow/v1/chat/completions" \
-H "Authorization: Bearer $DATABRICKS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"model": "system.ai.gpt-5-1",
"messages": [
{
"role": "user",
"content": "Why is the sky blue?"
}
],
"max_tokens": 4096,
"reasoning_effort": "none"
}'
GPT OSS モデルの例
reasoning_effort パラメーターは、"low"、"medium" (既定値)、または"high"値を受け取ります。 推論作業が多いほど、より思慮深く正確な応答が得られますが、待機時間とトークンの使用が増加する可能性があります。
curl -X POST "https://<workspace_host>/ai-gateway/mlflow/v1/chat/completions" \
-H "Authorization: Bearer $DATABRICKS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"model": "system.ai.gpt-oss-120b",
"messages": [
{
"role": "user",
"content": "Why is the sky blue?"
}
],
"max_tokens": 4096,
"reasoning_effort": "high"
}'
Gemini モデルの例
この例では、system.ai.gemini-3-1-proを使用します。
reasoning_effort パラメーターは既定で"low"に設定されていますが、次の例に示すように要求でオーバーライドできます。
curl -X POST "https://<workspace_host>/ai-gateway/mlflow/v1/chat/completions" \
-H "Authorization: Bearer $DATABRICKS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"model": "system.ai.gemini-3-1-pro",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "Why is the sky blue?"
}
],
"max_tokens": 2000,
"stream": true,
"reasoning_effort": "high"
}'
API 応答には、思考コンテンツ ブロックとテキスト コンテンツ ブロックの両方が含まれます。
ChatCompletionMessage(
role="assistant",
content=[
{
"type": "reasoning",
"summary": [
{
"type": "summary_text",
"text": ("The question is asking about the scientific explanation for why the sky appears blue... "),
"signature": ("EqoBCkgIARABGAIiQAhCWRmlaLuPiHaF357JzGmloqLqkeBm3cHG9NFTxKMyC/9bBdBInUsE3IZk6RxWge...")
}
]
},
{
"type": "text",
"text": (
"# Why the Sky Is Blue\n\n"
"The sky appears blue because of a phenomenon called Rayleigh scattering. Here's how it works..."
)
}
],
refusal=None,
annotations=None,
audio=None,
function_call=None,
tool_calls=None
)
複数のターンで推論を管理する
このセクションは、 databricks-claude-sonnet-4-5 モデルに固有です。
複数ターンの会話では、最後のアシスタント ターンまたはツール使用セッションに関連付けられている推論ブロックのみがモデルに表示され、入力トークンとしてカウントされます。
推論トークンをモデルに渡したくない場合 (たとえば、前の手順で推論する必要がない場合)、推論ブロックを完全に省略できます。 例えば次が挙げられます。
response = client.chat.completions.create(
model="system.ai.claude-sonnet-4-5",
messages=[
{"role": "user", "content": "Why is the sky blue?"},
{"role": "assistant", "content": text_content},
{"role": "user", "content": "Can you explain in a way that a 5-year-old child can understand?"}
],
max_tokens=20480,
extra_body={
"thinking": {
"type": "enabled",
"budget_tokens": 10240
}
}
)
answer = response.choices[0].message.content[1]["text"]
print("Answer:", answer)
ただし、モデルが以前の推論プロセスを推論する必要がある場合 (たとえば、中間的な推論を示すエクスペリエンスを構築している場合)、前のターンの推論ブロックを含む、変更されていない完全なアシスタント メッセージを含める必要があります。 完全なアシスタント メッセージを使用してスレッドを続行する方法を次に示します。
assistant_message = response.choices[0].message
response = client.chat.completions.create(
model="system.ai.claude-sonnet-4-5",
messages=[
{"role": "user", "content": "Why is the sky blue?"},
{"role": "assistant", "content": text_content},
{"role": "user", "content": "Can you explain in a way that a 5-year-old child can understand?"},
assistant_message,
{"role": "user", "content": "Can you simplify the previous answer?"}
],
max_tokens=20480,
extra_body={
"thinking": {
"type": "enabled",
"budget_tokens": 10240
}
}
)
answer = response.choices[0].message.content[1]["text"]
print("Answer:", answer)
応答 API を開く
Open Responses API を使用すると、応答reasoningのoutput項目として推論が返されます。 後のターンでモデルが以前の思考内容を踏まえて推論できるようにするには、それらのreasoning項目を、encrypted_contentフィールドを変更せずに、次のリクエストのinputに含めます。
応答出力で返される reasoning 項目の形状は次のとおりです。
{
"type": "reasoning",
"id": "rs_abc123",
"content": [{ "type": "reasoning_text", "text": "Let me work through the question..." }],
"encrypted_content": "<opaque-provider-signature>"
}
会話を続けるには、前のターンの出力内容を input に入れて返し、reasoning の項目はそのまま保持してください。
{
"model": "databricks-claude-sonnet-4-5",
"input": [
{ "role": "user", "content": "Why is the sky blue?" },
{
"type": "reasoning",
"id": "rs_abc123",
"content": [{ "type": "reasoning_text", "text": "Let me work through the question..." }],
"encrypted_content": "<opaque-provider-signature>"
},
{ "role": "assistant", "content": "The sky is blue because of Rayleigh scattering..." },
{ "role": "user", "content": "Can you explain it for a five-year-old?" }
]
}
encrypted_content値には、プロバイダー固有の推論状態が含まれます。 削除または変更された場合、モデルは以前の考え方を理由にすることはできません。 これは、Anthropic Claudeおよび Google Gemini モデルに適用されます。
推論モデルのしくみ
推論モデルでは、標準の入力トークンと出力トークンに加えて、特別な推論トークンが導入されます。 これらのトークンを使用すると、モデルはプロンプトを通じて "考える" ことができるようになります。これを分解し、さまざまな応答方法を検討します。 この内部推論プロセスの後、モデルは最終的な回答を可視出力トークンとして生成します。
databricks-claude-sonnet-4-5などの一部のモデルでは、これらの推論トークンをユーザーに表示し、OpenAI o シリーズなどの他のモデルは破棄し、最終的な出力では公開しません。