-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Description
Is there an existing issue for this?
- I have searched the existing issues.
Which plugins are affected?
Other
Which platforms are affected?
Web
Description
After following the official "Get Started with the Gemini API on Web" documentation, all calls to the Gemini model using the firebase_ai package fail with a 403 Forbidden: The caller does not have permission error.
This issue occurs exclusively when running the Flutter app in a web browser on localhost. The exact same API key and request configuration work perfectly when tested directly via Postman, which confirms that the API key is valid and the Generative Language/Vertex AI API is enabled and functioning correctly on the backend.
The error seems to be related to the context of the request originating from the browser (specifically localhost) rather than an issue with the API key or cloud project permissions themselves.
Reproducing the issue
Set up a new Flutter project and configure it for Web.
Initialize Firebase for the project using flutterfire configure.
Follow the official documentation to set up the Firebase AI SDK: Get Started with the Gemini API on Web
Implement a basic call to the model:
Dart
import 'package:firebase_ai/firebase_ai.dart';
// ...
final model = FirebaseAI.instance.googleAI(model: 'gemini-2.5-flash');
final response = await model.generateContent([Content.text('Why is the sky blue?')]);
print(response.text);
Run the app locally on Chrome: flutter run -d chrome
Trigger the generateContent call.
Observe the 403 permission error in the browser's developer tools network tab.
- Expected behavior
The API call from the Flutter Web app on localhost should succeed and return a valid response from the Gemini model, consistent with the behavior observed in Postman.
- Actual behavior
The request fails with a 403 Forbidden status code. The response body typically contains an error message like: The caller does not have permission.
Firebase Core version
4.1.1
Flutter Version
3.35.4
Relevant Log Output
ServerFailure(Failed to parse JSON response: The caller does not have permission)
Flutter dependencies
environment:
sdk: ^3.7.0
firebase_core: ^4.1.1
firebase_messaging: ^16.0.2
firebase_analytics: ^12.0.2
firebase_auth: ^6.1.0
firebase_ai: ^3.3.0
firebase_app_check: ^0.4.1