Authentication
Authenticate SDK requests with API keys
The Fanbeam SDK uses API keys for authentication. Configure your API key when setting up the client.
Setting Your API Key
Global Configuration
import { client } from 'fanbeam';
client.setConfig({
baseUrl: 'https://fanbeam.app/api',
headers: {
'X-API-Key': 'your-api-key-here'
}
});Environment Variables
import { client } from 'fanbeam';
client.setConfig({
baseUrl: 'https://fanbeam.app/api',
headers: {
'X-API-Key': process.env.FANBEAM_API_KEY!
}
});Per-Request Configuration
You can also pass a custom client instance to individual requests:
import { posts, createClient } from 'fanbeam';
const customClient = createClient({
baseUrl: 'https://fanbeam.app/api',
headers: {
'X-API-Key': 'different-api-key'
}
});
const response = await posts.list({
client: customClient
});Getting Your API Key
- Log in to your Fanbeam account
- Navigate to Settings → API Keys
- Click Create API Key
- Copy the API key (it's only shown once)
Security Best Practices
- Never commit API keys - Use environment variables
- Rotate regularly - Generate new keys periodically
- Use separate keys - Different keys for dev/staging/prod
- Revoke unused keys - Delete keys that are no longer needed