Function: buildFallbackChain()
buildFallbackChain(
excludeProvider?,call?):FallbackProviderEntry[]
Defined in: packages/agentos/src/api/generateText.ts:1969
Auto-discovers available LLM providers from well-known environment variables and builds an ordered fallback chain.
Each entry in the returned array contains a provider identifier and an optional model suitable for fallback use. Providers are ordered by general availability; the OpenAI legs pin a Sol model, the platform's quality floor for failover traffic. A primary-provider outage must not silently downgrade user-facing output to a mini-tier model:
- OpenAI (
gpt-6.2-sol) - Anthropic (
claude-sonnet-5-5at effortlow, with 1024 tokens of output headroom for thinking;claude-sonnet-5for a call whosetoolChoiceforces a tool, since Sonnet 5.5 refuses a forced choice and would be sentauto) - OpenRouter (
openai/gpt-5.6-sol) - Gemini (
gemini-3.1-pro-preview)
Parameters
excludeProvider?
string
Provider to omit from the chain (typically the primary provider that already failed).
call?
The call the chain rescues: its toolChoice picks the
Anthropic leg's model, so a required tool stays required on that hop.
Every leg pins cache: false: failover hops are sporadic one-shots, so
prompt-cache writes on a rescue leg almost never earn their reads back
(see FallbackProviderEntry.cache). Callers wanting a cached hop
supply their own chain with a per-entry ttl.
toolChoice?
string | Record<string, unknown>
Returns
An array of { provider, model?, cache } entries ready for use as
GenerateTextOptions.fallbackProviders.
Example
// Primary is anthropic: build fallback chain from remaining providers
const chain = buildFallbackChain('anthropic');
// => [{ provider: 'openai', model: 'gpt-6.2-sol' }, { provider: 'openrouter', model: 'openai/gpt-5.6-sol' }, ...]