Skip to main content

Query model services with the Anthropic Messages API

Beta

This feature is in Beta. Account admins can control access to this feature from the account console Previews page. See Manage Databricks previews.

important

The Anthropic Messages API is only compatible with Anthropic foundation 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 model service 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://<workspace-url>/ai-gateway/anthropic",
default_headers={
"Authorization": f"Bearer {DATABRICKS_TOKEN}",
},
)

message = client.messages.create(
model="system.ai.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

important

Anthropic Claude 3.7 Sonnet will be retired on April 12, 2026. See Retired models for the recommended replacement model and guidance for how to migrate during deprecation.

  • 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

Supported input types

Anthropic Claude models on Databricks accept text and image inputs. See Query foundation models by type for image format and size requirements. For per-model input types, see Databricks-hosted foundation models available in Foundation Model APIs.

Additional resources