Fix it in four steps
- Find the exact names your code expects.
Search your code for the key names (for example
OPENAI_API_KEY). The name on the server must match letter for letter, including capitals. - Add the keys where the live app runs.
- In a builder: look in the publishing settings, not the editor. In Replit they are under Publishing, then "Adjust settings", then "Production app secrets".
Source: Replit Docs, "Secrets"
- On your own server with Docker Compose: a container gets no settings unless the Compose file says so. Docker's documentation: "A container's environment is not set until there's an explicit entry in the service configuration to make this happen." Point the service to your file with
env_file: .env, or list the values underenvironment:. The Docker Compose Generator writes an.env.examplethat lists every value to fill in.Source: Docker Docs, "Set environment variables within your container's environment"
- In a builder: look in the publishing settings, not the editor. In Replit they are under Publishing, then "Adjust settings", then "Production app secrets".
- Publish or deploy again.
A running app does not pick up a key you add later. Start a new deploy so the app starts with the new values.
- Keep secret keys out of the browser.
Some names are made public on purpose. In Vite, variables that start with
VITE_"will be exposed in client-side source code", and Vite warns they "should not contain sensitive information such as API keys". In Next.js, variables that start withNEXT_PUBLIC_are "inlined into the JavaScript bundle duringnext build". Both are fixed when the app is built, so changing them later means building again. Keep secret keys without these prefixes and use them only in server code. If a secret key ever had one of these prefixes, treat it as public and create a new one.Source: Vite, "Env Variables and Modes"
Source: Next.js, "How to self-host your Next.js application"
Check that it worked
Open the live app and use the feature that needs the key. Then read the live app's logs. An empty or "undefined" key means the name or the place is still wrong. The "Secrets" part of the Production readiness checklist covers the rest: no secret in the Compose file, .env readable by its owner only, and no secret baked into an image.
Common mistakes
- Uploading the .env file to GitHub to "bring the keys along". Anyone who can see the repository can see the keys. Vite's documentation advises adding local env files (
*.local) to.gitignoreso they are not checked in. - Adding the key in the editor only. The live app reads its own settings (the second step).
- A public prefix on a secret key.
VITE_andNEXT_PUBLIC_values reach every visitor's browser (the fourth step). - Not deploying again. The app keeps running with the old values (the third step).
Limits
- Builder examples come from Replit's documentation; other builders name these screens differently.
- This guide does not cover secret managers or rotating keys on a schedule.
- Never paste a secret key into a tool or chat you don't control. ANAROQ does not host your app.