Databases, search and data

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

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.

SerpApi key types

TypePrefixSecret?ScopeExpiry
SerpApi private API key
Teams can give each member a separate key from the team management page.
—YesEvery SerpApi search engine on the account, spending the account's monthly searchesDoes 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.

Open SerpApi's key settings

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.

SerpApi keys change only when regenerated. Regenerating replaces the key in place, so the old value stops working and anything still using it fails until updated.

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 your SerpApi 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 and CLI

SerpApi's SDKs and docs read the key from SERPAPI_KEY or SERPAPI_API_KEY.

Things that catch people out

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

Common SerpApi authentication errors

401 Unauthorized - No valid API key provided.

The api_key parameter is missing, mistyped or holds a key that was regenerated.

403 Forbidden

The account behind the SerpApi key does not have permission for the request, usually because the account was deleted.

429 Too Many Requests

The account exceeded its hourly throughput limit or ran out of searches for the month.

Using your SerpApi 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 SerpApi 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.

SerpApi 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

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.

Stop pasting SerpApi keys into agents

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