Unity Gateway Schnellstart

Senden Sie Ihre erste Anfrage über das Unity Gateway an den OpenAI-kompatiblen Endpunkt.

Anforderungen

Authenticate

Um zu starten, benutze ein persönliches Zugangstoken. OAuth wird für Produktionsanwendungen empfohlen. Setze das Token DATABRICKS_TOKEN für deinen Arbeitsbereich ein.

Persönliches Zugriffstoken

Exportiere einen persönlichen Zugriffstoken:

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

OAuth

Ersetzen Sie <workspace-url> durch die URL Ihres Azure Databricks-Arbeitsbereichs. Melden Sie sich dann mit der Azure Databricks CLI an und exportieren Sie ein kurzlebiges OAuth-Token:

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

Wählen Sie ein Modell aus

Azure Databricks stellt einsatzbereite Modelle bereit, die Sie in der Benutzeroberfläche unter dem Schema system.ai durchsuchen oder die vollständige Liste der unterstützten Modelle hier ansehen können.

In dieser Schnellstartanleitung wird system.ai.gpt-5-2 verwendet. Um ein anderes Modell abzufragen, tauschen Sie seinen voll qualifizierten Namen ein.

Senden Sie Ihre Anfrage ab

Ersetzen Sie <workspace-url> durch Ihre Azure Databricks Arbeitsbereichs-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);

Sieh dir deine Anfrage an

Öffnen Sie das Modell, das Sie () abgefragt habensystem.ai.gpt-5-2, im Katalog-Explorer und wählen Sie den Tab Metrics, um die gerade gesendete Anfrage in der Nutzungshistorie sowie deren Token-Nutzung und Latenz zu sehen. Siehe Unity Gateway Observability.

Nächste Schritte