What is Error Handling?
This guide helps you understand common errors you might encounter when using Model Router and how to resolve them.Common Errors and Solutions
Authentication Errors
Error: “Invalid API Key” or 401 Unauthorized
What it means: Your API key is incorrect, missing, or invalid. How to fix:- Check that your API key starts with
sk- - Verify you copied the entire API key correctly
- Make sure you’re including it in the
Authorizationheader:Bearer sk-your-key - If you lost your key, create a new one in the console
Error: “API key not found”
What it means: The API key doesn’t exist or has been deleted. How to fix:- Verify the API key exists in the console
- Create a new API key if needed
- Make sure you’re using the correct API key
Model Errors
Error: “Model not found” or “Model does not exist”
What it means: The model you’re trying to use isn’t available to your API key. How to fix:- Check List Available Models to see which models you can use
- Verify the model name is spelled correctly (model names are case-sensitive)
- Use the exact model
idfrom the model list - Contact your administrator if you need access to a specific model
Error: “Model is not available”
What it means: The model exists but isn’t enabled for your API key group. How to fix:- Check which models are available to your API key
- Contact your administrator to enable the model for your group
- See Limits and Prerequisites for more information
Quota Errors
Error: “Insufficient quota” or “Quota exceeded”
What it means: You don’t have enough quota to make the request. How to fix:- Check your balance in the console under Billing → Overview
- View your usage to see how much you’ve consumed
- Top up credits, or ask your team admin to raise your member quota
- Confirm you’re in the intended space — personal and team contexts draw on different quota pools
Quota is checked before each request. If you don’t have enough quota, the request will be rejected immediately. See View Usage and Billing for details.
Rate Limiting Errors
Error: 429 “Too Many Requests” or “Rate limit exceeded”
What it means: You’re making requests too quickly. How to fix:- Wait a moment and try again
- Reduce the frequency of your requests
- Implement exponential backoff in your code
- Batch requests if possible
- See Reliability and Failover for retry strategies
Request Format Errors
Error: “Invalid request format” or 400 Bad Request
What it means: The request body or parameters are incorrect. How to fix:- Check that your request body is valid JSON
- Verify all required fields are present
- Make sure field names and types match the API specification
- Review the Direct API Requests guide for correct format
Error: “Missing required field”
What it means: A required parameter is missing from your request. How to fix:- Check the API documentation for required fields
- Verify all required parameters are included
- Check that field names are spelled correctly
Network Errors
Error: “Connection timeout” or “Network error”
What it means: The request couldn’t reach the server or took too long. How to fix:- Check your internet connection
- Verify the API endpoint URL is correct:
https://app.memorylake.ai - Try again after a moment
- Check if there are any network issues
- See Reliability and Failover for automatic retry mechanisms
Streaming Errors
Error: “Stream connection closed unexpectedly”
What it means: The streaming connection was interrupted. How to fix:- This is normal for long streams - implement reconnection logic
- Check your network stability
- Handle stream interruptions gracefully in your code
- See Reliability and Failover for streaming best practices
Error Response Format
When an error occurs, the API returns a JSON response with error details:Best Practices for Error Handling
- Always check the response status: Handle both success and error cases
- Read error messages: The error message usually tells you what went wrong
- Implement retry logic: For transient errors like rate limits or network issues
- Log errors: Keep track of errors for debugging
- Handle gracefully: Don’t crash your application on API errors
Example: Error Handling in Code
Python Example
Getting Help
If you’re still having issues:- Check the Limits and Prerequisites guide
- Review the Reliability and Failover documentation
- Check your API key and model availability
- Contact support@memorylake.ai with:
- The exact error message
- Your API key (masked)
- The request you were making
- Any relevant logs