透過 Unity Gateway 向相容的 OpenAI 端點發送你的第一個請求。
要求
- 一個位於 Unity Gateway 支援區域的 Azure Databricks workspace。
- 要用 OAuth 認證,安裝 Azure Databricks CLI。 或者,可以使用個人存取權杖,這不需要 Azure Databricks CLI。
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 可觀察性。