API Authentication
Overview
aiapi.services uses the Authorization header for authentication:
- Authorization: Bearer Token (API Key)
Authorization Header
Get API Key
- Login to aiapi.services
- Navigate to “Tokens” management page
- Create a new token and copy the key
Usage
cURL
curl https://aiapi.services/v1/chat/completions \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-2.5-flash",
"messages": [{"role": "user", "content": "Hello"}]
}'⚠️ Security Note: Never hardcode API keys in client-side code. Use environment variables.
Common Errors
| Code | Message | Cause | Solution |
|---|---|---|---|
| 401 | Unauthorized | Invalid or expired token | Check token validity |
| 403 | Forbidden | Insufficient permissions | Check user group permissions |
| 429 | Too Many Requests | Rate limit exceeded | Reduce request frequency |
Best Practices
-
Use Environment Variables: Store API keys in environment variables
export AIAPI_KEY="your_api_key" -
Key Rotation: Regularly rotate API keys
-
Least Privilege: Create tokens with minimum required permissions
-
Monitor Usage: Regularly check API usage and anomalies
Last updated on