How to protect an API key?

QuestionBeginner

Put it in an environment variable on the server only. Do not put it in front-end code or behind prefixes such as VITE_ and NEXT_PUBLIC_, and do not push .env to Git. If it leaks, revoke it immediately.