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

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

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.

## Key types

| Type | Prefix | Secret | Scope | Expiry |
|---|---|---|---|---|
| Brave Search API key | — | Yes | The 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`.

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

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

- `BRAVE_API_KEY`

## Gotchas

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

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

## Sources

- https://api-dashboard.search.brave.com/documentation/guides/authentication
- https://api-dashboard.search.brave.com/documentation/quickstart
- https://api-dashboard.search.brave.com/app/documentation/web-search/get-started
- https://github.com/brave/brave-search-mcp-server
