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:
_ProviderAdapterProvider adapter that talks to Anthropic’s Messages API.
Holds a bound
anthropic.AsyncAnthropicclient configured with the operator’s API key and a per-call timeout. Theproviderclass attribute identifies this adapter to theadapters.outbound.llmfactory.- Variables:
provider – The
LLMProvidertag selecting this adapter.- Parameters:
-
provider:
LLMProvider¶
- async complete(request)[source]¶
Execute a completion request against Anthropic and normalize the result.
Issues a
messages.createcall (with or without asystemprompt), concatenates everyanthropic.types.TextBlockin the response, and returns aProviderCompletion. 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 Anthropicmetadata.user_id.- Return type:
- Returns:
A
ProviderCompletionwith 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.