class RubyLLM::Error

Error is the base class for provider-operation errors raised by RubyLLM, including API, network, capability, and provider response-shape failures. When an HTTP response is available, it wraps that response and normalizes the message across providers. When the provider refuses a conversation, request_shape describes what it was sent. Subclasses map common HTTP status codes: BadRequestError (400), UnauthorizedError (401), PaymentRequiredError (402), ForbiddenError (403), RateLimitError (429), ServerError (500), ServiceUnavailableError (502 to 504), and OverloadedError (529).

begin
  RubyLLM.chat.ask "Translate 'hello' to French."
rescue RubyLLM::RateLimitError
  puts "Rate limit hit. Please wait a moment."
rescue RubyLLM::Error => e
  puts "API error: #{e.message}"
  puts e.response&.status
end

Providers often quote the request back in their error, so with Configuration#redact_error_messages the message carries only the HTTP status, the provider, and the provider’s error code. What the provider wrote stays on provider_message and its raw body on response_body.

Local setup and programming errors, such as ConfigurationError and ModelNotFoundError, inherit from StandardError directly and are not caught by rescuing Error.