Skip to main content
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

  1. Header format. Send Authorization: Bearer sk-.... The word Bearer, one space, then the key.
  2. Key type. Inference keys start with sk-. Management keys start with akm- and cannot call /v1/chat/completions. An sk- key cannot call the Management API.
  3. Base URL. The OpenAI SDK needs https://api.aicredits.in/v1. Anthropic SDKs and Claude Code use https://api.aicredits.in without /v1.
  4. Expiry and status. In the dashboard, check that the key is active and has not passed its expiry date.
  5. Account. A disabled account also returns 401. Email [email protected] if you think that is the case.
  6. 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.