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 Azure Databricks. Use this API when you need Anthropic-specific features or are migrating existing Anthropic SDK code.

Note

To constrain Claude output to a JSON schema with the Anthropic Messages API, use the format field of output_config. This is supported for databricks-claude-opus-5-5, databricks-claude-sonnet-5-5, and databricks-claude-haiku-5-5. These models, and databricks-claude-fable-5-1, do not support the response_format parameter of the Chat Completions API, which returns an HTTP 400 error. For supported models and constraints, see Structured outputs on Azure Databricks.

Tip

Genie Code can do this for you. Try this example prompt:

Query the system.ai.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

Note

The following examples are based on Unity Gateway and model services. If you use model serving endpoints instead of model services, replace the model service name with an endpoint name. See Detailed list of models supported by Databricks Foundation Model APIs for a list of available foundation models and their model service and endpoint names.

The following examples show how to query a Foundation Model API pay-per-token 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://example.staging.cloud.databricks.com/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)

REST API

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

Supported models

Databricks-hosted foundation models

  • system.ai.claude-opus-5-5
  • system.ai.claude-fable-5-1
  • system.ai.claude-opus-5
  • system.ai.claude-sonnet-5-5
  • system.ai.claude-sonnet-5
  • system.ai.claude-opus-4-8
  • system.ai.claude-opus-4-7
  • system.ai.claude-opus-4-6
  • system.ai.claude-sonnet-4-6
  • system.ai.claude-sonnet-4-5
  • system.ai.claude-haiku-5-5
  • system.ai.claude-haiku-4-5
  • system.ai.claude-opus-4-5
  • system.ai.claude-opus-4-1

External models

  • Anthropic model provider
  • Bedrock Anthropic model provider

Supported input types

Anthropic Claude models on Azure 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