<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/why-you-should-never-embed-your-gemini-api-key-in-client-code-and-how-firebase-ai-logic-fixes-it--cnmlp8pk0" -->

---
title: Why You Should Never Embed Your Gemini API Key in Client...
description: Embedding a Gemini API key directly in client-side JavaScript exposes it to trivial extraction from bundled code or browser network requests, risking quota...
canonical: https://daily.dev/posts/why-you-should-never-embed-your-gemini-api-key-in-client-code-and-how-firebase-ai-logic-fixes-it--cnmlp8pk0
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Why You Should Never Embed Your Gemini API Key in Client Code (And How Firebase AI Logic Fixes It) | daily.dev
og:description: Embedding a Gemini API key directly in client-side JavaScript exposes it to trivial extraction from bundled code or browser network requests, risking quota...
og:url: https://daily.dev/posts/why-you-should-never-embed-your-gemini-api-key-in-client-code-and-how-firebase-ai-logic-fixes-it--cnmlp8pk0
og:image: https://api.daily.dev/og/posts/cNMLp8pK0.png
og:image:alt: Why You Should Never Embed Your Gemini API Key in Client Code (And How Firebase AI Logic Fixes It)
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

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

**[freeCodeCamp](https://daily.dev/sources/freecodecamp)** · 14 min read · 0 upvotes · 0 comments

## Summary

Embedding a Gemini API key directly in client-side JavaScript exposes it to trivial extraction from bundled code or browser network requests, risking quota drain and billing spikes. Firebase AI Logic solves this by proxying requests server-side so the key never reaches the browser, while Firebase App Check adds attestation to ensure only genuine app instances can call that proxy, distinct from user authentication. The guide walks through setting up a Firebase project, configuring App Check with reCAPTCHA Enterprise and a local debug token, then implementing Firebase AI Logic for single requests, streaming, multi-turn chat, structured JSON output, and retry logic with exponential backoff. It also covers common debugging issues and notes that Google will make App Check enforcement mandatory for Firebase AI Logic starting November 2, 2026, with older Gemini models like gemini-2.0-flash already retired as of June 1, 2026.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.freecodecamp.org/news/why-you-should-never-embed-your-gemini-api-key-in-client-code-and-how-firebase-ai-logic-fixes-it>

## Questions this post answers

### Why shouldn't I put my Gemini API key directly in my client-side JavaScript code?

Because bundled JavaScript ships as plain text, so anyone can extract the key with a simple command like curl and grep against the deployed bundle, or just read it from the Network tab in dev tools. A leaked key lets an attacker drain your usage quota, spike your Cloud bill since Gemini is billed per token, or get your Google Cloud project suspended for abuse.

_daily.dev surfaces practical security patterns like this for developers shipping AI features safely._

### How does Firebase AI Logic keep my Gemini API key hidden from the browser?

Firebase AI Logic acts as a proxy gateway: the client SDK sends an authenticated request to the proxy, which injects the Gemini API key server-side on Google's infrastructure and forwards the call, so the key never appears in the JS bundle or network requests. It supports two providers, the Gemini Developer API on the free Spark plan, or the Agent Platform Gemini API requiring the Blaze billing plan.

_developers weighing a DIY backend proxy versus a managed one can track approaches like this on daily.dev._

### When does Firebase App Check become mandatory for Firebase AI Logic, and what happens if I don't set it up?

Google has announced App Check enforcement becomes mandatory for Firebase AI Logic starting November 2, 2026; any unverified request made after that date is rejected outright. The guided setup workflow in the Firebase console already enables App Check automatically for new AI Logic integrations starting July 2026, so it's worth wiring up attestation now rather than scrambling later.

_teams tracking Firebase deadlines like this can follow the change on daily.dev before it breaks production._

## Similar posts on daily.dev

- [Build smarter apps with Gemini 3 Flash](https://daily.dev/posts/build-smarter-apps-with-gemini-3-flash-rgootmsr4) · Android Developers Blog · 76 upvotes · 2 comments
- [Serverless AI for Android with Firebase AI Logic](https://daily.dev/posts/serverless-ai-for-android-with-firebase-ai-logic-33d7pefc4) · ProAndroidDev · 0 upvotes · 0 comments
- [Google API Keys Weren't Secrets. But then Gemini Changed the Rules. ◆ Truffle Security Co.](https://daily.dev/posts/google-api-keys-weren-t-secrets-but-then-gemini-changed-the-rules-truffle-security-co--wmqn4ysm3) · Hacker News · 0 upvotes · 0 comments

---

Tags: [#security](https://daily.dev/tags/security), [#javascript](https://daily.dev/tags/javascript), [#firebase](https://daily.dev/tags/firebase)

[View this post on daily.dev](https://daily.dev/posts/why-you-should-never-embed-your-gemini-api-key-in-client-code-and-how-firebase-ai-logic-fixes-it--cnmlp8pk0)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Why You Should Never Embed Your Gemini API Key in Client Code (And How Firebase AI Logic Fixes It)","url":"https://daily.dev/posts/why-you-should-never-embed-your-gemini-api-key-in-client-code-and-how-firebase-ai-logic-fixes-it--cnmlp8pk0","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/why-you-should-never-embed-your-gemini-api-key-in-client-code-and-how-firebase-ai-logic-fixes-it--cnmlp8pk0"},"datePublished":"2026-09-21T14:09:31.040Z","dateModified":"2026-09-21T14:09:55.185Z","description":"Embedding a Gemini API key directly in client-side JavaScript exposes it to trivial extraction from bundled code or browser network requests, risking quota...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/4a9d4afe350679cb95cdbae36269d5a4?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/4a9d4afe350679cb95cdbae36269d5a4?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"freeCodeCamp","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"freeCodeCamp","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1628412854/logos/freecodecamp","url":"https://daily.dev/sources/freecodecamp"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/why-you-should-never-embed-your-gemini-api-key-in-client-code-and-how-firebase-ai-logic-fixes-it--cnmlp8pk0","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"security,javascript,firebase","timeRequired":"PT14M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"freeCodeCamp","item":"https://daily.dev/sources/freecodecamp"},{"@type":"ListItem","position":3,"name":"Why You Should Never Embed Your Gemini API Key in Client Code (And How Firebase AI Logic Fixes It)"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/why-you-should-never-embed-your-gemini-api-key-in-client-code-and-how-firebase-ai-logic-fixes-it--cnmlp8pk0#faq","mainEntity":[{"@type":"Question","name":"Why shouldn't I put my Gemini API key directly in my client-side JavaScript code?","acceptedAnswer":{"@type":"Answer","text":"Because bundled JavaScript ships as plain text, so anyone can extract the key with a simple command like curl and grep against the deployed bundle, or just read it from the Network tab in dev tools. A leaked key lets an attacker drain your usage quota, spike your Cloud bill since Gemini is billed per token, or get your Google Cloud project suspended for abuse. daily.dev surfaces practical security patterns like this for developers shipping AI features safely."}},{"@type":"Question","name":"How does Firebase AI Logic keep my Gemini API key hidden from the browser?","acceptedAnswer":{"@type":"Answer","text":"Firebase AI Logic acts as a proxy gateway: the client SDK sends an authenticated request to the proxy, which injects the Gemini API key server-side on Google's infrastructure and forwards the call, so the key never appears in the JS bundle or network requests. It supports two providers, the Gemini Developer API on the free Spark plan, or the Agent Platform Gemini API requiring the Blaze billing plan. developers weighing a DIY backend proxy versus a managed one can track approaches like this on daily.dev."}},{"@type":"Question","name":"When does Firebase App Check become mandatory for Firebase AI Logic, and what happens if I don't set it up?","acceptedAnswer":{"@type":"Answer","text":"Google has announced App Check enforcement becomes mandatory for Firebase AI Logic starting November 2, 2026; any unverified request made after that date is rejected outright. The guided setup workflow in the Firebase console already enables App Check automatically for new AI Logic integrations starting July 2026, so it's worth wiring up attestation now rather than scrambling later. teams tracking Firebase deadlines like this can follow the change on daily.dev before it breaks production."}}]}
```

