ReqLLM.Providers.Azure.Anthropic (ReqLLM v1.14.0)

View Source

Anthropic model family support for Azure.

Handles Claude models deployed on Azure's infrastructure.

This module acts as a thin adapter between Azure's API and Anthropic's native message format. It delegates to the native Anthropic modules for all format conversion.

Key Differences from Native Anthropic

  • Uses x-api-key header (same as native Anthropic, set by parent Azure provider)
  • URL is /v1/messages (model specified in body, like native Anthropic)
  • The anthropic-version header is set by the parent Azure provider via get_anthropic_headers/2, configurable with anthropic_version option

Prompt Caching Support

Full Anthropic prompt caching is supported. Enable with anthropic_prompt_cache: true option.

Extended Thinking Support

Extended thinking (reasoning) is supported for models that have the capability. Enable with reasoning_effort: :low | :medium | :high option.

Important constraints:

  • Temperature is automatically set to 1.0 when reasoning is enabled, overriding any user-provided value (required by Anthropic)
  • If provider option translation changes temperature after reasoning is enabled, thinking will be disabled
  • Models without reasoning capability will log a warning and ignore reasoning params

Structured Output

Structured output is supported via tool-calling. Use generate_object/4 with a schema.

Note: Native Anthropic's json_schema structured output mode (beta) is not available on Azure. Azure uses the tool-based approach which is stable and well-supported.

Tool Calling

When no explicit tools are provided but the conversation history contains tool_use blocks, stub tool definitions are automatically extracted from the messages to satisfy Anthropic's validation requirements.

Streaming

Streaming is fully supported using the same SSE format as native Anthropic. The parent Azure provider handles attach_stream/4 for building streaming requests; this module provides decode_stream_event/2 for parsing SSE events. Usage information is automatically included in streaming responses.

Summary

Functions

Extracts usage metadata from the response body.

Anthropic Claude models do not support embeddings.

Formats a ReqLLM context into Anthropic request format for Azure.

Decodes Server-Sent Events for streaming responses.

Cleans up thinking config if incompatible with other options.

Parses Anthropic response from Azure into ReqLLM format.

Pre-validates and transforms options for Claude models on Azure. Handles reasoning_effort/reasoning_token_budget translation to thinking config. Warns if json_schema response_format is attempted (not supported on Azure).

Functions

decode_stream_event(event, model)

decode_stream_event(event, model, state)

extract_usage(body, model)

Extracts usage metadata from the response body.

Delegates to the native Anthropic provider.

flush_stream_state(state)

format_embedding_request(model_id, text, opts)

Anthropic Claude models do not support embeddings.

Note: This function should never be called under normal operation. The parent Azure provider validates embedding requests and rejects Claude models with a proper error tuple before reaching this point. This exists only as a safety net for direct formatter calls.

format_request(model_id, context, opts)

Formats a ReqLLM context into Anthropic request format for Azure.

Delegates to the native Anthropic.Context module and adjusts for Azure's deployment-based routing (no model field in body).

For :object operations, creates a synthetic "structured_output" tool to leverage Claude's tool-calling for structured JSON output.

init_stream_state()

Decodes Server-Sent Events for streaming responses.

Delegates to native Anthropic SSE event parsing since Azure uses the same streaming format.

maybe_clean_thinking_after_translation(opts, operation)

Cleans up thinking config if incompatible with other options.

Delegates to shared PlatformReasoning module. See ReqLLM.Providers.Anthropic.PlatformReasoning.maybe_clean_thinking_after_translation/2.

parse_response(body, azure_model, opts)

Parses Anthropic response from Azure into ReqLLM format.

Delegates to the native Anthropic.Response module.

For :object operations, extracts the structured output from the tool call.

Note: Azure responses don't include a "model" field since the deployment determines the model. We use the azure_model.id for response tracking.

pre_validate_options(operation, model, opts)

Pre-validates and transforms options for Claude models on Azure. Handles reasoning_effort/reasoning_token_budget translation to thinking config. Warns if json_schema response_format is attempted (not supported on Azure).