firebase-ai: LiveGenerativeModel.connect() WebSocket does not attach X-Firebase-AppCheck header
Environment
- Firebase Component: AI Logic (
firebase-ai) - Component version: 17.11.0 (via firebase-bom 34.12.0); also present on
mainas of today.
Problem
When App Check is enforced on firebasevertexai.googleapis.com, Gemini Live sessions fail with:
ServiceConnectionHandshakeFailedException: Channel was closed by the server. Details: Firebase App Check token is invalid.
HTTPS methods on the same FirebaseAI instance (generateContent, generateContentStream, countTokens) succeed with identical App Check setup. Only the Live API path (liveModel().connect()) fails.
Looking at APIController.kt:258-259:
suspend fun getWebSocketSession(location: String): DefaultClientWebSocketSession =
client.webSocketSession(getBidiEndpoint(location)) { applyCommonHeaders() }
The WebSocket config lambda calls only applyCommonHeaders(). It does not call applyHeaderProvider(), which is what sets the X-Firebase-AppCheck header (via AppCheckHeaderProvider.generateHeaders()). Other methods like countTokens (line 273) correctly call both.
Result: WebSocket upgrade request is sent without an App Check token, so the server rejects it.
Steps to reproduce
- Enable App Check enforcement on
firebasevertexai.googleapis.com. - Install a provider factory at startup:
Firebase.appCheck.installAppCheckProviderFactory(PlayIntegrityAppCheckProviderFactory.getInstance()) - Call Live API:
FirebaseAI.getInstance( backend = GenerativeBackend.vertexAI("us-central1"), useLimitedUseAppCheckTokens = true ).liveModel("gemini-live-2.5-flash-native-audio").connect() - Observe
ServiceConnectionHandshakeFailedException: ... App Check token is invalid. - Confirm
generativeModel(...).generateContentStream(...)works on the same setup.
Hi @jacksonej, thank you for reaching out. I was able to reproduce the issue with the steps and code snippets you shared. I'll raise this to our engineers along with the PR you submitted to resolve the issue. Thanks!