APITroubleshooting
401 error: invalid or missing API key
Why AICredits returns 401 authentication_error and how to fix it. Check the key format, the Authorization header, expiry and account status.
Use this page with an AI assistant
Opens a new chat with this docs URL and the correct AICredits base URLs.
A 401 response with type: authentication_error means the key or the account cannot be used. The request never reached a model, so you are not charged.
Check these in order
- Header format. Send
Authorization: Bearer sk-.... The wordBearer, one space, then the key. - Key type. Inference keys start with
sk-. Management keys start withakm-and cannot call/v1/chat/completions. Ansk-key cannot call the Management API. - Base URL. The OpenAI SDK needs
https://api.aicredits.in/v1. Anthropic SDKs and Claude Code usehttps://api.aicredits.inwithout/v1. - Expiry and status. In the dashboard, check that the key is active and has not passed its expiry date.
- Account. A disabled account also returns 401. Email [email protected] if you think that is the case.
- Copy errors. Look for a leading or trailing space or a line break in the key, and for a stale key in a shell variable.
Claude Code
Set ANTHROPIC_AUTH_TOKEN to your key and unset ANTHROPIC_API_KEY. If both are set, the wrong one may be sent.