Skip to main content

Overview

The Brave Search API uses API key authentication to secure requests. Every API request must include your subscription token in the request header to authenticate and authorize access.
Your API key is confidential and should be kept secure. Never expose it in client-side code, public repositories, or share it publicly.

Obtaining Your API Key

To get started with the Brave Search API, you’ll need a subscription token:
  1. Subscribe to a plan — Visit the Brave Search API page and choose a plan that fits your needs
  2. Access your API keys — Once subscribed, navigate to the API Keys section in your dashboard
  3. Copy your token — Your subscription token will be displayed. Copy it to use in your requests
Even on the Free plan, you need to subscribe to obtain an API key. You won’t be charged for the free tier.

Authentication Method

All requests to the Brave Search API must include your subscription token in the X-Subscription-Token HTTP header.

Header Format

X-Subscription-Token: YOUR_API_KEY

Code Examples

Here are examples of how to authenticate requests in various programming languages:
curl -s --compressed "https://api.search.brave.com/res/v1/web/search?q=brave+search" \
  -H "Accept: application/json" \
  -H "Accept-Encoding: gzip" \
  -H "X-Subscription-Token: YOUR_API_KEY"

Best Practices

Secure Storage

Never hardcode your API key directly in your source code. Instead, use environment variables or secure configuration management:
import os

api_key = os.environ.get('BRAVE_API_KEY')
headers = {
    'X-Subscription-Token': api_key
}

Key Rotation

Regularly rotate your API keys as a security best practice. You can generate new keys from your dashboard.
If you suspect your API key has been compromised, immediately revoke it from your dashboard and generate a new one.

Next Steps

I