How to troubleshoot AI API errors 401, 402 and 429
Use the response body to diagnose invalid credentials, insufficient balance and throttling.
What should I check first?
Read the error message and code in the response body. A 401 typically indicates authentication failure. A 402 may indicate insufficient balance. A 429 can indicate either rate limiting or exhausted quota.
What should I do for each error?
- 401: Check the Base URL, key, and Authorization header. Verify the key belongs to the service receiving the request.
- 402: Check the balance at the provider named in the error. A gateway allowance and upstream provider balance are separate.
- 429: If the body indicates throttling, honor Retry-After where present. If it indicates exhausted quota, resolve that quota before retrying.
What can I share for troubleshooting?
Record the time, model ID, status code and request ID. Remove credentials and private request content.