Skip to main content
The anthropic provider supports the Anthropic /v1/messages endpoint for Claude models.

Quick Start

client<llm> MyClient {
  provider "anthropic"
  options {
    model "claude-sonnet-4-20250514"
    temperature 0
  }
}

Authentication

Set your Anthropic API key as an environment variable:
export ANTHROPIC_API_KEY="your-api-key-here"
Or specify it explicitly in your BAML configuration:
client<llm> MyClient {
  provider "anthropic"
  options {
    api_key env.MY_ANTHROPIC_KEY
    model "claude-sonnet-4-20250514"
  }
}

Configuration Options

BAML-Specific Options

These options modify the API request sent to Anthropic.
api_key
string
default:"env.ANTHROPIC_API_KEY"
Passed as a bearer token in the Authorization header: Authorization: Bearer $api_key
base_url
string
default:"https://api.anthropic.com"
The base URL for the Anthropic API.
headers
object
Additional headers to send with requests.Unless specified, BAML injects this default header:
"anthropic-version": "2023-06-01"
Example:
client<llm> MyClient {
  provider "anthropic"
  options {
    api_key env.MY_ANTHROPIC_KEY
    model "claude-sonnet-4-20250514"
    headers {
      "X-My-Header" "my-value"
    }
  }
}

Supported Models

model
string
required
The Claude model to use.
ModelUse CaseReleaseContextFeatures
claude-opus-4-1-20250805Complex coding, AI agentsAug 2025200KMost powerful reasoning
claude-sonnet-4-20250514Default choice, versatileMay 2025200K-1MHybrid reasoning modes
claude-3-5-haiku-20241022Fast, cost-efficientOct 2024200KSpeed optimized
You can specify any model name - BAML won’t validate whether it exists.See the Anthropic documentation for the latest models.

Model Parameters

These parameters are passed directly to the Anthropic API.
max_tokens
int
default:"4069"
The maximum number of tokens to generate.
Common parameters:
  • temperature - Controls randomness (0-1)
  • max_tokens - Maximum tokens to generate (required by Anthropic)
  • top_p - Nucleus sampling parameter
  • top_k - Top-k sampling parameter
  • stop_sequences - Array of sequences that stop generation
For all options, see the Anthropic API documentation.

Media Handling

Anthropic’s default behavior converts PDFs to base64 (send_base64) while keeping other media types as URLs (send_url). This is because Anthropic’s API requires PDFs to be base64-encoded.

Features

  • Streaming: Supported for real-time response generation
  • Multimodal: Supports text, image, and PDF inputs
  • Extended Thinking: Available with Opus-4 and Sonnet-4 models
  • Tool Use: Native support for function calling

System Messages

BAML automatically constructs the system field from your prompt if necessary. Only the first system message is used; subsequent ones are cast to the assistant role.

Do Not Set

system
DO NOT USE
BAML automatically constructs this from your prompt.
messages
DO NOT USE
BAML automatically constructs this from your prompt.
stream
DO NOT USE
BAML automatically sets this based on how you call the client in your code.

Build docs developers (and LLMs) love