ReqAnthropic.RateLimited exception (ReqAnthropic v0.2.1)

Copy Markdown View Source

Returned when the Anthropic API responds with HTTP 429 (Too Many Requests).

The retry_after field (seconds) is promoted to the top level for ergonomic pattern matching:

case ReqAnthropic.Messages.create(opts) do
  {:ok, body} -> body
  {:error, %ReqAnthropic.RateLimited{retry_after: n}} -> Process.sleep(n * 1000)
  {:error, other} -> raise other
end

The full %ReqAnthropic.RateLimit{} struct is available in the rate_limit field for detailed quota information.

Summary

Functions

Build a %RateLimited{} from a %Req.Response{} and a pre-parsed %RateLimit{}.

Types

t()

@type t() :: %ReqAnthropic.RateLimited{
  __exception__: term(),
  message: String.t() | nil,
  rate_limit: ReqAnthropic.RateLimit.t(),
  raw: term(),
  request_id: String.t() | nil,
  retry_after: non_neg_integer() | nil
}

Functions

from_response(response, rate_limit)

@spec from_response(Req.Response.t(), ReqAnthropic.RateLimit.t()) :: t()

Build a %RateLimited{} from a %Req.Response{} and a pre-parsed %RateLimit{}.