Overview
All Brew SDK requests require authentication using an API key. The SDKs send your API key in theX-API-Key header with every request.
Getting Your API Key
1
Open Settings
In Brew, navigate to Settings → API from the sidebar.
2
Generate a Key
Click Generate Key and give it a descriptive name like “Production App” or “Development”.
3
Copy and Store
Copy your API key immediately. For security reasons, you won’t be able to see the full key again.
Setting Up Authentication
Using Environment Variables (Recommended)
The simplest and most secure way to configure your API key is through environment variables. Both SDKs automatically read fromBREW_SDK_API_KEY.
- TypeScript
- Python
Explicit Configuration
You can also pass the API key directly when creating the client:- TypeScript
- Python
If you pass
apiKey explicitly, it takes precedence over the environment variable.Environment Variables
Both SDKs support these environment variables:| Variable | Description | Default |
|---|---|---|
BREW_SDK_API_KEY | Your Brew API key | None (required) |
BREW_SDK_BASE_URL | Override the API base URL | https://brew.new/api |
BREW_SDK_LOG | Log level (debug, info, warn, error, off) | warn |
Example .env File
- TypeScript
- Python
Use a package like
dotenv to load environment variables:Verifying Your API Key
You can verify your API key is working by making a simple API call:- TypeScript
- Python
Security Best Practices
Never commit API keys to version control
Never commit API keys to version control
Add
.env to your .gitignore file:Use different keys for different environments
Use different keys for different environments
Generate separate API keys for development, staging, and production. This limits the blast radius if a key is compromised.
Rotate keys periodically
Rotate keys periodically
Regularly rotate your API keys, especially if team members leave or you suspect a key may have been exposed.
Use secrets managers in production
Use secrets managers in production
For production deployments, use a secrets manager like:
- AWS Secrets Manager
- Google Cloud Secret Manager
- HashiCorp Vault
- Doppler
Never use API keys in client-side code
Never use API keys in client-side code
API keys should only be used in server-side code. If you need to make API calls from a frontend, route them through your backend.
Troubleshooting
”Could not resolve authentication method” Error
This error occurs when no API key is provided. Make sure:- The
BREW_SDK_API_KEYenvironment variable is set - Or you’re passing
apiKeywhen creating the client
401 Unauthorized Response
If you receive a 401 error:- Verify your API key is correct (no extra spaces or characters)
- Check that the key hasn’t been revoked in the Brew dashboard
- Ensure you’re using the correct format (just the key, not
Bearerprefix)
Need Help?
Our team is ready to support you at every step of your journey with Brew. Choose the option that works best for you:- Self-Service Tools
- Talk to Our Team
Search Documentation
Type in the “Ask any question” search bar at the top left to instantly find relevant documentation pages.
ChatGPT/Claude Integration
Click “Open in ChatGPT” at the top right of any page to analyze documentation with ChatGPT or Claude for deeper insights.