Use a service's secret key without ever leaking it.
What this is
An API key is a password that lets your site use another company's service. This guide shows how to keep it secret.
Who it is for
Anyone whose site uses payments, maps, email or AI.
What you will get
Your keys stored safely, and a site that never shows them.
Time
About 5 minutes
You need
A project on your computer
An account on the service you want to use
Your path: Keep keys safe
1
Step 1 of 8Time: 3 min
Open the account on the service's site
Why: because the service must know it is you using it, and who to charge.
An API keyAn API key is a long secret password that proves to a service that a request comes from you.Read the full entry is a password that lets your site use another company's service, like payments or AI. You get it from that service.
What to do
Make the account on the service's own website.
Open its API keys or Developers page.
You should see: You see a page where you can make a key.
Stuck?
I cannot find the page?
Search the service's help for: API keys.
It needs a card?
Many services do. Read the price first.
API keys: what they are and how to keep them safe
☐ Open the account on the service's site
Make the account on the service's own website.
Open its API keys or Developers page.
You should see: You see a page where you can make a key.
☐ Make a test key first
Make a test key.
Use the live key only when you launch.
You should see: You have a test key.
☐ Keep the key in a secret file
In your project folder, make a file called .env.local.
Write one line like the one below for each key.
You should see: The file holds your key.
☐ Keep the file away from GitHub
Open the file called .gitignore.
Check that it has the line below.
You should see: The line .env* is in the file.
☐ Add the key on Vercel
Open Project, Settings, Environment Variables.
Paste the same names and values, then deploy again.
You should see: The live site works with the key.
☐ Use secret keys on the server only
Keep secret keys out of any name that starts with NEXT_PUBLIC_.
Use them only in server code.
You should see: No secret key starts with NEXT_PUBLIC_.
☐ Set a spending limit
Open the billing or usage page of the service.
Set a monthly limit or an alert.
You should see: A limit or alert is set.
☐ Know what to do if a key leaks
Delete the key on the service's page.
Make a new one and put it in your secret file and Vercel.