Abfrage mit der Anthropic Messages-API

Von Bedeutung

Die Anthropic Messages-API ist nur mit Anthropic Pay per Token Foundation-Modellen und externen Modellen kompatibel. Verwenden Sie für eine einheitliche API, die anbieterübergreifend funktioniert, die Api für offene Antworten oder die Chatabschluss-API.

Die Anthropic Messages-API bietet native Anthropic SDK-Kompatibilität für Claude-Modelle auf Azure Databricks. Verwenden Sie diese API, wenn Sie anthropic-spezifische Features benötigen oder vorhandene Anthropic SDK-Code migrieren.

Tip

Genie Code (Agent-Modus) kann dies für Sie tun. Probieren Sie diese Beispielaufforderung aus:

Query the databricks-claude-sonnet-4-5 model using the Anthropic Messages API with Bearer token auth and the workspace's anthropic base URL. Send a user message and print the response text.

Anforderungen

  • Siehe Anforderungen.
  • Installieren Sie das anthropic Paket auf Ihrem Computer.

Abfragebeispiele

Die folgenden Beispiele zeigen, wie Sie einen Foundation Model-API-Pay-per-Token-Endpunkt mithilfe der Anthropic Messages-API abfragen.

Python

import anthropic
import os

DATABRICKS_TOKEN = os.environ.get('DATABRICKS_TOKEN')

client = anthropic.Anthropic(
    api_key="unused",
    base_url="https://example.staging.cloud.databricks.com/serving-endpoints/anthropic",
    default_headers={
        "Authorization": f"Bearer {DATABRICKS_TOKEN}",
    },
)

message = client.messages.create(
    model="databricks-claude-sonnet-4-5",
    max_tokens=256,
    messages=[
        {"role": "user", "content": "What is a mixture of experts model?"},
    ],
)

print(message.content[0].text)

REST API

curl \
-u token:$DATABRICKS_TOKEN \
-X POST \
-H "Content-Type: application/json" \
-d '{
  "model": "databricks-claude-sonnet-4-5",
  "max_tokens": 256,
  "messages": [
    {
      "role": "user",
      "content": "What is a mixture of experts model?"
    }
  ]
}' \
https://<workspace_host>.databricks.com/serving-endpoints/anthropic/v1/messages

Unterstützte Modelle

Von Databricks gehostete Foundation-Modelle

  • databricks-claude-opus-5-5
  • databricks-claude-fable-5-1
  • databricks-claude-opus-5
  • databricks-claude-sonnet-5-5
  • databricks-claude-sonnet-5
  • databricks-claude-opus-4-8
  • databricks-claude-opus-4-7
  • databricks-claude-opus-4-6
  • databricks-claude-sonnet-4-6
  • databricks-claude-sonnet-4-5
  • databricks-claude-haiku-4-5
  • databricks-claude-opus-4-5
  • databricks-claude-opus-4-1
  • databricks-claude-sonnet-4

Externe Modelle

  • Anbieter anthropischer Modelle
  • Bedrock Anthropic-Modellanbieter

Unterstützte Eingabetypen

Anthropic Claude-Modelle auf Azure Databricks können Text- und Bildeingaben akzeptieren. Siehe Abfrage-Vision-Modelle für Bildformat- und Größenanforderungen. Für Eingabetypen pro Modell siehe Detaillierte Liste der von Databricks Foundation Model APIs unterstützten Modelle.

Weitere Ressourcen