Overview
This guide covers all possible errors you may encounter when using the SundayPyjamas AI Suite API, along with best practices for handling them gracefully in your applications.All API errors follow a consistent JSON format with human-readable error messages and appropriate HTTP status codes.
Error Response Format
Standard Error Format
All API errors return a consistent JSON structure:Enhanced Error Format
Some errors may include additional fields for better debugging:HTTP Status Codes
400 Bad Request
Invalid request format or parameters.Missing Messages Array
Missing Messages Array
messages arraySolution: Ensure your request includes a valid messages arrayInvalid Message Format
Invalid Message Format
content field or empty contentSolution: Ensure all messages have valid role and content fieldsInvalid Request Body
Invalid Request Body
401 Unauthorized
Authentication issues with your API key.Invalid API Key
Invalid API Key
- API key doesn’t exist or has been deleted
- API key format is incorrect
- API key has been deactivated
- Verify your API key is correct and active
- Check the key format:
spj_ai_[64-character-string] - Generate a new API key if needed
Missing Authorization Header
Missing Authorization Header
403 Forbidden
Permission or limit issues.Token Limit Exceeded
Token Limit Exceeded
- Wait for monthly reset
- Upgrade subscription plan
- Optimize prompts to use fewer tokens
Insufficient Permissions
Insufficient Permissions
404 Not Found
Resource doesn’t exist.API Key Not Found
API Key Not Found
Endpoint Not Found
Endpoint Not Found
Cause: Invalid API endpoint URLSolution: Check the API documentation for correct endpoints
429 Too Many Requests
Rate limiting applied.500 Internal Server Error
Server-side issues.AI Service Error
AI Service Error
- AI model temporarily unavailable
- Server overload
- Temporary service disruption
AI Model Initialization Error
AI Model Initialization Error
502 Bad Gateway
503 Service Unavailable
Error Handling Patterns
Basic Error Handling
Comprehensive Error Handling
Error Recovery Strategies
Graceful Degradation
Circuit Breaker Pattern
Retry with Jitter
Debugging Tips
Enable Detailed Logging
Test Error Scenarios
Error Monitoring
Best Practices Summary
Always Handle Errors
Implement comprehensive error handling for all API calls
Use Exponential Backoff
Retry with increasing delays for transient errors
Graceful Degradation
Provide fallback responses when the API is unavailable
Monitor Error Patterns
Track error frequencies to identify and fix issues
Validate Inputs
Validate requests before sending to avoid 400 errors
Secure API Keys
Protect API keys and handle auth errors appropriately
Log for Debugging
Implement detailed logging for troubleshooting
Circuit Breaker
Use circuit breakers to prevent cascade failures

