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: LLMProviderBase

Anthropic Claude API provider implementation.

Provides integration with Anthropic’s Claude models including support for tool/function calling and streaming responses.

__init__()[source]

Initialize the AnthropicProvider instance.

Return type:

None

property name: str

The provider instance id.

Returns:

The anthropic built-in provider id.

Return type:

str

property dialect: ApiDialect

The wire format this provider speaks.

Returns:

Always ApiDialect.MESSAGES.

Return type:

ApiDialect

async connect(credentials)[source]

Connect to Anthropic API.

Parameters:

credentials (ProviderCredentials) – Must contain api_key. api_base is forwarded to the SDK client, and timeout replaces the SDK’s default request timeout when set.

Raises:
Return type:

None

async disconnect()[source]

Disconnect from Anthropic API.

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:

list[ModelInfo]

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:
  • messages (list[Message]) – Conversation history.

  • 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:

tuple[Message, list[ToolCall] | None]

Raises:
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:
  • messages (list[Message]) – Conversation history.

  • 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:
Return type:

AsyncIterator[str]

async cancel_request()[source]

Cancel any in-flight request.

Return type:

None