Skip to main content

Query with the Anthropic Messages API

important

The Anthropic Messages API is only compatible with Anthropic pay per token foundation models and external models. For a unified API that works across all providers, use the Chat Completions API.

The Anthropic Messages API provides native Anthropic SDK compatibility for Claude models on Databricks. Use this API when you need Anthropic-specific features or are migrating existing Anthropic SDK code.

Requirements

  • See Requirements.
  • Install the anthropic package on your compute.

Query examples

The following examples show how to query a Foundation Model API pay-per-token endpoint using the Anthropic Messages API.

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)

Supported models

Databricks-hosted foundation models

  • 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
  • databricks-claude-3-7-sonnet

External models

  • Anthropic model provider
  • Bedrock Anthropic model provider

Additional resources