The SRT Live Server now includes a secure REST API with authentication, rate limiting, and SQLite database storage. All API endpoints (except /health and /stats) require authentication using Bearer tokens.
All API requests must include an Authorization header:
Authorization: Bearer <API_KEY>
When the server starts for the first time, it will generate a default admin API key and print it to the console:
Generated default admin API key: <32-character-key>
IMPORTANT: Save this key securely. It will not be shown again.
Check if the server is running.
GET /health
Response:
{
"status": "ok",
"service": "srt-live-server",
"version": "1.6.0"
}GET /api/stream-ids
Authorization: Bearer <API_KEY>
Response:
{
"status": "success",
"data": [
{
"publisher": "studio_1",
"player": "live_stream",
"description": "Main studio feed"
}
]
}POST /api/stream-ids
Authorization: Bearer <API_KEY>
Content-Type: application/json
{
"publisher": "studio_1",
"player": "live_stream",
"description": "Main studio feed (optional)"
}
Required Permissions: admin or write
Response:
200 OK- Stream ID added successfully{ "status": "success", "message": "Stream ID added successfully" }400 Bad Request- Invalid request body or missing required fields401 Unauthorized- Invalid or missing API key403 Forbidden- Insufficient permissions409 Conflict- Stream ID with the given player ID already exists{ "status": "error", "message": "Stream ID with player 'demo' already exists" }
DELETE /api/stream-ids/{player_id}
Authorization: Bearer <API_KEY>
Required Permissions: admin
Response:
{
"status": "success",
"message": "Stream ID deleted successfully"
}Get real-time statistics for a specific publisher (using player ID).
Note: This endpoint does not require authentication.
Endpoint: GET /stats/{player_id}
Parameters:
player_id(path) - The player ID associated with the publisherreset(query, optional) - Reset statistics after retrievallegacy(query, optional) - Use legacy format with detailed information (set to "1")
Response:
{
"publisher": {
"bitrate": 16363,
"buffer": 1995,
"dropped_pkts": 45,
"rtt": 30.2,
"uptime": 3600,
"latency": 2000
},
"status": "ok"
}Legacy Format with `legacy=1`
{
"publishers": {
"live": {
"bitrate": 16363,
"bytes_rcv_drop": 0,
"bytes_rcv_loss": 0,
"mbps_bandwidth": 2.1,
"mbps_recv_rate": 2.4,
"ms_rcv_buf": 1984,
"pkt_rcv_drop": 0,
"pkt_rcv_loss": 0,
"rtt": 30.2,
"uptime": 3600,
"latency": 2000
}
},
"status": "ok"
}POST /api/keys
Authorization: Bearer <API_KEY>
Content-Type: application/json
{
"name": "Frontend App",
"permissions": "read"
}
Required Permissions: admin
Permission Levels:
admin: Full access to all endpointswrite: Can read and write stream IDsread: Read-only access
Response:
{
"status": "success",
"api_key": "<new-32-character-key>",
"message": "Save this key securely. It cannot be retrieved again."
}The API implements rate limiting to prevent abuse. Each endpoint type has its own separate rate limit:
- API endpoints (
api): 30 requests per minute per IP (configurable viarate_limit_api)- GET /api/stream-ids
- POST /api/stream-ids
- DELETE /api/stream-ids/{player_id}
- Statistics (
stats): 300 requests per minute per IP (configurable viarate_limit_stats)- GET /stats/{player_id}
- Configuration (
config): 20 requests per minute per IP (configurable viarate_limit_config)- POST /api/keys
Each endpoint type is tracked separately, so high usage of statistics endpoints won't affect your ability to use other API endpoints.
Rate limits can be configured in sls.conf:
srt {
# Rate limiting configuration (requests per minute)
rate_limit_api 30; # For API endpoints (stream IDs)
rate_limit_stats 300; # For statistics endpoints
rate_limit_config 20; # For configuration endpoints (config, API keys)
}
When rate limit is exceeded:
{
"status": "error",
"message": "Rate limit exceeded"
}{
"status": "error",
"message": "Missing or invalid Authorization header"
}{
"status": "error",
"message": "Insufficient permissions"
}{
"status": "error",
"message": "Stream ID not found"
}{
"status": "error",
"message": "Rate limit exceeded"
}The SQLite database (/etc/sls/streams.db) contains:
id: Primary keypublisher: Publisher stream IDplayer: Player stream ID (unique)description: Optional descriptioncreated_at: Creation timestampupdated_at: Last update timestamp
id: Primary keykey_hash: SHA256 hash of API keyname: Key name/descriptionpermissions: Permission level (admin/write/read)created_at: Creation timestamplast_used: Last usage timestampactive: Boolean status
id: Primary keyapi_key_id: Foreign key to api_keysendpoint: API endpoint accessedmethod: HTTP methodip_address: Client IPtimestamp: Access timestampresponse_code: HTTP response code
# Get all stream IDs
curl -H "Authorization: Bearer YOUR_API_KEY" \
http://hostname:8080/api/stream-ids
# Add new stream ID
curl -X POST -H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"publisher":"studio_1","player":"live_stream"}' \
http://hostname:8080/api/stream-ids
# Get statistics
curl -H "Authorization: Bearer YOUR_API_KEY" \
http://hostname:8080/stats/live_streamimport requests
API_KEY = "your_api_key_here"
BASE_URL = "http://hostname:8080"
headers = {"Authorization": f"Bearer {API_KEY}"}
# List stream IDs
response = requests.get(f"{BASE_URL}/api/stream-ids", headers=headers)
stream_ids = response.json()
# Add new stream ID
data = {
"publisher": "studio_1",
"player": "live_stream",
"description": "Main studio feed"
}
response = requests.post(f"{BASE_URL}/api/stream-ids", json=data, headers=headers)const API_KEY = 'your_api_key_here';
const BASE_URL = 'http://hostname:8080';
// List stream IDs
fetch(`${BASE_URL}/api/stream-ids`, {
headers: {
'Authorization': `Bearer ${API_KEY}`
}
})
.then(response => response.json())
.then(data => console.log(data));
// Add new stream ID
fetch(`${BASE_URL}/api/stream-ids`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
publisher: 'studio_1',
player: 'live_stream',
description: 'Main studio feed'
})
})
.then(response => response.json())
.then(data => console.log(data));- API Keys: Store API keys securely. Never commit them to version control.
- HTTPS: In production, use HTTPS to protect API keys in transit.
- Network Security: Restrict API access to trusted networks.
- Database Backup: Regularly backup the SQLite database.
- Log Monitoring: Monitor access_logs for suspicious activity.