Databases, search and data

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

Brave Search API keys are created in the API Keys section of the Brave Search API dashboard (api-dashboard.search.brave.com) after you activate a plan, and are sent in the X-Subscription-Token header on every request. Brave's own examples store the key in BRAVE_API_KEY, the variable its official MCP server also reads. Brave says to rotate keys regularly and to revoke a key at once if it may be compromised.

Brave Search API key types

TypePrefixSecret?ScopeExpiry
Brave Search API key
Brave does not document a key prefix or per-key permissions. A plan must be active before a key can be created.
—YesThe Brave Search API products included in the account's active plan, such as Web Search and LLM Context—

How to create a Brave Search API key

  1. Register at the Brave Search API dashboard with an email and password, then confirm the email.
  2. Open the Plans page and activate a plan; Brave asks for a credit card to activate one.
  3. Open the API Keys section and click Add API Key.
  4. Give the key a descriptive name such as "Production App" or "Development", then copy it and store it in BRAVE_API_KEY.

Open Brave Search API's key settings

Limiting what the key can do

A Brave Search API key reaches whatever its plan includes; there are no documented per-key scopes or caps, so the plan itself is the boundary. Separate keys per application, named clearly, let you revoke one without breaking the others. Keep the key out of client-side code and public repositories, as Brave instructs, and call the API from a server or a local tool such as the MCP server. The MCP server can also read the key from a file named in BRAVE_API_KEY_FILE, which keeps it out of the client's JSON configuration.

How to rotate a Brave Search API key

  1. Add a new key in the API Keys section of the dashboard.
  2. Replace BRAVE_API_KEY wherever the old key is used, including MCP client configs.
  3. Revoke the old key in the dashboard.

Brave calls regular rotation a security best practice and says you can generate new keys and revoke old ones from the dashboard. There is no documented overlap window or in-place regenerate.

How to revoke a Brave Search API key

  1. Sign in to the Brave Search API dashboard.
  2. Revoke the key in the API Keys section.

If your Brave Search API key leaked

  1. Revoke the exposed key in the dashboard immediately, as Brave advises for a possibly compromised key.
  2. Generate a new key and update every service that used the old one.
  3. Check the dashboard's usage for queries you did not make.

Environment variables and CLI

Brave Search API's SDKs and docs read the key from BRAVE_API_KEY.

Things that catch people out

  • The header is X-Subscription-Token, not Authorization: Bearer; Brave's docs and reference list X-Subscription-Token as the required header for the key.
  • A plan, with a card on file, must be active before the API Keys section will issue a key.
  • The MCP server prefers BRAVE_API_KEY_FILE over BRAVE_API_KEY when both are set, which can make a rotated key appear not to take effect.

Using your Brave Search API 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 Brave Search API 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.

Brave Search API 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

How do I get a Brave Search API key?

Register at api-dashboard.search.brave.com, activate a plan on the Plans page, then open API Keys and click Add API Key.

Which header does the Brave Search API use?

Every request sends the key in the X-Subscription-Token HTTP header.

What environment variable does Brave Search use?

Brave's authentication guide exports BRAVE_API_KEY and reads it with os.environ.get('BRAVE_API_KEY') or process.env.BRAVE_API_KEY. The official MCP server reads the same variable.

How do I add Brave Search to an AI agent through MCP?

Run Brave's official server, npx -y @brave/brave-search-mcp-server, with BRAVE_API_KEY in the client's env block, or point BRAVE_API_KEY_FILE at a file holding the key. It supports stdio and HTTP transports; the HTTP mode listens on http://127.0.0.1:8080/mcp by default.

What should I do if my Brave Search API key leaks?

Revoke it in the dashboard's API Keys section, generate a new key, and update every application that used the old one.

Can an AI agent use my Brave Search API 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 Brave Search API keys into agents

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