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

Source: https://botpassword.com/keys/firebase
Last checked: 2026-10-25

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.

## Key types

| Type | Prefix | Secret | Scope | Expiry |
|---|---|---|---|---|
| Firebase API key | — | No | Identifies your Firebase project and app to Firebase services; not an access credential | — |
| Service account key (JSON) | — | Yes | Admin-level access for the Firebase Admin SDK, governed by the service account's IAM roles | — |
| Gemini Developer API key | — | Yes | Calls 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.

## 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.

## 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 the 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

- `GOOGLE_APPLICATION_CREDENTIALS`

## Gotchas

- 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.

## Using this key with AI agents (BotPassword)

- `run_with`: Runs 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_request`: Makes 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_login`: Lets 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.
- `rotate`: Partly 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_secret`: Saves a value the agent already holds as a new vault item.

## FAQ

### 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.

## Sources

- https://firebase.google.com/docs/projects/api-keys
- https://firebase.google.com/docs/admin/setup
- https://firebase.google.com/docs/cli/mcp-server
- https://docs.cloud.google.com/iam/docs/key-rotation
