Normalized error returned by every provider operation.
Providers speak different error dialects; this struct gives callers one
vocabulary. The :type classifies what went wrong, :retryable? says
whether retrying could plausibly succeed, and :raw always preserves the
original body so nothing is lost in translation.
case ExAgent.chat(agent, "hello") do
{:ok, message} -> message
{:error, %ExAgent.Error{retryable?: true}} -> retry_with_backoff()
{:error, %ExAgent.Error{} = error} -> Logger.error(error.message)
endThis is also an exception, so it can be raised where a return value is not
available (see ExAgent.Provider.stream/3).
Types
| Type | Meaning | Retryable |
|---|---|---|
:auth | Bad or missing credentials (401, 403) | no |
:not_found | Unknown model or resource (404) | no |
:timeout | Request timed out (408, transport timeout) | yes |
:rate_limit | Rate or quota limit hit (429) | yes |
:context_length | Input exceeds the model's context window | no |
:invalid_request | Malformed request (other 4xx) | no |
:unsupported | The provider cannot perform this operation | no |
:server | Provider-side failure (5xx, unexpected response shape) | yes for 5xx |
:transport | Connection-level failure | yes |
Summary
Functions
Classifies a non-success HTTP response into a normalized error.
Normalizes a Req result into {:ok, body} or {:error, t()}.
Classifies a connection-level failure into a normalized error.
Builds an error that did not originate from an HTTP response.
Builds an error for a success response whose shape the service cannot parse.
Types
@type type() ::
:auth
| :rate_limit
| :invalid_request
| :context_length
| :unsupported
| :not_found
| :server
| :timeout
| :transport
Functions
@spec from_http(pos_integer(), term(), module() | nil) :: t()
Classifies a non-success HTTP response into a normalized error.
body is preserved verbatim in :raw.
@spec from_result({:ok, Req.Response.t()} | {:error, term()}, module() | nil) :: {:ok, term()} | {:error, t()}
Normalizes a Req result into {:ok, body} or {:error, t()}.
Collapses the status/transport dispatch every service would otherwise repeat.
Classifies a connection-level failure into a normalized error.
Builds an error that did not originate from an HTTP response.
Used for capability errors (:unsupported) and local validation failures.
Builds an error for a success response whose shape the service cannot parse.
Retryable - a malformed body is usually a transient provider-side glitch.