Routing & Composition

Provider Fallback

When one provider's API errors mid-stream, transparently switch to another provider while preserving state.

Problem

A single-provider deployment is hostage to that provider's worst hour: when its stream fails halfway through a generation, the user sees a half-rendered answer followed by an error and has to start over. A request-boundary fallback chain handles the case where a whole call fails before any output, but it cannot recover a stream that began on provider A and died after some tokens were already delivered. Without mid-stream failover, the team's only options are to lose the partial output or to lock in to whichever provider was most reliable last week.

Solution

A gateway proxy holds the conversation state. On stream error, it switches to a fallback provider, optionally preserving partial output, and continues with translated message format. Tool-call schemas are normalised at the gateway. Streaming clients see one continuous stream.

When to use

  • Single-provider outages mid-stream would otherwise drop the user's session.
  • A gateway can hold conversation state and translate message formats across providers.
  • Tool-call schemas can be normalised at the gateway.

Open the full interactive page

Diagram, neighbourhood map, code examples, related patterns and full provenance.

Related