class RubyLLM::Fallback

A Fallback is a fallback model target configured with Chat#with_fallbacks. When the active model fails with a matching error, the chat retries the request with each fallback in order. Instances are yielded to Chat#before_fallback and Chat#after_fallback callbacks, enriched with the details of that attempt.

chat = RubyLLM.chat(model: "gpt-4.1")
              .with_fallbacks("gpt-4.1-mini", "claude-haiku-4-5")

chat.before_fallback do |fallback|
  puts "Falling back from #{fallback.from.id} to #{fallback.to.id}"
end

chat.after_fallback do |fallback|
  puts "Fallback #{fallback.succeeded? ? 'succeeded' : 'failed'}"
end