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 providers, use the Open Responses API or 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.

prompt

Genie Code (Agent mode) can do this for you. Try this example prompt:

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.

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-5-5
  • databricks-claude-fable-5-1
  • databricks-claude-opus-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

External models​

  • Anthropic model provider
  • Bedrock Anthropic model provider

Supported input types​

Anthropic Claude models on Databricks accept text and image inputs. See Query vision models for image format and size requirements. For per-model input types, see Detailed list of models supported by Databricks Foundation Model APIs.

Additional resources​