🔑 API Key Setup Guide
Prerequisites
Before starting, ensure you have Node.js 16+ installed and basic knowledge of JavaScript/TypeScript.
Overview
The BRDZ SDK requires an API Key to authenticate all requests to the BRDZ API. This guide will walk you through generating and configuring your API key.
Understanding API Keys vs JWT Tokens
| Type | Purpose | Required For | Lifetime |
|---|---|---|---|
| API Key | Identifies your application/SDK client | All API requests | Long-lived (until revoked) |
| JWT Token | Identifies the logged-in user | Authenticated endpoints only | Short-lived (expires) |
Quick Start
Step 1: Generate API Key
For Development/Testing (No Auth Required):
curl -X POST https://api.brdz.link/api/keys/generate-sdk-key \
-H "Content-Type: application/json" \
-H "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36" \
-d '{"provider_name": "My App Development"}'
Expected Response:
{
"success": true,
"api_key": "f868a9cdc377916bcc33b93b5035f70b180df048b1d041e94d7f157c1464c4e7",
"provider_name": "My App Development",
"created_at": "2024-01-15T10:30:00Z"
}
Step 2: Configure SDK
import brdzSDK from 'anantla_sdk';
// Initialize configuration
const config = brdzSDK.config;
// Required: Set base URL
config.setBaseUrl('https://api.brdz.link/api');
// Required: Set API Key (from Step 1)
config.setApiKey('f868a9cdc377916bcc33b93b5035f70b180df048b1d041e94d7f157c1464c4e7');
// Optional: Set JWT token (after user login)
// config.setToken('your_jwt_token_here');
Step 3: Verify Setup
try {
// Test API call (no auth required)
const result = await brdzSDK.mcp.step1_detectIntent({
prompt: "test connection"
});
console.log('✅ SDK configured successfully!');
console.log('Response:', result);
} catch (error) {
console.error('❌ Setup failed:', error.message);
// Common error handling
if (error.message.includes('API key is missing')) {
console.log('→ Missing API key - run setApiKey() first');
}
if (error.message.includes('invalid API key')) {
console.log('→ Invalid API key - generate a new one');
}
}
Production Setup
Environment Variables
Create environment files:
.env
# Backend Environment
BRDZ_API_BASE=https://api.brdz.link/api
BRDZ_API_KEY=your_generated_api_key_here
BRDZ_JWT_TOKEN=user_jwt_token_after_login
.env.local
# Frontend Environment (React/Next.js)
REACT_APP_BRDZ_API_KEY=your_generated_api_key_here
NEXT_PUBLIC_BRDZ_API_KEY=your_generated_api_key_here
VITE_BRDZ_API_KEY=your_generated_api_key_here
Production Configuration
// Load environment variables
require('dotenv').config();
// Configure SDK
const config = brdzSDK.config;
config.setBaseUrl(process.env.BRDZ_API_BASE);
config.setApiKey(process.env.BRDZ_API_KEY);
// Set user token if available
if (process.env.BRDZ_JWT_TOKEN) {
config.setToken(process.env.BRDZ_JWT_TOKEN);
}
Advanced Setup
Team/Production API Keys
For production applications with user authentication:
# Requires valid JWT token
curl -X POST https://api.brdz.link/api/keys/sdk-key \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_JWT_TOKEN" \
-d '{"provider_name": "Production App v1.0"}'
Complete Setup Class
class BRDZClient {
constructor() {
this.sdkReady = false;
this.init();
}
async init() {
try {
const config = brdzSDK.config;
// Step 1: Configure base URL
config.setBaseUrl('https://api.brdz.link/api');
// Step 2: Set API Key
const apiKey = process.env.REACT_APP_BRDZ_API_KEY ||
process.env.BRDZ_API_KEY;
if (!apiKey) {
throw new Error('API Key not found in environment variables');
}
config.setApiKey(apiKey);
// Step 3: Set JWT token if user is logged in
const authToken = localStorage.getItem('brdz_auth_token');
if (authToken) {
config.setToken(authToken);
}
// Step 4: Verify configuration
await this.verifySetup();
this.sdkReady = true;
console.log('✅ BRDZ SDK initialized successfully');
} catch (error) {
console.error('❌ SDK initialization failed:', error);
throw error;
}
}
async verifySetup() {
// Test with a simple API call
const utils = brdzSDK.utils;
utils.validateSDKSetup();
}
async login(email, password) {
if (!this.sdkReady) {
throw new Error('SDK not ready. Call init() first.');
}
try {
const auth = brdzSDK.auth;
const result = await auth.loginUser(email, password);
// Save JWT token
localStorage.setItem('brdz_auth_token', result.token);
localStorage.setItem('user_id', result.user_id);
// Update SDK configuration
const config = brdzSDK.config;
config.setToken(result.token);
return result;
} catch (error) {
if (error.message.includes('API key is missing')) {
throw new Error('API Key not configured. Check your environment variables.');
}
throw error;
}
}
}
// Usage
const brdzClient = new BRDZClient();
Troubleshooting
Common Issues
❌ "API key is missing"
// Solution: Make sure you call setApiKey()
const config = brdzSDK.config;
config.setApiKey('your_api_key_here');
❌ "Invalid API key"
// Solution: Generate a new API key
// 1. Use the curl command above
// 2. Update your environment variables
// 3. Restart your application
❌ API calls fail silently
// Solution: Check your headers
const utils = brdzSDK.utils;
utils.debugHeaders(); // Shows current configuration
Debug Mode
Enable detailed logging:
// Enable debug mode
process.env.DEBUG = 'brdz-sdk:*';
// Check current configuration
const utils = brdzSDK.utils;
utils.debugHeaders();
utils.validateSDKSetup();
API Key Management
Key Rotation
// 1. Generate new key
const apikey = brdzSDK.apikey;
const newKey = await apikey.create('Updated App v2.0');
// 2. Update configuration
config.setApiKey(newKey.api_key);
// 3. Update environment variables
// 4. Deploy updated configuration
List Your Keys
const apikey = brdzSDK.apikey;
const keys = await apikey.list();
console.log('Your API Keys:', keys);
Remove Old Keys
const apikey = brdzSDK.apikey;
await apikey.remove('old_api_key_to_remove');
Security Best Practices
Security Guidelines
- Never expose API keys in client-side code repositories
- Use environment variables for all sensitive configuration
- Rotate keys regularly for production applications
- Use different keys for development, staging, and production
- Monitor API key usage through your dashboard
Environment-Specific Keys
// Development
const DEV_API_KEY = 'dev_f868a9cdc377916bcc33b93b5035f70b';
// Staging
const STAGING_API_KEY = 'stg_a123b456c789d012e345f678g901h234';
// Production
const PROD_API_KEY = 'prod_x987y654z321w098v765u432t109s876';
// Configuration
const config = brdzSDK.config;
config.setApiKey(
process.env.NODE_ENV === 'production' ? PROD_API_KEY :
process.env.NODE_ENV === 'staging' ? STAGING_API_KEY :
DEV_API_KEY
);
Next Steps
Once your API key is configured:
- Authentication Guide - Guidance on how set up user login
- Quickstart Tutorial - Guidance on how build your first app
- React Integration - Examples of Frontend components
Need Help?
If you encounter issues:
- Check the Troubleshooting section above
- Email: support@anantla.org
- Contact: BRDZ Support Form