/api/v1/sms-api/balance/Check SMS Balance
Retrieve your current SMS balance, including available units, rate per SMS, and total balance value in your account currency.
Authentication Required
This endpoint requires a Bearer token. Get your API key from your dashboard.
When to Check Balance
Request Details
Code Examples
import requests
# Configuration
# Get your API key from: https://roycetalk.com/
# Format: XXXX_XXXXXXXXXXXXXXXXXXXXXXXX_
API_URL = "https://roycetalk.com/api/v1/sms-api/balance/"
BEARER_TOKEN = "XXXX_XXXXXXXXXXXXXXXXXXXXXXXX_"
def check_balance():
"""
Check current SMS balance via RoyceBulkSMS API
Returns:
dict: API response with balance information
"""
# Request headers with Bearer token
headers = {
"Authorization": f"Bearer {BEARER_TOKEN}",
}
try:
# Make GET request
response = requests.get(API_URL, headers=headers)
# Check if request was successful
if response.status_code == 200:
result = response.json()
balance = result['data']
print("✓ Balance retrieved successfully!")
print(f"Current Balance: {balance['current_balance']} units")
print(f"SMS Rate: KES {balance['sms_rate']} per unit")
print(f"Balance Value: KES {balance['balance_value']}")
print(f"Currency: {balance['currency']}")
return result
elif response.status_code == 403:
error = response.json()
print(f"✗ Authentication Error: {error['error']['message']}")
return None
else:
print(f"✗ Unexpected Error: {response.status_code}")
print(response.text)
return None
except requests.exceptions.RequestException as e:
print(f"✗ Request failed: {str(e)}")
return None
# Example usage
if __name__ == "__main__":
balance_info = check_balance()
if balance_info:
# Check if balance is sufficient for campaign
units_needed = 100
current_balance = balance_info['data']['current_balance']
if current_balance >= units_needed:
print(f"\n✓ Sufficient balance for {units_needed} messages")
else:
shortage = units_needed - current_balance
print(f"\n✗ Insufficient balance. Need {shortage} more units")Response Examples
{
"success": true,
"data": {
"current_balance": 9910,
"sms_rate": 0.5,
"balance_value": 4955,
"currency": "KES"
},
"message": "Balance retrieved successfully",
"meta": {
"timestamp": "2025-11-28T14:30:00.000000+00:00",
"api_version": "v1"
},
"errors": []
}Response Fields
current_balanceNumber of SMS units available in your account. Each SMS typically consumes 1 unit (for messages up to 160 characters).
sms_rateCost per SMS unit in your account currency. Standard rate is KES 0.50 per unit.
balance_valueTotal monetary value of your SMS balance (current_balance × sms_rate). This is how much credit you have in currency terms.
currencyCurrency code for your account. Default is KES (Kenyan Shillings).
Best Practices
Cache Balance Data
Balance doesn't change frequently. Cache the result for 5-10 minutes to reduce API calls. The Laravel example includes caching implementation.
Check Before Bulk Sends
Always check balance before initiating bulk campaigns. Use the /calculate-cost/ endpoint to estimate total cost first.
Set Low Balance Alerts
Monitor balance regularly and set up alerts when it drops below a threshold (e.g., 100 units). This prevents campaign failures due to insufficient credits.
Common Integration Patterns
Dashboard Widget
Display current balance on your admin dashboard:
Pre-Send Validation
Validate sufficient balance before sending:
Automated Monitoring
Set up scheduled balance checks with alerts:
Rate Limiting
Balance checks are lightweight and don't count against your SMS rate limits. However, implement caching to avoid unnecessary API calls.