Skip to content

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 access
connector = 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

MessageRoleMessage role in conversation.
ContentBlockContent block within a message.
UsageToken usage information.
MessageClaude message response.
ModelClaude model information.
AgentExecutionResultResult of agent task execution.
AnthropicConnectorAnthropic 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”

https://api.anthropic.com’

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

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.

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.

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.

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.

Initialize self. See help(type(self)) for accurate signature.

class vendor_connectors.anthropic.MessageRole

Section titled “class vendor_connectors.anthropic.MessageRole”

Bases: str, enum.Enum

Message role in conversation.

Initialize self. See help(type(self)) for accurate signature.

‘user’

‘assistant’

class vendor_connectors.anthropic.ContentBlock

Section titled “class vendor_connectors.anthropic.ContentBlock”

Bases: pydantic.BaseModel

Content block within a message.

‘ConfigDict(…)’

‘Field(…)’

‘Field(…)’

‘Field(…)’

‘Field(…)’

‘Field(…)’

Bases: pydantic.BaseModel

Token usage information.

‘ConfigDict(…)’

‘Field(…)’

‘Field(…)’

Bases: pydantic.BaseModel

Claude message response.

‘ConfigDict(…)’

‘Field(…)’

‘Field(…)’

‘Field(…)’

‘Field(…)’

‘Field(…)’

‘Field(…)’

‘Field(…)’

‘Field(…)’

Get the text content of the message.

Bases: pydantic.BaseModel

Claude model information.

‘ConfigDict(…)’

‘Field(…)’

‘Field(…)’

‘Field(…)’

class vendor_connectors.anthropic.AgentExecutionResult

Section titled “class vendor_connectors.anthropic.AgentExecutionResult”

Result of agent task execution.

None

None

None

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)

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

‘ANTHROPIC_API_KEY’

None

Build Anthropic-specific headers.

Check if API key is available.

Returns: True if ANTHROPIC_API_KEY is set in environment.

Get dictionary of available Claude models.

Returns: Dictionary mapping model IDs to display names.

Handle API error responses.

Args: response: httpx Response object.

Raises: AnthropicError: Appropriate error type for the response.

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 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 available models from the API.

Returns: List of Model objects.

Raises: AnthropicError: If the API request fails.

Get information about a specific model.

Args: model_id: Model identifier.

Returns: Model object with details.

Raises: AnthropicError: If the API request fails.

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.

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 for a use case.

Args: use_case: Use case type (“general”, “coding”, “fast”, “powerful”).

Returns: Recommended model ID.