Skip to content

Allow passing Firebase App Check configuration to defaultGenerativeModelFactory #837

@Jerome-Jumah

Description

@Jerome-Jumah

Describe the bug
When enforcing Firebase App Check on a project utilizing Vertex AI for Firebase, the genui package fails to generate dynamic UI. This happens because the default factory (defaultGenerativeModelFactory) inside FirebaseAiContentGenerator hardcodes the FirebaseAI.googleAI() initialization. It does not expose any parameters to pass an appCheck instance or the useLimitedUseAppCheckTokens flag, resulting in an invalid App Check token error during generation.

To Reproduce
Steps to reproduce the behavior:

  1. Set up a Firebase project and enable the Vertex AI for Firebase API.
  2. Enable Firebase App Check in the Firebase console and enforce it specifically for the Firebase AI Logic service.
  3. In a Flutter project using the genui package, initialize Firebase and activate App Check (e.g., FirebaseAppCheck.instance.activate(...)).
  4. Attempt to generate a dynamic UI component using genui's default FirebaseAiContentGenerator without a custom modelCreator.
  5. Trigger the UI generation.
  6. See error: The generation fails, and the console outputs a permission denied or invalid App Check token error because the default factory did not attach the App Check token to the request.

Expected behavior
The FirebaseAiContentGenerator and its default factory should allow developers to pass optional FirebaseAppCheck configurations down to the underlying FirebaseAI.googleAI() initialization. The dynamic UI should generate successfully without authentication errors, rather than requiring developers to completely rewrite the default model factory just to inject the App Check parameter.

Additional context
Currently, the only way to bypass this is to manually install the firebase_ai package and completely override the modelCreator like this:

_generator = FirebaseAiContentGenerator(
  catalog: insightCatalogRegistry,
  modelCreator: ({required configuration, systemInstruction, toolConfig, tools}) => GeminiGenerativeModel(
    FirebaseAI.googleAI(
      appCheck: FirebaseAppCheck.instance, // Manually passed here
      useLimitedUseAppCheckTokens: true,
    ).generativeModel(
      model: 'gemini-2.5-flash',
      systemInstruction: systemInstruction,
      tools: tools,
      toolConfig: toolConfig,
    ),
  ),
);

Exposing appCheck and useLimitedUseAppCheckTokens as optional parameters in FirebaseAiContentGenerator would resolve this friction. I would be happy to open a PR for this if the team agrees with this approach!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions