Unity Gateway クイックスタート

Unityゲートウェイを通じてOpenAI互換エンドポイントに対して最初のリクエストを送信します。

必要条件

Authenticate

まずは個人アクセストークンを使いましょう。 OAuthは本番環境の用途に推奨されています。 ワークスペースのトークンに DATABRICKS_TOKEN 設定してください。

個人用アクセス トークン

パーソナルアクセストークンのエクスポート:

export DATABRICKS_TOKEN=<your-personal-access-token>

OAuth

<workspace-url>をAzure DatabricksワークスペースのURLに置き換えてください。 次にAzure Databricks CLIでログインし、短命のOAuthトークンをエクスポートします:

databricks auth login --host https://<workspace-url>
export DATABRICKS_TOKEN=$(databricks auth token --host https://<workspace-url> | jq -r .access_token)

モデルを選んでください

Azure Databricksは、UIのsystem.aiスキーマ下で閲覧できるすぐに使えるモデルを提供しており、サポートされているモデルの完全なリストもこちらでご覧いただけます。

このクイックスタートでは、system.ai.gpt-5-2 を使用します。 別のモデルをクエリするには、その完全修飾名を交換してください。

リクエストを送信してください

<workspace-url>をAzure DatabricksワークスペースのURLに置き換えてください。

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)を開き、「 メトリクス 」タブを選択すると、先ほど送ったリクエストとトークンの使用履歴、遅延が表示されます。 Unity Gatewayの可視性を参照してください。

次のステップ