Fix firebase_options.dart Stale API Key: 400 Error Flutter

A firebase_options.dart stale api key is the most common cause of the Firebase AI Logic 400 "API key not valid" error. Your code didn't change — the key in your config file no longer matches your project. Re-running flutterfire configure regenerates the file with a valid key; this guide shows the 3…

Last updated: October 21, 2026 Your AI feature worked yesterday. This morning every Gemini request dies with 400: API key not valid. Please pass a valid API key. — and you changed nothing in your code. That maddening detail is the whole clue: a firebase_options.dart stale api key means the key baked into your config file no longer matches any valid key in your Firebase project. Your Dart is fine; your config is lying to Google. The fix takes three steps: confirm the mismatch, re-run flutterfire configure to regenerate the file, and fully restart the app. 🎬 Watch: Firebase setup with FlutterFire CLI [[YT|i75Luxm1jCU|0|Data unavailable|Codefend|Build a Ride Sharing App with AI Part 10: Firebase Setup in Flutter — firebase login + flutterfire configure walkthrough|Shows the exact flutterfire configure flow this fix prescribes: Firebase CLI login, FlutterFire CLI install, and regenerating the project config including firebase_options.dart.]] What the 400 "API key not valid" error looks like The exact error from Firebase AI Logic: [FirebaseAIException] 400: API key not valid. Please pass a valid API key. You'll see it in logcat / the debug console the moment you call generateContent , generateContentStream , or sendMessage on a firebase_ai model (v5.0.0, Flutter BoM 5.0.0). The app initializes fine — Firebase.initializeApp succeeds — and then the first real AI call throws. That "init works, AI calls fail" pattern is the signature of a config-key problem, not a code problem. Which 400 are you actually seeing? Not every Firebase AI Logic 400 is the stale-key problem. Triage before you fix: Error text Meaning Fix API key not valid. Please pass a valid API key. This article. The key in your config doesn't exist or isn't set up for your app/project. Re-run…

Explore