Hybrid Web AI: Routing Between Browser Gemini Nano & Cloud Models
Zero-Latency Local Inference with Automatic Edge Fallback
Why pay cloud token costs for simple summarization or draft formatting when Chrome's built-in Gemini Nano can run it locally on the user's GPU for $0?
export async function generateHybridSummary(text: string): Promise<string> {
if (typeof window !== "undefined" && "LanguageModel" in window) {
const session = await (window as any).LanguageModel.create();
return await session.prompt(`Summarize in 2 sentences: ${text}`);
}
const res = await fetch("/api/ai/hybrid-fallback", {
method: "POST",
body: JSON.stringify({ prompt: text }),
});
const data = await res.json();
return data.text;
}Production Architecture Takeaway
Always pair window.LanguageModel feature detection with an edge API fallback so Safari, Firefox, and mobile users get the exact same UX.
how this course connects together.
Follow AJ from first principles to production-ready architecture.
