Databases, search and data

Firebase API keys: find, store, rotate, and use them safely with AI agents

A Firebase web API key is not a secret: it only identifies your project and app, and access is controlled by Security Rules, IAM and App Check. Service account keys (the JSON file from Project settings → Service accounts) are secrets that grant admin access, and a Gemini Developer API key must never be in code or config.

Firebase key types

TypePrefixSecret?ScopeExpiry
Firebase API key
Can be included in code or config files when restricted to Firebase services. Review its API restrictions in Google Cloud Console.
—NoIdentifies your Firebase project and app to Firebase services; not an access credential—
Service account key (JSON)
Google warns that extremely high security awareness is required when working with service account keys.
—YesAdmin-level access for the Firebase Admin SDK, governed by the service account's IAM roles—
Gemini Developer API key
Docs say it should never be included in your code or configuration files.
—YesCalls the Generative Language API—

How to create a Firebase key

  1. In the Firebase console open Settings → Service accounts.
  2. Click Generate New Private Key, then confirm with Generate Key.
  3. Store the downloaded JSON file securely and point GOOGLE_APPLICATION_CREDENTIALS at it.

Open Firebase's key settings

Limiting what the key can do

Firebase API keys are restricted in Google Cloud Console under APIs & Services → Credentials; Firebase-provisioned keys are restricted to Firebase-related APIs by default. Service account permissions come from IAM roles. Use separate, restricted keys for any non-Firebase API such as Maps.

How to rotate a Firebase key

  1. Create a new key for the same service account.
  2. Replace the old key in all applications.
  3. Disable the old key and monitor that applications still work.
  4. Delete the old key.

Google recommends rotating service account keys at least every 90 days, or immediately if compromise is suspected.

How to revoke a Firebase key

  1. Disable and then delete the service account key in Google Cloud (IAM and Admin → Service accounts → Keys).
  2. Delete or restrict an exposed Firebase API key in APIs & Services → Credentials.

If your Firebase key leaked

  1. Disable and delete the exposed service account key, after creating a replacement.
  2. Update every app and CI secret that used it.
  3. Review Cloud Audit Logs for activity from that service account.

Environment variables and CLI

Firebase's SDKs and docs read the key from GOOGLE_APPLICATION_CREDENTIALS.

Firebase CLI (firebase)

Things that catch people out

  • A Firebase web API key in your page source is normal; real protection comes from Security Rules, IAM and App Check.
  • The Gemini Developer API key can appear in the Google Cloud console as "Gemini Developer API key (auto created by Firebase)" and must stay secret.
  • Do not remove APIs a Firebase service needs from a key's restrictions, or those services will fail.
  • The Firebase MCP server (npx -y firebase-tools@latest mcp) uses the same credentials as the Firebase CLI.

Recent incidents that put Firebase keys at risk

If you were affected by one of these, rotate your Firebase keys using the rotation steps above.

Using your Firebase key with AI agents

A coding agent that can read your .env file or your shell history can read the key, and anything in its context can end up in logs, transcripts or a prompt-injected request. The safer pattern is to keep the key in a credential broker that performs the authenticated step for the agent and hands back only the result.

BotPassword works this way. For a Firebase key, these intents fit:

IntentWhat BotPassword does
run_withRuns a command with the key injected as an environment variable or a 0600 temporary file, never on the command line, and redacts the key from the output.
http_requestMakes an authenticated API call after checking the destination against the hosts this key may be sent to. The response comes back with credential-shaped values redacted, and one that holds the key itself is refused.
cli_loginLets git, Docker, the AWS CLI and kubectl log in through bpw's credential helper, so the token is fetched when the tool needs it and not written into its config. The helper hands the value to the tool, so the grant is always disclosing. Other tools use run_with; OAuth device logins are planned.
rotatePartly built: creates a new key, stores it as pending, verifies it, promotes it, then revokes the old key after a grace period. Today it works for Cloudflare tokens and AWS IAM keys you have set up, and an agent can start it only under a grant with autopilot; other providers cannot be rotated through their API yet.
store_secretSaves a value the agent already holds as a new vault item.

Firebase also publishes its own MCP server. Whatever server the agent uses, keep the credential it authenticates with out of the agent's context.

Set it up in your agent: Aider · Amp · Claude Code · Claude Desktop · Cline · OpenAI Codex CLI · all agents

Frequently asked questions

Is a Firebase API key secret?

No. Firebase API keys only identify your project and app. Protect data with Security Rules, IAM and App Check instead.

Where do I find my Firebase service account key?

In the Firebase console under Settings → Service accounts, click Generate New Private Key. Treat the downloaded JSON file as a secret.

How do I use a Firebase service account key file?

Set GOOGLE_APPLICATION_CREDENTIALS to the file's path so Application Default Credentials finds it.

Can an AI agent use my Firebase key without seeing it?

Yes, if the key never enters the agent's context. Instead of pasting the key into a chat or leaving it in a .env file the agent can read, keep it in a credential broker that injects it into the command or request on the agent's behalf. BotPassword does this with run_with, http_request, store_secret, so the agent gets the result and never the value.

Stop pasting Firebase keys into agents

BotPassword is in early access. Request an invite and we'll email you when your spot opens.