Skip to content

genkit_firebase_ai: Live sessions fail on web when App Check is enforced #730

Open

Description

@pavelgj

On web, every generateBidi session was closed by the server right after connecting:

WebSocket Closed, closeCode: 1008, closeReason: Firebase App Check token is invalid.

This happened for gemini-3.8-live on the Developer API and for both Live models on Agent Platform (us-central1). Non-Live requests in the same run passed App Check with the same registered debug token.

Repro (main at 7cb61bb, 2026-11-10, Chrome, firebase_ai 5.1.0 and 3.15.0, App Check enforced, registered debug token): the README Live example.

Cause. firebase_ai does not send the App Check token on the web WebSocket. LiveSession._defaultConnector (lib/src/live_session.dart):

static WebSocketChannel _defaultConnector(
        Uri uri, Map<String, String> headers) =>
    kIsWeb
        ? WebSocketChannel.connect(uri)
        : IOWebSocketChannel.connect(uri, headers: headers);

On web the headers are dropped, and the token is in neither the URL (only ?key=) nor the setup message. Same code in 3.15.0, 4.0.0, 5.0.0 and 5.1.0. Browsers cannot set headers on a WebSocket, so this needs an upstream change.

This conflicts with the smoke run on #719, which records Live passing on web with App Check enforced, in a different project. Before acting on this, please check whether enforcement was active for that project: a generateContent POST to firebasevertexai.googleapis.com with the API key and no X-Firebase-AppCheck header returns 401 UNAUTHENTICATED: Firebase App Check token is invalid. when it is. It did in my project.

Proposed

Not checked: Live on Android, iOS or macOS, where the header is sent.

Part of #380.

Activity

  1. adesinah commented on Nov 10, 2026

    @adesinah
    Contributor

    You're right, my smoke run on #719 didn't have enforcement on for the Gemini API (a key-only generateContent call answers), so it doesn't contradict this. The cause checks out in firebase_ai 5.1.0's _defaultConnector. Filed upstream as firebase/flutterfire#18938, and #738 adds the README caveat.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions