module

Crig::Providers::Anthropic

Constants

ANTHROPIC_API_BASE_URL = "https://api.anthropic.com"
ANTHROPIC_RAW_CONTENT_KEY = "anthropic_content"
ANTHROPIC_VERSION_2023_01_01 = "2023-01-01"
ANTHROPIC_VERSION_2023_06_01 = "2023-06-01"
ANTHROPIC_VERSION_LATEST = "2023-06-01"
CLAUDE_3_5_HAIKU = "claude-3-5-haiku-latest"
CLAUDE_3_5_SONNET = "claude-3-5-sonnet-latest"
CLAUDE_3_7_SONNET = "claude-3-7-sonnet-latest"
CLAUDE_4_OPUS = "claude-opus-4-0"
CLAUDE_4_SONNET = "claude-sonnet-4-0"
CLAUDE_HAIKU_4_5 = "claude-haiku-4-5"
CLAUDE_OPUS_4_6 = "claude-opus-4-6"
CLAUDE_OPUS_4_7 = "claude-opus-4-7"
CLAUDE_SONNET_4_6 = "claude-sonnet-4-6"

Class methods

apply_cache_control(system : Array(SystemContent), messages : Array(Message)) : Nil
Source
calculate_max_tokens(model : String) : Int64 | Nil
Source
calculate_max_tokens_custom(model : String) : Int64
Source
coerce_tool_input(input : JSON::Any) : JSON::Any

The Anthropic Messages API requires tool_use.input to be a JSON OBJECT. ToolCall.function.arguments can arrive as a JSON-encoded STRING or as null/empty; coerce to an object at the send boundary.

Source
handle_event(event : StreamingEvent, current_tool_call : ToolCallState | Nil, current_thinking : ThinkingState | Nil) : Tuple(Crig::RawStreamingChoice(StreamingCompletionResponse) | Nil, ToolCallState | Nil, ThinkingState | Nil)

ameba:disable Metrics/CyclomaticComplexity

Source
normalize_anthropic_base_url(base_url : String) : String
Source
parse_sse_events(text : String) : Array(StreamingEvent)
Source
sanitize_schema(schema : JSON::Any) : JSON::Any
Source
split_system_messages_from_history(history : Array(Crig::Completion::Message), preserve_mid_conversation : Bool) : Tuple(Array(String), Array(Crig::Completion::Message))
Source
supports_mid_conversation_system_messages?(model : String) : Bool
Source

Nested types