Skip to content

An OpenAI fallback when the primary provider dies mid-demo - #67

Merged
diego-salvatierra merged 1 commit into
mainfrom
openai-fallback-provider
Aug 18, 2026
Merged

An OpenAI fallback when the primary provider dies mid-demo#67
diego-salvatierra merged 1 commit into
mainfrom
openai-fallback-provider

Conversation

@diego-salvatierra

Copy link
Copy Markdown
Collaborator

A hackathon deploy runs on borrowed or personal API keys with nobody on call. A Bedrock bearer token expiring overnight, or an OpenRouter rate limit while a room full of people all try the prototype at once, is the ordinary failure mode here, not the rare one.

What it does

generateStructured/streamStructured now retry once against an OpenAI model if OPENAI_FALLBACK_API_KEY is set, on top of whatever LLM_PROVIDER already names. Deliberately a different vendor from every existing option (Anthropic direct, OpenRouter, Bedrock) rather than a fourth way to reach Claude — an OpenRouter outage and an Anthropic outage are correlated with each other in a way neither is with OpenAI's.

Absent the env var, this is a total no-op — existing deployments are unaffected.

streamStructured only retries before the first partial has been yielded. Falling back mid-stream would mean un-yielding output a caller already rendered, and that window is exactly where a dead credential or a 429 fails anyway, so nothing real is given up.

Config

OPENAI_FALLBACK_API_KEY=sk-...
OPENAI_FALLBACK_MODEL_ID=gpt-4o-mini   # optional, this is the default

"With limits" is a dashboard setting, not something this code can enforce — documented in .env.example: pair the key with a hard monthly budget in the OpenAI dashboard (Settings → Limits).

Verified: typecheck clean, lint clean (0 errors, pre-existing warnings only), production build succeeds.

🤖 Generated with Claude Code

@vercel

vercel Bot commented Aug 18, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
interactive-learning-experiences Ready Ready Preview Aug 18, 2026 5:46pm

Request Review

A hackathon deploy runs on borrowed or personal API keys with nobody on
call. A Bedrock bearer token expiring overnight, or an OpenRouter rate
limit while a room full of people all try the prototype at once, is the
ordinary failure mode here, not the rare one.

generateStructured/streamStructured now retry once against an OpenAI model
if OPENAI_FALLBACK_API_KEY is set, on top of whatever LLM_PROVIDER already
names. Deliberately a different vendor from every existing option
(Anthropic direct, OpenRouter, Bedrock) rather than a fourth way to reach
Claude — an OpenRouter outage and an Anthropic outage are correlated with
each other in a way neither is with OpenAI's.

Absent the env var, this is a total no-op: existing deployments are
unaffected. streamStructured only retries before the first partial has
been yielded — falling back mid-stream would mean un-yielding output a
caller already rendered, and that window is exactly where a dead
credential or a 429 fails anyway.

"With limits" is a dashboard setting, not something this code can enforce
— documented in .env.example: pair the key with a hard monthly budget in
the OpenAI dashboard (Settings -> Limits).

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@diego-salvatierra
diego-salvatierra merged commit be22e4d into main Aug 18, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant