Authentication
The SMS Gateway API supports two authentication methods: API Keys for SMS API access and JWT Bearer Tokens for dashboard and management operations. All requests must be authenticated.
Overview
API Key Authentication
Best for server-to-server communication. Use for all SMS API endpoints including sending messages, checking status, and OTP operations.
JWT Token Authentication
Best for dashboard integrations and management APIs. Provides short-lived access with refresh token rotation.
API Key Authentication
API keys are long-lived credentials that authenticate your server-side requests to the SMS API. Each key is scoped to specific permissions and can optionally be restricted to a set of allowed IP addresses.
Generating an API Key
- Navigate to Developer → API Keys in the dashboard.
- Click Generate New Key.
- Enter a descriptive name (e.g., “Production SMS”).
- Select the required permission scopes.
- Optionally add IP address restrictions for enhanced security.
- Click Create and copy the generated key.
Using the API Key
Include the API key in the Authorization header of every request using the Bearer scheme:
1Authorization: Bearer sg_live_xxxxxxxxxxxx1curl -X POST https://api.smsgateway.com/api/v1/sms/send \2 -H "Authorization: Bearer sg_live_xxxxxxxxxxxx" \3 -H "Content-Type: application/json" \4 -d '{5 "to": "+251911234567",6 "body": "Hello from SMS Gateway!"7 }'Security Best Practices
Store securely: Keep API keys in environment variables or a secrets manager. Never commit them to source control.
Use IP restrictions: Limit key usage to your server IP addresses to prevent unauthorized access.
Apply least privilege: Only grant the permission scopes your application needs.
Rotate regularly: Rotate keys periodically and immediately if a compromise is suspected.
Monitor usage: Review API logs in the dashboard to detect unusual activity.
Key Prefixes
| Prefix | Environment | Description |
|---|---|---|
| sg_live_ | Production | Live API key — messages are billed and delivered. |
| sg_test_ | Sandbox | Test API key — messages are simulated, not delivered. |