ReqLLM.Providers.AmazonBedrock.Anthropic (ReqLLM v1.26.0)

View Source

Anthropic model family support for AWS Bedrock.

Handles Claude models (Claude 3 Sonnet, Haiku, Opus, etc.) on AWS Bedrock.

This module acts as a thin adapter between Bedrock's AWS-specific wrapping and Anthropic's native message format. It delegates to the native Anthropic modules for all format conversion.

Prompt Caching Support

Enable with prompt_cache: true. The Bedrock caching options are bridged to Anthropic cache_control on both the native InvokeModel API and the bedrock-mantle Messages API. With tools present the request routes through the Converse API by default.

Summary

Functions

Extracts usage metadata from the response body.

Formats a ReqLLM context into Anthropic request format for Bedrock.

Anthropic headers for the bedrock-mantle Messages API.

Parses Anthropic response from Bedrock into ReqLLM format.

Parses a streaming chunk for Anthropic models.

Preserve inference profile prefix for all Anthropic models.

Returns whether this model family supports toolChoice in Bedrock Converse API.

Functions

extract_usage(body, model)

Extracts usage metadata from the response body.

Delegates to the native Anthropic provider.

Note: AWS Bedrock does not return a separate reasoning_tokens field in its response structure. Extended thinking tokens are included in output_tokens and billed accordingly, but Bedrock's API response only provides input_tokens and output_tokens. This differs from Anthropic's direct API which returns reasoning_tokens as a separate field.

format_request(model_id, context, opts)

Formats a ReqLLM context into Anthropic request format for Bedrock.

Delegates to the native Anthropic.Context module and adds Bedrock-specific version parameter.

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

mantle_headers(opts)

Anthropic headers for the bedrock-mantle Messages API.

parse_response(body, opts)

Parses Anthropic response from Bedrock into ReqLLM format.

Delegates to the native Anthropic.Response module.

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

parse_stream_chunk(chunk, opts)

Parses a streaming chunk for Anthropic models.

Unwraps the Bedrock-specific encoding then delegates to native Anthropic SSE event parsing.

preserve_inference_profile?(model_id)

Preserve inference profile prefix for all Anthropic models.

All Anthropic inference profile models require the region prefix to be preserved in the API request path.

supports_converse_tool_choice?()

Returns whether this model family supports toolChoice in Bedrock Converse API.