๐ Authentication
Sendly uses API keys to authenticate requests. Your API keys carry many privileges, so be sure to keep them secure! Do not share your secret API keys in publicly accessible areas such as GitHub, client-side code, and so forth.
API Key Typesโ
Sendly provides two types of API keys:
๐งช Test Keysโ
- Format: 
sl_test_xxxxxxxxxx - Purpose: Development and testing
 - Behavior: No SMS sent, no charges
 - Rate Limits: Same as live keys
 - Webhooks: Simulated events
 
๐ Live Keysโ
- Format: 
sl_live_xxxxxxxxxx - Purpose: Production use
 - Behavior: Real SMS sent, charges apply
 - Rate Limits: Based on your plan
 - Webhooks: Real delivery events
 
Getting Your API Keyโ
- Sign up at sendly.live
 - Navigate to your dashboard
 - Go to API Keys section
 - Create a new key or copy existing ones
 - Choose test or live mode
 
๐ Security Best Practices
- Never expose API keys in client-side code
 - Use environment variables for API keys
 - Rotate keys regularly
 - Use test keys for development
 - Monitor key usage in dashboard
 
Authentication Methodsโ
HTTP Bearer Token (Recommended)โ
The most common and secure method:
Using Authorization Header
curl -X POST https://sendly.live/api/v1/send \
  -H "Authorization: Bearer sl_live_YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "to": "+1234567890",
    "text": "Hello world!"
  }'
SDK Authenticationโ
All our SDKs handle authentication automatically:
- Node.js
 - Python
 - cURL
 
Node.js SDK Authentication
import { SendlyClient } from '@sendly/node';
// Option 1: Direct API key
const sendly = new SendlyClient({
  apiKey: 'sl_live_YOUR_API_KEY'
});
// Option 2: Environment variable (recommended)
// Set SENDLY_API_KEY in your environment
const sendly = new SendlyClient(); // Auto-loads from env
// Option 3: Custom configuration
const sendly = new SendlyClient({
  apiKey: process.env.SENDLY_API_KEY,
  baseURL: 'https://sendly.live/api', // Optional
  timeout: 30000 // Optional timeout in ms
});
Python SDK Authentication
from sendly import Sendly
import os
# Option 1: Direct API key
client = Sendly(api_key='sl_live_YOUR_API_KEY')
# Option 2: Environment variable (recommended)
# Set SENDLY_API_KEY in your environment
client = Sendly()  # Auto-loads from env
# Option 3: Custom configuration
client = Sendly(
    api_key=os.environ.get('SENDLY_API_KEY'),
    base_url='https://sendly.live/api',  # Optional
    timeout=30.0  # Optional timeout in seconds
)
cURL Authentication
# Set as environment variable (recommended)
export SENDLY_API_KEY="sl_live_YOUR_API_KEY"
# Use in requests
curl -X POST https://sendly.live/api/v1/send \
  -H "Authorization: Bearer $SENDLY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"to": "+1234567890", "text": "Hello!"}'
# Or inline (not recommended for production)
curl -X POST https://sendly.live/api/v1/send \
  -H "Authorization: Bearer sl_live_YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"to": "+1234567890", "text": "Hello!"}'
Environment Variablesโ
Setting Environment Variablesโ
- Bash/Zsh
 - .env File
 - Docker
 - Vercel
 
~/.bashrc or ~/.zshrc
# Add to your shell configuration file
export SENDLY_API_KEY="sl_live_YOUR_API_KEY"
# Reload your shell
source ~/.bashrc  # or ~/.zshrc
.env
# Create a .env file in your project root
SENDLY_API_KEY=sl_live_YOUR_API_KEY
SENDLY_WEBHOOK_SECRET=whsec_YOUR_WEBHOOK_SECRET
# Add .env to your .gitignore file!
Load with dotenv (Node.js)
import dotenv from 'dotenv';
dotenv.config();
import { SendlyClient } from '@sendly/node';
const sendly = new SendlyClient(); // Uses process.env.SENDLY_API_KEY
Dockerfile
# Set environment variable in Dockerfile
ENV SENDLY_API_KEY=sl_live_YOUR_API_KEY
Docker Run
# Pass environment variable at runtime
docker run -e SENDLY_API_KEY=sl_live_YOUR_API_KEY your-app
# Or use env file
docker run --env-file .env your-app
Vercel CLI
# Set environment variable for Vercel deployment
vercel env add SENDLY_API_KEY
# Or in vercel.json
{
  "env": {
    "SENDLY_API_KEY": "@sendly-api-key"
  }
}
Error Handlingโ
Authentication Errorsโ
When authentication fails, you'll receive a 401 Unauthorized response:
Authentication Error Response
{
  "error": "authentication_error",
  "message": "Invalid API key provided",
  "code": "invalid_api_key",
  "statusCode": 401
}
Common Authentication Issuesโ
| Issue | Cause | Solution | 
|---|---|---|
401 Unauthorized | Invalid API key | Check key format and validity | 
401 Unauthorized | Missing Authorization header | Add Authorization: Bearer <key> | 
403 Forbidden | API key lacks permissions | Use correct key type (test/live) | 
429 Rate Limited | Too many requests | Implement rate limiting | 
SDK Error Handlingโ
- Node.js
 - Python
 
Handle Authentication Errors
import { SendlyClient, SendlyError } from '@sendly/node';
const sendly = new SendlyClient({
  apiKey: 'sl_live_YOUR_API_KEY'
});
try {
  const result = await sendly.sms.send({
    to: '+1234567890',
    text: 'Hello world!'
  });
  console.log('Success:', result.messageId);
} catch (error) {
  if (error instanceof SendlyError) {
    switch (error.code) {
      case 'authentication_error':
        console.error('Invalid API key:', error.message);
        break;
      case 'rate_limit_exceeded':
        console.error('Rate limited:', error.message);
        break;
      default:
        console.error('API error:', error.message);
    }
  } else {
    console.error('Network error:', error.message);
  }
}
Handle Authentication Errors
from sendly import Sendly
from sendly.errors import AuthenticationError, RateLimitError, APIError
client = Sendly(api_key='sl_live_YOUR_API_KEY')
try:
    response = client.sms.send(
        to='+1234567890',
        text='Hello world!'
    )
    print(f'Success: {response.id}')
    
except AuthenticationError as e:
    print(f'Invalid API key: {e.message}')
    
except RateLimitError as e:
    print(f'Rate limited: {e.message}')
    if e.retry_after:
        print(f'Retry after {e.retry_after} seconds')
        
except APIError as e:
    print(f'API error: {e.message}')
    
finally:
    client.close()
API Key Managementโ
Dashboard Featuresโ
Access your API key management in the Sendly Dashboard:
- ๐ Usage Analytics - Monitor API key usage and costs
 - ๐ Key Rotation - Create new keys and deactivate old ones
 - โ๏ธ Permissions - Set key-specific permissions and limits
 - ๐ Rate Limits - View and upgrade rate limits
 - ๐ Alerts - Set up usage and security alerts
 
Key Rotation Best Practicesโ
- Regular Rotation - Rotate keys every 90 days
 - Gradual Migration - Deploy new keys before deactivating old ones
 - Monitoring - Watch for authentication errors during rotation
 - Documentation - Update your team's documentation
 
Key Rotation Example
// Step 1: Create new API key in dashboard
// Step 2: Update your environment variables
const oldKey = process.env.SENDLY_API_KEY_OLD;
const newKey = process.env.SENDLY_API_KEY_NEW;
// Step 3: Gradual migration with fallback
const sendly = new SendlyClient({
  apiKey: newKey || oldKey
});
// Step 4: Monitor and remove old key
Security Considerationsโ
โ Do'sโ
- โ Use environment variables for API keys
 - โ Implement proper error handling
 - โ Monitor API key usage regularly
 - โ Use test keys for development
 - โ Rotate keys regularly
 - โ Set up rate limiting
 - โ Use HTTPS for all requests
 
โ Don'tsโ
- โ Hardcode API keys in source code
 - โ Commit API keys to version control
 - โ Share API keys in public channels
 - โ Use live keys for testing
 - โ Ignore authentication errors
 - โ Use HTTP for API requests
 
Webhook Authenticationโ
Webhooks also require authentication to ensure security:
Webhook Signature Verification
import crypto from 'crypto';
function verifyWebhookSignature(payload, signature, secret) {
  const expectedSignature = crypto
    .createHmac('sha256', secret)
    .update(payload, 'utf8')
    .digest('hex');
    
  return `sha256=${expectedSignature}` === signature;
}
// In your webhook handler
app.post('/webhook', (req, res) => {
  const signature = req.headers['x-sendly-signature'];
  const payload = JSON.stringify(req.body);
  
  if (!verifyWebhookSignature(payload, signature, process.env.SENDLY_WEBHOOK_SECRET)) {
    return res.status(401).send('Invalid signature');
  }
  
  // Process webhook...
  res.status(200).send('OK');
});
๐ Need Help?
- ๐ง Email Support - support@sendly.live
 - ๐ฌ Discord - discord.gg/sendly
 - ๐ Security Guide - /guides/security
 - ๐ง Dashboard - dashboard.sendly.live
 
Next Stepsโ
Now that you understand authentication, explore these guides:
- ๐ฑ Send Your First SMS - Put authentication into practice
 - ๐ฎ API Playground - Test with your API keys
 - ๐ Webhook Security - Secure webhook authentication
 - ๐ ๏ธ SDK Guides - Language-specific authentication examples