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

Source: https://botpassword.com/keys/serpapi
Last checked: 2026-11-08

The SerpApi API key is shown on the SerpApi dashboard and managed at `serpapi.com/manage-api-key`, where **Regenerate API Key** replaces it. SerpApi expects the key as the required `api_key` query parameter on `https://serpapi.com/search`, so it appears in every request URL. The official Python library's examples read it from `SERPAPI_KEY`, and SerpApi's official MCP server reads `SERPAPI_API_KEY`.

## Key types

| Type | Prefix | Secret | Scope | Expiry |
|---|---|---|---|---|
| SerpApi private API key | — | Yes | Every SerpApi search engine on the account, spending the account's monthly searches | Does not change until it is regenerated |

## How to create a SerpApi key

1. Create a SerpApi account at `serpapi.com/users/sign_up`; the free plan includes 250 searches a month.
2. Open the dashboard, where the SerpApi API key is shown.
3. Open **Manage API Key** (`serpapi.com/manage-api-key`) to view or regenerate it.
4. Store the SerpApi key in `SERPAPI_KEY` (or `SERPAPI_API_KEY` for the MCP server), never in source code.

## Limiting what the key can do

SerpApi keys cannot be limited to particular engines or a spending cap; a key can run any search the account's plan allows, and every non-cached search counts toward the monthly quota. Separate keys per team member, set up from the team management page, are the way to tell usage apart and to cut off one person without affecting the others. Because the key travels as a URL query parameter, call SerpApi only from a server, so the key does not appear in browser history, page source or third-party logs.

## How to rotate a SerpApi key

1. Open `serpapi.com/manage-api-key` from the dashboard.
2. Click **Regenerate API Key** and confirm.
3. Update `SERPAPI_KEY` and every application, CI secret and MCP configuration with the new key.

## How to revoke a SerpApi key

1. Open `serpapi.com/manage-api-key` and click **Regenerate API Key**, which replaces the current key.
2. For a team member's separate key, manage it from the team management page.

## If the key leaked

1. Regenerate the SerpApi key at `serpapi.com/manage-api-key` immediately.
2. Deploy the new key to every service and to repository secrets such as GitHub Actions secrets.
3. Check the dashboard's search usage for searches you did not run.
4. Add `.env` to `.gitignore` so the key is not committed again.

## Environment variables

- `SERPAPI_KEY`
- `SERPAPI_API_KEY`

## Gotchas

- The key goes in the URL, so any proxy, analytics or error tool that logs URLs can capture it.
- The Python library uses `SERPAPI_KEY` while the MCP server uses `SERPAPI_API_KEY`; set the name each tool expects.
- Cached searches do not count toward the monthly quota, but a 429 can still mean the quota is spent.
- Regenerating breaks every integration still holding the old key, including MCP clients configured with the key in the server URL path.

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

## FAQ

### Where do I find my SerpApi API key?

The key is on your SerpApi dashboard and at `serpapi.com/manage-api-key`, where you can also regenerate it.

### How do I regenerate my SerpApi API key?

Open **Manage API Key** at `serpapi.com/manage-api-key`, click **Regenerate API Key** and confirm, then update your applications with the new key.

### What environment variable does SerpApi use?

The official `serpapi` Python library's README exports `SERPAPI_KEY` and passes it as `serpapi.Client(api_key=os.environ["SERPAPI_KEY"])`. The SerpApi MCP server reads `SERPAPI_API_KEY`.

### How do I connect SerpApi to an AI agent through MCP?

Use SerpApi's official MCP server, hosted at `https://mcp.serpapi.com/mcp`. Its README recommends sending the key as `Authorization: Bearer` rather than in the URL path, so the key stays out of URLs and logs.

### How many free searches does SerpApi include?

The free plan includes 250 searches per month; cached searches are not counted.

### Can an AI agent use my SerpApi 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`, so the agent gets the result and never the value.

## Sources

- https://serpapi.com/search-api
- https://serpapi.com/api-status-and-error-codes
- https://serpapi.com/blog/how-to-securely-store-api-keys/
- https://serpapi.com/blog/getting-started-with-serpapi-the-web-search-api/
- https://github.com/serpapi/serpapi-python
- https://github.com/serpapi/serpapi-mcp
