Category: Forms and APIs

Openrouter API returns 401 Unauthorized — what to check?

Read this guide in Polish

Chat page shows an error instead of an answer, and endpoint Openrouter returns 401 Unauthorized.

Why is there a problem?

Usually the problem concerns the key, the Authorization header format, the permissions or the wrong environment from which the key is read.

Diagnostics and solutions

1. Check the response status and request ID in the logs without printing the API key.

2 . Verify if the server code uses the corresponding environment variable.

3 . Make sure the header has the required Bearer format and does not contain random spaces.

4 . Check the key status and possible limitations in the supplier panel.

5 . After turning the key, perform a new deploy or reboot according to the platform and test on a short question.

How to check and avoid what?

The server receives the correct response from the API and the key does not appear in HTML, console or repository.

Never send a secret key from a browser via NEXT PUBLAC or a client code.