# Where do my API keys go?

> On your computer, secret keys go in a .env file that Git ignores. For your site online, you add them in your host’s environment settings. They never go in code a browser or phone downloads, or in a chat or screenshot.

Web page: https://buildladder.com/answers/where-keys-go

## What to do

- If you’re running your product on your computer: Put each key on its own line in .env, like STRIPE_SECRET_KEY=sk_test_…, with no spaces around the equals sign. Before your first save to Git, ask your AI tool to confirm .env is in .gitignore. Restart your product after each change to .env.
- If your product uses Next.js and keeps its code in a src folder: Put .env in the main folder, next to package.json, not inside src. Next.js only reads .env files from the main folder, so keys inside src are ignored.
- If your site is online on Vercel or Netlify: Your host doesn’t receive the ignored .env file. In the site’s settings, find environment variables and add each value. On Vercel, use the Secret type for secret values.
- If your site is online on Cloudflare: Cloudflare keeps values used while building apart from values the running Worker uses. Add each in the matching settings area, mark secret values as secrets, and put the site online again.
- If you changed a key on your host, but the site online still uses the old one: Put the site online again after changing environment values. Values copied into browser code, such as NEXT_PUBLIC_ values, change only with a new build.
- If a preview link is missing a key that works on the main site: Vercel sets each variable for Production, Preview or Development separately. Edit the variable, select Preview as well, then choose “Redeploy” on the preview.
- If you’re building a phone app: Anyone who installs the app can read what’s inside it, including EXPO_PUBLIC_ values. Keep secret keys, like an AI service key, on a server your app calls.

## What you do

- Copy each key from the service’s dashboard and paste it into .env.
- Type the same keys into your host’s environment variable settings.
- Pick the Secret type for secret keys on Vercel and Cloudflare.
- Put your site online again after you change a key on your host.
- Keep .env out of chats, screenshots and screen shares.

## What your AI tool does

- Create .env with the names your product needs and empty values, and add it to .gitignore.
- Write code that reads each key by its name, never by its value.
- List every name your host needs, and say which are publishable and which are secret.
- Check that no secret key ends up in code a browser or phone downloads.
- Restart your product on your computer after you edit .env.

## Prompt to copy

```text
I want this product’s keys stored safely. Don’t open or print my .env file. If you need to know what’s in it, list the names only.
1. Check that this product has a .env file (or the env file my framework uses) and that Git ignores it. If it doesn’t, create one with the names my product needs and empty values, add it to .gitignore, and tell me where to find each value. I’ll paste them in myself.
2. Make sure the code reads every key by name from the environment, and that no secret key is used in code that runs in a browser or on a phone.
3. List every name my host will need, and say whether each one is publishable or secret. Show names only, never values.
4. Tell me which settings page on my host to type them into, and remind me to put the site online again afterwards.
```

## Sources

Updated 2026-11-10.

- [Next.js environment variables](https://nextjs.org/docs/app/guides/environment-variables)
- [Vercel environment variables](https://vercel.com/docs/environment-variables)
- [Netlify environment variables](https://docs.netlify.com/build/environment-variables/get-started/)
- [Cloudflare Workers secrets](https://developers.cloudflare.com/workers/configuration/secrets/)
- [Cloudflare build settings](https://developers.cloudflare.com/workers/ci-cd/builds/configuration/)
- [Expo environment variables](https://docs.expo.dev/guides/environment-variables/)
- [Vite env variables](https://vite.dev/guide/env-and-mode)
