intellicrack.providers.anthropic
Anthropic Claude API provider implementation.
This module provides integration with Anthropic’s Claude models for chat completion and tool/function calling.
- class AnthropicProvider[source]
Bases:
LLMProviderBaseAnthropic Claude API provider implementation.
Provides integration with Anthropic’s Claude models including support for tool/function calling and streaming responses.
- property name: str
The provider instance id.
- Returns:
The
anthropicbuilt-in provider id.- Return type:
- property dialect: ApiDialect
The wire format this provider speaks.
- Returns:
Always
ApiDialect.MESSAGES.- Return type:
- async connect(credentials)[source]
Connect to Anthropic API.
- Parameters:
credentials (ProviderCredentials) – Must contain api_key.
api_baseis forwarded to the SDK client, andtimeoutreplaces the SDK’s default request timeout when set.- Raises:
AuthenticationError – If API key is invalid.
ProviderError – If connection fails.
- Return type:
None
- async list_models()[source]
Dynamically fetch available Claude models from Anthropic API.
Uses the /v1/models endpoint to retrieve the current list of available models, handling pagination as needed.
- Returns:
List of available Claude models with their capabilities.
- Return type:
- Raises:
ProviderError – If not connected or the request fails.
- async chat(messages, model, tools=None, temperature=0.7, max_tokens=4096, tool_choice=None, thinking=None, *, enable_cache=False)[source]
Send a chat completion request to Claude.
- Parameters:
model (str) – Model ID to use.
tools (list[ToolDefinition] | None) – Available tools for function calling.
temperature (float) – Sampling temperature.
max_tokens (int) – Maximum tokens in response.
tool_choice (ToolChoice | None) – How the model should select tools.
thinking (ThinkingConfig | None) – Extended thinking configuration.
enable_cache (bool) – Whether to enable prompt caching.
- Returns:
Tuple of (assistant message, tool calls if any).
- Return type:
- Raises:
ProviderError – If not connected or request fails.
RateLimitError – If rate limited.
- async chat_stream(messages, model, tools=None, temperature=0.7, max_tokens=4096, tool_choice=None, thinking=None, *, enable_cache=False)[source]
Stream a chat completion response from Claude.
- Parameters:
model (str) – Model ID to use.
tools (list[ToolDefinition] | None) – Available tools for function calling.
temperature (float) – Sampling temperature.
max_tokens (int) – Maximum tokens in response.
tool_choice (ToolChoice | None) – How the model should select tools.
thinking (ThinkingConfig | None) – Extended thinking configuration.
enable_cache (bool) – Whether to enable prompt caching.
- Yields:
str – Text chunks as they arrive.
- Raises:
ProviderError – If not connected or request fails.
RateLimitError – If rate limited.
- Return type:
AsyncIterator[str]