aeat.adapters.outbound.llm._providers.anthropic module

Anthropic Messages API adapter for the LLM outbound port.

Implements the _ProviderAdapter contract by translating a normalized ProviderRequest into an anthropic.AsyncAnthropic messages.create call and converting the response (or any provider error) into the substrate’s typed completion / error envelope. Network I/O is async; all SDK exceptions are mapped to LLMProviderError, LLMRateLimitError, or LLMConfigError.

class AnthropicAdapter(api_key, timeout_s)[source]

Bases: _ProviderAdapter

Provider adapter that talks to Anthropic’s Messages API.

Holds a bound anthropic.AsyncAnthropic client configured with the operator’s API key and a per-call timeout. The provider class attribute identifies this adapter to the adapters.outbound.llm factory.

Variables:

provider – The LLMProvider tag selecting this adapter.

Parameters:
  • api_key (str)

  • timeout_s (int)

provider: LLMProvider
async complete(request)[source]

Execute a completion request against Anthropic and normalize the result.

Issues a messages.create call (with or without a system prompt), concatenates every anthropic.types.TextBlock in the response, and returns a ProviderCompletion. SDK errors are mapped to the substrate’s typed exception hierarchy.

Parameters:

request (ProviderRequest) – Normalized provider request carrying the model id, prompt, optional system prompt, sampling parameters, and a request-id used as Anthropic metadata.user_id.

Return type:

ProviderCompletion

Returns:

A ProviderCompletion with the joined text, model id echoed by the server, token usage, and the provider’s request id.

Raises:

LLMProviderError – On authentication failures, bad requests, connection or timeout failures, and non-2xx API status codes.