Authentication
Learn how to authenticate with the AltSportsData API
Authentication
All API requests require authentication. The AltSportsData API uses API keys delivered via HTTP headers.
Getting Your API Key
Contact the AltSportsData team to obtain production API credentials:
- Email: connect@altsportsdata.com
- Website: altsportsdata.com
For testing, use a demo key matching the pattern demo-xxxx (e.g., demo-test123). Demo keys provide access to a curated subset of ~50 verified leagues with rate limits applied.
Authentication Methods
1. Bearer Token (Recommended)
Include your API key in the Authorization header:
Authorization: Bearer YOUR_API_KEY2. X-API-Key Header
Alternatively, use the X-API-Key header:
X-API-Key: YOUR_API_KEYBoth methods are equivalent. Choose whichever fits your HTTP client best.
Example Requests
import { AltSportsData } from 'altsportsdata';
// SDK handles authentication automatically
const client = new AltSportsData({
apiKey: process.env.ASD_API_KEY,
});
const health = await client.health();
console.log(health.data.status); // "healthy"from altsportsdata import AltSportsData
# SDK handles authentication automatically
client = AltSportsData(api_key="YOUR_API_KEY")
health = client.health()
print(health.data["status"]) # "healthy"# Using Bearer token
curl -X GET "https://api.altsportsdata.com/v1/health" \
-H "Authorization: Bearer YOUR_API_KEY"
# Or using X-API-Key header
curl -X GET "https://api.altsportsdata.com/v1/health" \
-H "X-API-Key: YOUR_API_KEY"const response = await fetch("https://api.altsportsdata.com/v1/health", {
headers: {
"Authorization": "Bearer YOUR_API_KEY"
}
});
const data = await response.json();
console.log(data);require 'net/http'
require 'json'
uri = URI('https://api.altsportsdata.com/v1/health')
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Get.new(uri)
request['Authorization'] = 'Bearer YOUR_API_KEY'
response = http.request(request)
puts JSON.parse(response.body)<?php
$ch = curl_init('https://api.altsportsdata.com/v1/health');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer YOUR_API_KEY'
]);
$response = curl_exec($ch);
$data = json_decode($response, true);
curl_close($ch);
print_r($data);
?>using var client = new HttpClient();
client.DefaultRequestHeaders.Add("Authorization", "Bearer YOUR_API_KEY");
var response = await client.GetStringAsync("https://api.altsportsdata.com/v1/health");
Console.WriteLine(response);req, _ := http.NewRequest("GET", "https://api.altsportsdata.com/v1/health", nil)
req.Header.Set("Authorization", "Bearer YOUR_API_KEY")
resp, _ := http.DefaultClient.Do(req)
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
fmt.Println(string(body))URL url = new URL("https://api.altsportsdata.com/v1/health");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Authorization", "Bearer YOUR_API_KEY");
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
StringBuilder response = new StringBuilder();
while ((line = in.readLine()) != null) response.append(line);
in.close();
System.out.println(response.toString());Error Responses
| Status Code | Description |
|---|---|
401 Unauthorized | Missing or invalid API key |
403 Forbidden | API key does not have access to the requested resource |
429 Too Many Requests | Rate limit exceeded |
Security Best Practices
- Never expose API keys in client-side code or public repositories
- Use environment variables to store API keys (
ASD_API_KEY) - Rotate keys regularly for enhanced security
- Use HTTPS only — all API requests are served over TLS (enforced)
- Restrict key scope — use demo keys for development, production keys for live traffic
Demo vs Production Keys
| Feature | Demo Key (demo-xxxx) | Production Key |
|---|---|---|
| Access | ~50 curated leagues | All leagues |
| Rate Limit | Restricted | Based on plan |
| Real-time Data | No | Yes |
| WebSocket Access | No | Yes |
| Support | Community | Dedicated |
Need Help?
For API access, technical support, or partnership inquiries, contact connect@altsportsdata.com.