Unity Gateway クイックスタート
OpenAI互換のEndpointに対して、Unity Gateway経由で最初のリクエストを送信します。
要件
- A Databricks ワークスペース in a Unity Gateway supported region。
- OAuth で認証するには、Databricks CLI をインストールします。または、Databricks CLI を必要としないアクセストークンを使用します。
認証
開始するには、アクセストークンを使用します。本番運用のユースケースには OAuth が推奨されます。DATABRICKS_TOKEN をワークスペースのトークンに設定します。
- Personal access token
- OAuth
パーソナルアクセストークンのエクスポート:
Bash
export DATABRICKS_TOKEN=<your-personal-access-token>
<workspace-url> を Databricks ワークスペースの URL に置き換えます。次に、Databricks CLI でログインし、有効期間の短い OAuth トークンをエクスポートします。
Bash
databricks auth login --host https://<workspace-url>
export DATABRICKS_TOKEN=$(databricks auth token --host https://<workspace-url> | jq -r .access_token)
モデルの選択
Databricks ではすぐに使用できるモデルが提供されており、system.ai スキーマの UI で参照するか、こちらでサポートされているモデルの完全な一覧を確認できます。
このクイックスタートでは、system.ai.gpt-5-2を使用します。別のモデルをクエリーするには、その完全修飾名をスワップします。
リクエストを送信
<workspace-url> を Databricks ワークスペースの URL に置き換えます。
- Bash
- Python
- TypeScript
Bash
curl https://<workspace-url>/ai-gateway/mlflow/v1/responses \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $DATABRICKS_TOKEN" \
-d '{
"model": "system.ai.gpt-5-2",
"max_output_tokens": 256,
"input": [
{
"role": "user",
"content": [{"type": "input_text", "text": "Hello!"}]
},
{
"role": "assistant",
"content": [{"type": "output_text", "text": "Hello! How can I assist you today?"}]
},
{
"role": "user",
"content": [{"type": "input_text", "text": "What is Databricks?"}]
}
]
}'
Python
from openai import OpenAI
import os
client = OpenAI(
api_key=os.environ.get("DATABRICKS_TOKEN"),
base_url="https://<workspace-url>/ai-gateway/mlflow/v1",
)
response = client.responses.create(
model="system.ai.gpt-5-2",
max_output_tokens=256,
input=[
{"role": "user", "content": [{"type": "input_text", "text": "Hello!"}]},
{"role": "assistant", "content": [{"type": "output_text", "text": "Hello! How can I assist you today?"}]},
{"role": "user", "content": [{"type": "input_text", "text": "What is Databricks?"}]},
],
)
print(response.output)
TypeScript
import OpenAI from 'openai';
const client = new OpenAI({
apiKey: process.env.DATABRICKS_TOKEN,
baseURL: 'https://<workspace-url>/ai-gateway/mlflow/v1',
});
const response = await client.responses.create({
model: 'system.ai.gpt-5-2',
max_output_tokens: 256,
input: [
{ role: 'user', content: [{ type: 'input_text', text: 'Hello!' }] },
{ role: 'assistant', content: [{ type: 'output_text', text: 'Hello! How can I assist you today?' }] },
{ role: 'user', content: [{ type: 'input_text', text: 'What is Databricks?' }] },
],
});
console.log(response.output);
リクエストを表示
カタログエクスプローラーでクエリーを実行したモデル (system.ai.gpt-5-2) を開き、 メトリクス tab を選択して、使用履歴に送信したばかりのリクエスト、トークンの使用量、およびレイテンシーを確認します。Unity Gateway のオブザーバビリティをご覧ください。