Auth for Chat
Error Handling
Common errors and solutions
Common Errors
| Status Code | Error | Cause | Solution |
|---|---|---|---|
| 401 | Unauthorized | Invalid API credentials | Check keyId and keySecret |
| 401 | Unauthorized | Expired API key | Generate a new API key |
| 401 | Unauthorized | Insufficient permissions | Enable required permissions on API key |
| 400 | Bad Request | Agent not found | Verify agentId exists and is active |
| 400 | Bad Request | No active agents | Create an active agent for your company |
| 500 | Internal Server Error | Server error | Retry request, contact support if persists |
Example Error Response
{
"statusCode": 401,
"message": "Invalid API credentials",
"error": "Unauthorized"
}Handling Token Expiration
// Auto-refresh token when expired
let currentToken = null;
let tokenExpiresAt = null;
async function getValidToken() {
if (!currentToken || Date.now() >= tokenExpiresAt) {
const response = await fetch('/api/chat/token');
const data = await response.json();
currentToken = data.token;
tokenExpiresAt = Date.now() + (55 * 60 * 1000); // Refresh 5 min early
}
return currentToken;
}Rate Limits
| Operation | Limit | Window |
|---|---|---|
| Token generation | 100 requests | 1 minute |
| Failed authentication | 10 attempts | 5 minutes |
| API requests | 1000 requests | 1 minute |
Exceeding rate limits returns a 429 Too Many Requests response.