aeat.adapters.outbound.llm._providers.base module

Provider adapter contract for the LLM outbound subpackage.

Defines the normalized request and response shapes that every concrete provider adapter (Anthropic, OpenAI, Gemini, local, deterministic) consumes and produces, so the higher-level LLMClient can stay provider-agnostic. Adapters live in sibling modules under adapters.outbound.llm._providers.

class ProviderRequest(**data)[source]

Bases: BaseModel

Normalized inbound payload passed to a provider adapter.

Variables:
  • request_id – Stable opaque hash identifying the public request, suitable for cross-referencing cache and usage records.

  • model – Fully resolved provider model identifier.

  • prompt – Rendered prompt text sent to the provider.

  • system – Optional system prompt prepended to the conversation.

  • max_tokens – Maximum number of output tokens to request.

  • temperature – Sampling temperature in the inclusive range [0.0, 1.0].

  • timeout_s – Per-request timeout in seconds.

  • images – Base64-encoded on-host-prepared image inputs for a multimodal read (empty for a text-only request). Transient and in-memory only; a provider adapter forwards them to a local vision model and they are never persisted (sensitive-financial-data-secure-storage-only).

Parameters:
request_id: str
model: str
prompt: str
system: str | None
max_tokens: int
temperature: float
timeout_s: int
images: tuple[str, ...]
class ProviderCompletion(**data)[source]

Bases: BaseModel

Normalized provider response returned to the public client.

Variables:
  • text – Generated text payload.

  • model – Provider model that actually served the request (may differ from the requested model when a vendor performs upstream routing).

  • input_tokens – Provider-reported prompt token count.

  • output_tokens – Provider-reported output token count.

  • provider_request_id – Provider-native request or message id when available, otherwise None.

Parameters:
  • text (str)

  • model (str)

  • input_tokens (int)

  • output_tokens (int)

  • provider_request_id (str | None)

text: str
model: str
input_tokens: int
output_tokens: int
provider_request_id: str | None
parse_retry_after(value)[source]

Parse an HTTP Retry-After header value into seconds.

Parameters:

value (str | None) – Raw header value, or None when the header is absent.

Return type:

float | None

Returns:

Number of seconds to wait, or None when the value is missing or not a plain numeric string.

raise_rate_limit(message, retry_after)[source]

Raise a normalized rate-limit error with parsed retry hint.

Parameters:
  • message (str) – Human-readable error message to attach.

  • retry_after (str | None) – Raw Retry-After header value supplied by the provider.

Raises:

LLMRateLimitError – Always raised with the parsed retry hint.

Return type:

None

check_http_error(response, *, provider_name, model, logger)[source]

Raise a normalized error for a non-2xx LLM HTTP response.

A 429 raises a rate-limit error carrying the parsed Retry-After hint; any other 5xx or 4xx status raises a provider error. Shared by the OpenAI and Gemini adapters, whose status-dispatch was otherwise identical.

Parameters:
  • response (Response) – Provider HTTP response to inspect.

  • provider_name (str) – Human-readable provider label for log and error text.

  • model (str) – Model identifier, included in the log context.

  • logger (Logger) – Adapter logger for status diagnostics.

Raises:
Return type:

None