Why You Should Never Embed Your Gemini API Key in Client Code

Why You Should Never Embed Your Gemini API Key in Client Code (And How Firebase AI Logic Fixes It)


The explosion of generative AI has pushed thousands of web developers to add intelligent features to their apps.


The first instinct is usually to call the Gemini API's SDK directly from the browser. That instinct comes with a serious security risk: exposing your API key to the world.


In this article, you'll learn why shipping a raw Gemini API key to the client is dangerous, how Firebase AI Logic's proxy architecture solves it, and how Firebase App Check closes the second half of the problem that a proxy alone doesn't fix.


By the end, you'll have a working, production-style setup: a protected AI Logic client, a properly configured App Check flow (debug token included), and real usage patterns—streaming, multi-turn chat, and structured JSON output—not just a single console.log.


Table of Contents


via FreeCodeCamp

Related