BotGem

How to fix BotGem returning 401 or an invalid API key

401 means the request reached the AI Code With server but authentication failed. The problem is the API key itself, its validity, or the account state — not the Base URL or model.

Start with these checks

The request reached the server but authentication failed.

  • Check Connection or sending a message returns 401, Unauthorized, or Invalid API Key.
  • The pasted API key is incomplete, has extra spaces, or is the wrong key
  • Open BotGem Settings → Service Provider and select the OpenAI API Compatible provider
401UnauthorizedInvalid API Key

01

Confirm the request reached the server

401 / Unauthorized means the request reached the AI Code With endpoint but was rejected at authentication. Do not change the Base URL or model yet — check the API key first.

02

Re-paste and verify the API key

In BotGem Settings → Service Provider, select the provider and paste the full API key into the API Key field. Avoid copying line breaks or spaces.

  1. 1Open BotGem Settings → Service Provider and select the OpenAI API Compatible provider
  2. 2Re-paste the full API key into the API Key field without extra spaces

03

Verify the key and account

Confirm on the AI Code With API key page that the key is valid and the account has balance. After Check Connection passes and you save, messages no longer returning 401 means the credential chain is restored.

  1. 1Re-paste the full API key into the API Key field without extra spaces
  2. 2Confirm the key is a valid AI Code With API key (see the API key page)

If it is still not fixed

Sources

Reconfigure

Return to the integration center and continue the setup steps.

Return to the related setup step