> Version notice: This site documents BAML v0, the legacy DSL. BAML v1 is a separate, fully featured programming language in public beta. If the user intends to use BAML v1, ignore this site's content and use the BAML v1 documentation instead. If the intended version is unclear, clarify it before using this page. > For clean Markdown of any page, append .md to the page URL. For the complete documentation index, see https://docs.boundaryml.com/llms.txt. For MCP access, connect to https://docs.boundaryml.com/_mcp/server. # anthropic The `anthropic` provider supports all APIs that use the same interface for the `/v1/messages` endpoint. Example: **`BAML`** ```baml BAML client MyClient { provider anthropic options { model "claude-sonnet-4-20250514" temperature 0 } } ``` ## BAML-specific request `options` These unique parameters (aka `options`) modify the API request sent to the provider. You can use this to modify the `headers` and `base_url` for example. **`api_key`** `string` Will be passed as a bearer token. **Default: `env.ANTHROPIC_API_KEY`** `Authorization: Bearer $api_key` --- **`base_url`** `string` The base URL for the API. **Default: `https://api.anthropic.com`** --- **`headers`** `object` Additional headers to send with the request. Unless specified with a different value, we inject in the following headers: ``` "anthropic-version" "2023-06-01" ``` Example: ```baml client MyClient { provider anthropic options { api_key env.MY_ANTHROPIC_KEY model "claude-sonnet-4-20250514" headers { "X-My-Header" "my-value" } } } ``` --- **`default_role`** `string` The role to use if the role is not in the allowed\_roles. **Default: `"user"` usually, but some models like OpenAI's `gpt-5` will use `"system"`** Picked the first role in `allowed_roles` if not "user", otherwise "user". --- **`allowed_roles`** `string[]` Which roles should we forward to the API? **Default: `["system", "user", "assistant"]` usually, but some models like OpenAI's `o1-mini` will use `["user", "assistant"]`** When building prompts, any role not in this list will be set to the `default_role`. --- **`remap_roles`** `map` A mapping to transform role names before sending to the API. **Default: `{}`** (no remapping) For google-ai provider, the default is: `{ "assistant": "model" }` This allows you to use standard role names in your prompts (like "user", "assistant", "system") but send different role names to the API. The remapping happens after role validation and default role assignment. **Example:** ```json { "user": "human", "assistant": "ai", } ``` With this configuration, `{{ _.role("user") }}` in your prompt will result in a message with role "human" being sent to the API. --- **`allowed_role_metadata`** `string[]` Which role metadata should we forward to the API? **Default: `[]`** For example you can set this to `["cache_control"]` to forward the cache policy to the API. If you do not set `allowed_role_metadata`, we will not forward any role metadata to the API even if it is set in the prompt. Then in your prompt you can use something like: ```baml client ClaudeWithCaching { provider anthropic options { model claude-3-5-haiku-20241022 api_key env.ANTHROPIC_API_KEY max_tokens 1000 allowed_role_metadata ["cache_control"] headers { "anthropic-beta" "prompt-caching-2024-07-31" } } } client FooWithout { provider anthropic options { } } template_string Foo() #" {{ _.role('user', cache_control={"type": "ephemeral"}) }} This will be cached for ClaudeWithCaching, but not for FooWithout! {{ _.role('user') }} This will not be cached for Foo or FooWithout! "# ``` You can use the playground to see the raw curl request to see what is being sent to the API. --- **`supports_streaming`** `boolean` Whether the internal LLM client should use the streaming API. **Default: `true`** Then in your prompt you can use something like: ```baml client MyClientWithoutStreaming { provider anthropic options { model claude-3-5-haiku-20241022 api_key env.ANTHROPIC_API_KEY max_tokens 1000 supports_streaming false } } function MyFunction() -> string { client MyClientWithoutStreaming prompt #"Write a short story"# } ``` ```python # This will be streamed from your python code perspective, # but under the hood it will call the non-streaming HTTP API # and then return a streamable response with a single event b.stream.MyFunction() # This will work exactly the same as before b.MyFunction() ``` --- **`finish_reason_allow_list`** `string[]` Which finish reasons are allowed? **Default: `null`** > **Warning** > > version 0.73.0 onwards: This is case insensitive. Will raise a `BamlClientFinishReasonError` if the finish reason is not in the allow list. See [Exceptions](/guide/baml-basics/error-handling#bamlclientfinishreasonerror) for more details. Note, only one of `finish_reason_allow_list` or `finish_reason_deny_list` can be set. For example you can set this to `["stop"]` to only allow the stop finish reason, all other finish reasons (e.g. `length`) will treated as failures that PREVENT fallbacks and retries (similar to parsing errors). Then in your code you can use something like: ```baml client MyClient { provider "openai" options { model "gpt-5-mini" api_key env.OPENAI_API_KEY // Finish reason allow list will only allow the stop finish reason finish_reason_allow_list ["stop"] } } ``` --- **`finish_reason_deny_list`** `string[]` Which finish reasons are denied? **Default: `null`** > **Warning** > > version 0.73.0 onwards: This is case insensitive. Will raise a `BamlClientFinishReasonError` if the finish reason is in the deny list. See [Exceptions](/guide/baml-basics/error-handling#bamlclientfinishreasonerror) for more details. Note, only one of `finish_reason_allow_list` or `finish_reason_deny_list` can be set. For example you can set this to `["length"]` to stop the function from continuing if the finish reason is `length`. (e.g. LLM was cut off because it was too long). Then in your code you can use something like: ```baml client MyClient { provider "openai" options { model "gpt-5-mini" api_key env.OPENAI_API_KEY // Finish reason deny list will allow all finish reasons except length finish_reason_deny_list ["length"] } } ``` --- ### `media_url_handler` Controls how media URLs are processed before sending to the provider. This allows you to override the default behavior for handling images, audio, PDFs, and videos. ```baml client MyClient { provider openai options { media_url_handler { image "send_base64" // Options: send_base64 | send_url | send_url_add_mime_type | send_base64_unless_google_url audio "send_url" pdf "send_url_add_mime_type" video "send_url" } } } ``` #### Options Each media type can be configured with one of these modes: * **`send_base64`** - Always download URLs and convert to base64 data URIs * **`send_url`** - Pass URLs through unchanged to the provider * **`send_url_add_mime_type`** - Ensure MIME type is present (may require downloading to detect) * **`send_base64_unless_google_url`** - Only process non-gs\:// URLs (keep Google Cloud Storage URLs as-is) #### Provider Defaults If not specified, each provider uses these defaults: | Provider | Image | Audio | PDF | Video | | ------------ | ------------------------------- | ------------------------ | ------------- | ---------- | | OpenAI | `send_url` | `send_base64` | `send_url` | `send_url` | | Anthropic | `send_url` | `send_url` | `send_base64` | `send_url` | | Google AI | `send_base64_unless_google_url` | `send_url` | `send_url` | `send_url` | | Vertex AI | `send_url_add_mime_type` | `send_url_add_mime_type` | `send_url` | `send_url` | | AWS Bedrock | `send_base64` | `send_base64` | `send_base64` | `send_url` | | Azure OpenAI | `send_url` | `send_base64` | `send_url` | `send_url` | #### When to Use * **Use `send_base64`** when your provider doesn't support external URLs and you need to embed media content * **Use `send_url`** when your provider handles URL fetching and you want to avoid the overhead of base64 conversion * **Use `send_url_add_mime_type`** when your provider requires MIME type information (e.g., Vertex AI) * **Use `send_base64_unless_google_url`** when working with Google Cloud Storage and want to preserve gs\:// URLs > **Warning** > > URL fetching happens at request time and may add latency. Consider caching or pre-converting frequently used media when using `send_base64` mode. > **Note** > > Anthropic's default behavior is to convert 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. ## Provider request parameters These are other parameters that are passed through to the provider, without modification by BAML. For example if the request has a `temperature` field, you can define it in the client here so every call has that set. Consult the specific provider's documentation for more information. **`system`** `DO NOT USE` BAML will auto construct this field for you from the prompt, if necessary. Only the first system message will be used, all subsequent ones will be cast to the `assistant` role. --- **`messages`** `DO NOT USE` BAML will auto construct this field for you from the prompt --- **`stream`** `DO NOT USE` BAML will auto construct this field for you based on how you call the client in your code --- **`model`** `string` The model to use. | Model | Use Case | Release | Context | Features | | ----------------------------- | ------------------------- | -------- | ------- | ----------------------- | | **claude-opus-4-1-20250805** | Complex coding, AI agents | Aug 2025 | 200K | Most powerful reasoning | | **claude-sonnet-4-20250514** | Default choice, versatile | May 2025 | 200K-1M | Hybrid reasoning modes | | **claude-3-5-haiku-20241022** | Fast, cost-efficient | Oct 2024 | 200K | Speed optimized | ![](https://mintlify.s3-us-west-1.amazonaws.com/anthropic/images/3-5-sonnet-curve.png) See anthropic docs for the latest list of all models. You can pass any model name you wish, we will not check if it exists. --- **`max_tokens`** `int` The maximum number of tokens to generate. **Default: `4069`** --- For all other options, see the [official anthropic API documentation](https://docs.anthropic.com/en/api/messages).