Category: Vercel and hosting

Openrouter on Vercel: ENV variable is set, but API does not work

Read this guide in Polish

The AI assistant works on localhost, but after publication does not get answers and logs suggest no configuration.

Why is there a problem?

The variable could be added only for the Preview environment, had a typo in the name or did not reach the already built version.

Diagnostics and solutions

1. Compare variable name in code with name in Vercel Environment Variables.

2 . Check Production, Preview and Development range.

3 . Do not display variable value in logs or debug endpoint.

4 . Make a new deploy after updating the configuration if required.

5 . Test endpoint server, support limit and user messages.

How to check and avoid what?

Production responds to the test question and no key displays a controlled message without revealing a secret.

Do not skip the server by placing the Openrouter key in the frontend code.