View Source Anthropic.Error exception (anthropic_community v0.5.0)

Unified error type returned as {:error, %Anthropic.Error{}} from every resource function, and raised by the ! bang variants (this struct is a defexception).

:type mirrors the Anthropic API's error.type taxonomy (invalid_request_error, authentication_error, permission_error, not_found_error, request_too_large, rate_limit_error, api_error, overloaded_error) for errors that came back from the API, plus client-local types for failures that never reach the wire: :connection_error, :timeout, :decode_error, :validation_error, :tool_runner_max_iterations.

Summary

Functions

Builds an Error from a raw HTTP error response: status code, raw body, and headers (used to extract a request-id for support/debugging).

Builds an Error from a decoded wire error object: %{"type" => ..., "message" => ...} (the value of the top-level "error" key in an API error response body).

Whether this error is safe to retry (used by the retry/backoff layer). Status-driven first — retries on 408 (request timeout), 409 (lock timeout), and any 5xx, regardless of the wire error.type — then falls back to semantic error types for failures with no HTTP status at all (:rate_limit_error, :overloaded_error, :connection_error, :timeout).

Types

@type t() :: %Anthropic.Error{
  __exception__: term(),
  message: String.t(),
  request_id: String.t() | nil,
  status: pos_integer() | nil,
  type: atom()
}

Functions

Link to this function

from_response(status, body, headers)

View Source
@spec from_response(pos_integer(), String.t(), [{String.t(), String.t()}]) :: t()

Builds an Error from a raw HTTP error response: status code, raw body, and headers (used to extract a request-id for support/debugging).

@spec from_wire_error(map()) :: t()

Builds an Error from a decoded wire error object: %{"type" => ..., "message" => ...} (the value of the top-level "error" key in an API error response body).

Link to this function

new(type, message, opts \\ [])

View Source
@spec new(atom(), String.t(), keyword()) :: t()
@spec retryable?(t()) :: boolean()

Whether this error is safe to retry (used by the retry/backoff layer). Status-driven first — retries on 408 (request timeout), 409 (lock timeout), and any 5xx, regardless of the wire error.type — then falls back to semantic error types for failures with no HTTP status at all (:rate_limit_error, :overloaded_error, :connection_error, :timeout).

@spec timeout() :: t()
@spec validation(String.t()) :: t()