vendor_connectors.anthropic
Anthropic Connector - Claude AI SDK wrapper for the jbcom ecosystem.
This connector provides Python access to Anthropic’s Claude AI, including the Claude Agent SDK for sandbox/local agent execution.
Usage: from vendor_connectors.anthropic import AnthropicConnector
# Standard API accessconnector = AnthropicConnector(api_key="...")response = connector.create_message( model="claude-sonnet-4-20250514", max_tokens=1024, messages=[{"role": "user", "content": "Hello"}])
# Agent execution (sandbox mode)result = connector.execute_agent_task( task="Implement feature X", working_dir="/path/to/repo")Reference: https://docs.anthropic.com/claude/reference
Submodules
Section titled “Submodules”Package Contents
Section titled “Package Contents”Classes
Section titled “Classes”MessageRole | Message role in conversation. |
|---|---|
ContentBlock | Content block within a message. |
Usage | Token usage information. |
Message | Claude message response. |
Model | Claude model information. |
AgentExecutionResult | Result of agent task execution. |
AnthropicConnector | Anthropic Claude API connector. |
DEFAULT_API_URL | |
|---|---|
DEFAULT_API_VERSION | |
DEFAULT_TIMEOUT | |
DEFAULT_MAX_TOKENS | |
CLAUDE_MODELS |
vendor_connectors.anthropic.DEFAULT_API_URL
Section titled “vendor_connectors.anthropic.DEFAULT_API_URL”vendor_connectors.anthropic.DEFAULT_API_VERSION
Section titled “vendor_connectors.anthropic.DEFAULT_API_VERSION”‘2023-06-01’
vendor_connectors.anthropic.DEFAULT_TIMEOUT
Section titled “vendor_connectors.anthropic.DEFAULT_TIMEOUT”60.0
vendor_connectors.anthropic.DEFAULT_MAX_TOKENS
Section titled “vendor_connectors.anthropic.DEFAULT_MAX_TOKENS”4096
vendor_connectors.anthropic.CLAUDE_MODELS
Section titled “vendor_connectors.anthropic.CLAUDE_MODELS”None
exception vendor_connectors.anthropic.AnthropicError(message: str, status_code: int | None = None, error_type: str | None = None)
Section titled “exception vendor_connectors.anthropic.AnthropicError(message: str, status_code: int | None = None, error_type: str | None = None)”Bases: Exception
Base exception for Anthropic API errors.
Initialization
Section titled “Initialization”Initialize self. See help(type(self)) for accurate signature.
exception vendor_connectors.anthropic.AnthropicAuthError(message: str, status_code: int | None = None, error_type: str | None = None)
Section titled “exception vendor_connectors.anthropic.AnthropicAuthError(message: str, status_code: int | None = None, error_type: str | None = None)”Bases: vendor_connectors.anthropic.AnthropicError
Authentication error.
Initialization
Section titled “Initialization”Initialize self. See help(type(self)) for accurate signature.
exception vendor_connectors.anthropic.AnthropicRateLimitError(message: str, status_code: int | None = None, error_type: str | None = None)
Section titled “exception vendor_connectors.anthropic.AnthropicRateLimitError(message: str, status_code: int | None = None, error_type: str | None = None)”Bases: vendor_connectors.anthropic.AnthropicError
Rate limit exceeded error.
Initialization
Section titled “Initialization”Initialize self. See help(type(self)) for accurate signature.
exception vendor_connectors.anthropic.AnthropicAPIError(message: str, status_code: int | None = None, error_type: str | None = None)
Section titled “exception vendor_connectors.anthropic.AnthropicAPIError(message: str, status_code: int | None = None, error_type: str | None = None)”Bases: vendor_connectors.anthropic.AnthropicError
API error from Anthropic service.
Initialization
Section titled “Initialization”Initialize self. See help(type(self)) for accurate signature.
class vendor_connectors.anthropic.MessageRole
Section titled “class vendor_connectors.anthropic.MessageRole”Message role in conversation.
Initialization
Section titled “Initialization”Initialize self. See help(type(self)) for accurate signature.
‘user’
ASSISTANT
Section titled “ASSISTANT”‘assistant’
class vendor_connectors.anthropic.ContentBlock
Section titled “class vendor_connectors.anthropic.ContentBlock”Bases: pydantic.BaseModel
Content block within a message.
model_config
Section titled “model_config”‘ConfigDict(…)’
‘Field(…)’
‘Field(…)’
‘Field(…)’
‘Field(…)’
input : dict[str, Any] | None
Section titled “input : dict[str, Any] | None”‘Field(…)’
class vendor_connectors.anthropic.Usage
Section titled “class vendor_connectors.anthropic.Usage”Bases: pydantic.BaseModel
Token usage information.
model_config
Section titled “model_config”‘ConfigDict(…)’
input_tokens : int
Section titled “input_tokens : int”‘Field(…)’
output_tokens : int
Section titled “output_tokens : int”‘Field(…)’
class vendor_connectors.anthropic.Message
Section titled “class vendor_connectors.anthropic.Message”Bases: pydantic.BaseModel
Claude message response.
model_config
Section titled “model_config”‘ConfigDict(…)’
‘Field(…)’
‘Field(…)’
role : vendor_connectors.anthropic.MessageRole
Section titled “role : vendor_connectors.anthropic.MessageRole”‘Field(…)’
content : list[vendor_connectors.anthropic.ContentBlock]
Section titled “content : list[vendor_connectors.anthropic.ContentBlock]”‘Field(…)’
model : str
Section titled “model : str”‘Field(…)’
stop_reason : str | None
Section titled “stop_reason : str | None”‘Field(…)’
stop_sequence : str | None
Section titled “stop_sequence : str | None”‘Field(…)’
‘Field(…)’
property text : str
Section titled “property text : str”Get the text content of the message.
class vendor_connectors.anthropic.Model
Section titled “class vendor_connectors.anthropic.Model”Bases: pydantic.BaseModel
Claude model information.
model_config
Section titled “model_config”‘ConfigDict(…)’
‘Field(…)’
display_name : str
Section titled “display_name : str”‘Field(…)’
‘Field(…)’
class vendor_connectors.anthropic.AgentExecutionResult
Section titled “class vendor_connectors.anthropic.AgentExecutionResult”Result of agent task execution.
success : bool
Section titled “success : bool”None
output : str
Section titled “output : str”None
error : str | None
Section titled “error : str | None”None
duration_seconds : float | None
Section titled “duration_seconds : float | None”None
tokens_used : int | None
Section titled “tokens_used : int | None”None
class vendor_connectors.anthropic.AnthropicConnector(api_key: str | None = None, api_version: str = DEFAULT_API_VERSION, timeout: float = DEFAULT_TIMEOUT, logger: lifecyclelogging.Logging | None = None, **kwargs)
Section titled “class vendor_connectors.anthropic.AnthropicConnector(api_key: str | None = None, api_version: str = DEFAULT_API_VERSION, timeout: float = DEFAULT_TIMEOUT, logger: lifecyclelogging.Logging | None = None, **kwargs)”Bases: vendor_connectors.base.VendorConnectorBase
Anthropic Claude API connector.
Provides HTTP client access to Anthropic’s Claude AI API for message generation and agent execution.
Args: api_key: Anthropic API key. Defaults to ANTHROPIC_API_KEY env var. api_version: API version string. Default “2023-06-01”. timeout: Request timeout in seconds. Default 60s. logger: Optional logger instance. **kwargs: Additional DirectedInputsClass arguments.
Example:
connector = AnthropicConnector() response = connector.create_message( … model=”claude-sonnet-4-20250514”, … max_tokens=1024, … messages=[{“role”: “user”, “content”: “Hello”}] … ) print(response.text)
Initialization
Section titled “Initialization”Initialize the connector.
Args: api_key: API key (overrides environment variable) base_url: Base URL (overrides class default) timeout: HTTP timeout in seconds logger: Logger instance **kwargs: Passed to DirectedInputsClass
API_KEY_ENV
Section titled “API_KEY_ENV”‘ANTHROPIC_API_KEY’
BASE_URL
Section titled “BASE_URL”None
_build_headers() → dict[str, str]
Section titled “_build_headers() → dict[str, str]”Build Anthropic-specific headers.
static is_available() → bool
Section titled “static is_available() → bool”Check if API key is available.
Returns: True if ANTHROPIC_API_KEY is set in environment.
static get_available_models() → dict[str, str]
Section titled “static get_available_models() → dict[str, str]”Get dictionary of available Claude models.
Returns: Dictionary mapping model IDs to display names.
_handle_error(response) → None
Section titled “_handle_error(response) → None”Handle API error responses.
Args: response: httpx Response object.
Raises: AnthropicError: Appropriate error type for the response.
create_message(model: str, max_tokens: int, messages: list[dict[str, Any]], system: str | None = None, temperature: float | None = None, top_p: float | None = None, top_k: int | None = None, stop_sequences: list[str] | None = None, tools: list[dict[str, Any]] | None = None, tool_choice: dict[str, Any] | None = None, metadata: dict[str, Any] | None = None) → vendor_connectors.anthropic.Message
Section titled “create_message(model: str, max_tokens: int, messages: list[dict[str, Any]], system: str | None = None, temperature: float | None = None, top_p: float | None = None, top_k: int | None = None, stop_sequences: list[str] | None = None, tools: list[dict[str, Any]] | None = None, tool_choice: dict[str, Any] | None = None, metadata: dict[str, Any] | None = None) → vendor_connectors.anthropic.Message”Create a message using Claude.
Args: model: Model ID (e.g., “claude-sonnet-4-20250514”). max_tokens: Maximum tokens to generate. messages: List of message dicts with role and content. system: Optional system prompt. temperature: Sampling temperature (0-1). top_p: Top-p sampling parameter. top_k: Top-k sampling parameter. stop_sequences: Stop sequences to end generation. tools: Tool definitions for function calling. tool_choice: Tool choice configuration. metadata: Optional metadata for the request.
Returns: Message object with response.
Raises: AnthropicError: If the API request fails.
count_tokens(model: str, messages: list[dict[str, Any]], system: str | None = None, tools: list[dict[str, Any]] | None = None) → int
Section titled “count_tokens(model: str, messages: list[dict[str, Any]], system: str | None = None, tools: list[dict[str, Any]] | None = None) → int”Count tokens for a set of messages.
Args: model: Model ID. messages: List of message dicts. system: Optional system prompt. tools: Optional tool definitions.
Returns: Token count.
Raises: AnthropicError: If the API request fails.
list_models() → list[vendor_connectors.anthropic.Model]
Section titled “list_models() → list[vendor_connectors.anthropic.Model]”List available models from the API.
Returns: List of Model objects.
Raises: AnthropicError: If the API request fails.
get_model(model_id: str) → vendor_connectors.anthropic.Model
Section titled “get_model(model_id: str) → vendor_connectors.anthropic.Model”Get information about a specific model.
Args: model_id: Model identifier.
Returns: Model object with details.
Raises: AnthropicError: If the API request fails.
execute_agent_task(task: str, working_dir: str | None = None, model: str = ‘claude-sonnet-4-5-20250929’, max_tokens: int = DEFAULT_MAX_TOKENS, system_prompt: str | None = None) → vendor_connectors.anthropic.AgentExecutionResult
Section titled “execute_agent_task(task: str, working_dir: str | None = None, model: str = ‘claude-sonnet-4-5-20250929’, max_tokens: int = DEFAULT_MAX_TOKENS, system_prompt: str | None = None) → vendor_connectors.anthropic.AgentExecutionResult”Execute a task using Claude as an agent (sandbox mode).
This is a simplified agent execution pattern for local single-agent workflows. For full agent capabilities, consider using LangChain agents or the agentic-control package.
Args: task: The task description. working_dir: Working directory for execution context. model: Model to use (default: claude-sonnet-4-5-20250929). max_tokens: Maximum tokens per response. system_prompt: Optional custom system prompt.
Returns: AgentExecutionResult with execution details.
Note: This is a simplified synchronous implementation. For production agent workflows with tools and multi-turn conversations, consider using LangChain/LangGraph which will be available in the vendor_connectors.ai sub-package.
validate_model(model_id: str) → bool
Section titled “validate_model(model_id: str) → bool”Check if a model ID is valid.
Args: model_id: Model identifier to validate.
Returns: True if model exists in known models.
get_recommended_model(use_case: str = ‘general’) → str
Section titled “get_recommended_model(use_case: str = ‘general’) → str”Get recommended model for a use case.
Args: use_case: Use case type (“general”, “coding”, “fast”, “powerful”).
Returns: Recommended model ID.