ReqLLM.Providers.Anthropic (ReqLLM v1.0.0)
View SourceProvider implementation for Anthropic Claude models.
Supports Claude 3 models including:
- claude-3-5-sonnet-20241022
- claude-3-5-haiku-20241022
- claude-3-opus-20240229
Key Differences from OpenAI
- Uses
/v1/messagesendpoint instead of/chat/completions - Different authentication:
x-api-keyheader instead ofAuthorization: Bearer - Different message format with content blocks
- Different response structure with top-level
roleandcontent - System messages are included in the messages array, not separate
- Tool calls use different format with content blocks
Usage
iex> ReqLLM.generate_text("anthropic:claude-3-5-sonnet-20241022", "Hello!")
{:ok, response}
Summary
Functions
Default implementation of attach/3.
Default implementation of attach_stream/4.
Default implementation of decode_response/1.
Default implementation of decode_stream_event/2.
Callback implementation for ReqLLM.Provider.default_env_key/0.
Default implementation of encode_body/1.
Default implementation of extract_usage/2.
Maps reasoning effort levels to token budgets.
Default implementation of prepare_request/4.
Convert a ReqLLM.Tool to Anthropic's tool format.
Default implementation of translate_options/3.
Functions
Default implementation of attach/3.
Sets up Bearer token authentication and standard pipeline steps.
Default implementation of attach_stream/4.
Builds complete streaming requests using OpenAI-compatible format.
Default implementation of decode_response/1.
Handles success/error responses with standard ReqLLM.Response creation.
Default implementation of decode_stream_event/2.
Decodes SSE events using OpenAI-compatible format.
Callback implementation for ReqLLM.Provider.default_env_key/0.
Default implementation of encode_body/1.
Encodes request body using OpenAI-compatible format for chat and embedding operations.
Default implementation of extract_usage/2.
Extracts usage data from standard usage field in response body.
Maps reasoning effort levels to token budgets.
This is the canonical source of truth for Anthropic reasoning effort mappings, used by all providers hosting Anthropic models.
:low→ 1,024 tokens:medium→ 2,048 tokens:high→ 4,096 tokens
Examples
iex> ReqLLM.Providers.Anthropic.map_reasoning_effort_to_budget(:low)
1024
iex> ReqLLM.Providers.Anthropic.map_reasoning_effort_to_budget("medium")
2048
Default implementation of prepare_request/4.
Handles :chat, :object, and :embedding operations using OpenAI-compatible patterns.
Convert a ReqLLM.Tool to Anthropic's tool format.
This is made public so that Bedrock and Vertex formatters can reuse it.
Default implementation of translate_options/3.
Pass-through implementation that returns options unchanged.