What Is an API Key?
An API key is a long secret string a program sends with each request to prove which account is calling a service, such as a payment, maps or email provider. Treat most keys like a password: keep them on a server, never in website code, limit what they can do, and replace them if exposed.
| API key | OAuth access token | Password | |
|---|---|---|---|
| Who uses it | Your own code or server | An app acting for a user who approved it | A person signing in |
| How you get it | Copy it from the provider's dashboard | Issued after the user clicks Allow | Chosen by the person |
| Typical lifetime | Until you rotate or delete it | Short, then refreshed | Until changed |
| Scope | Whatever you allowed when creating it | The permissions the user granted | Everything the account can do |
Updated
If you run a website or store, you meet API keys whenever you connect a service: payments, maps, email, a form tool or an AI agent. Most are secret, a few are meant to be public, and mixing them up is how bills and data leaks happen. Paste a key into the inspector below to see what kind it looks like; it runs entirely in your browser and sends nothing anywhere.
API key inspector
Paste a key or just its first few characters. The check runs in your browser only; still, prefer a test key or a dummy value over a live secret.
Paste something to inspect.
Using a key safely from a server
The key lives in an environment variable on the server. The browser calls your own endpoint, which adds the key and calls the provider.
.env (never committed)
Placeholder values only. Add .env to .gitignore so it never reaches your repository.
# .env
PAYMENTS_SECRET_KEY=sk_test_your_key_here
MAPS_BROWSER_KEY=your_restricted_browser_keyapi/quote.js
A tiny server route. The secret is read on the server and never sent to the browser.
export default async function handler(req, res) {
const r = await fetch("https://api.example.com/v1/quotes", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.PAYMENTS_SECRET_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({ amount: Number(req.body?.amount) || 0 }),
});
res.status(r.status).json(await r.json());
}
Public keys and secret keys
Some services issue a pair. A publishable key identifies your account from the browser but cannot do anything sensitive, while the secret key on your server can charge cards or read data. Stripe's docs mark only the publishable key as safe to expose.
A browser key is still worth restricting. Google Cloud's guidance is to add API key restrictions, which limit the ways a key can be used and so reduce the harm if someone copies it.
Leaked key checklist
First, rotate or delete the key in the provider's dashboard. Second, update the new key in every place that used the old one. Third, check the provider's usage logs for calls you did not make. Fourth, find how it leaked, such as a committed file or a front-end bundle, and close that gap.
How it works
- You create the key in the provider's dashboard and copy it once; many providers never show it again.
- Your server stores it in an environment variable or the host's secret settings.
- Each request to the provider carries the key, usually in an Authorization header.
- The provider looks the key up, checks what it is allowed to do, and answers or refuses.
Tips
- Never paste a secret key into front-end code, a public repository, a support chat or an email.
- Use restricted keys where offered. Stripe, for example, recommends restricted keys that carry only the permissions an integration needs.
- Add restrictions such as allowed websites, IP addresses or specific APIs, so a stolen key is worth less.
- Delete keys you no longer use and rotate the rest on a schedule, and when someone with access leaves.
- Keep test and live keys apart. Many providers mark them in the prefix, such as sk_test_ and sk_live_.
Frequently asked questions
Is an API key the same as a password?
They are both secrets, but a password is for a person signing in while an API key is for software calling a service. Keys are long and random, usually limited to certain actions, and can be replaced without changing anyone's login.
Can I put an API key in my website's JavaScript?
Only if the provider says that key type is safe to expose. Stripe's publishable keys starting pk_ are meant for front-end code; its secret and restricted keys are not. Anything in the browser can be read by every visitor.
Where should I store API keys?
In a secrets vault or your host's environment variable settings. Stripe and Google both say not to put keys in source code or commit them to code repositories.
What should I do if my API key leaked?
Revoke or rotate it at once in the provider's dashboard, then put the new key in your server settings. GitHub's guidance on detected secrets is to rotate the affected credential immediately; scrubbing history alone does not make a live key safe.
API key or OAuth?
Use an API key when your own server talks to a service on your own account. Use OAuth when your app must act for other people on their accounts, because each of them then grants and can revoke access themselves.
Related: API key generator, .env file format, Next.js environment variables, Notion API key, Rate limiting explained.
Build your site free or see all free tools. On We.Inc you can build your site free, with no card and no trial needed to start. AI building is on paid plans from $19 a month.
More in Guides
- What Is an MCP Server?
- What Is Deep Linking?
- What Is a JWT? Structure, Claims and Decoding
- What Is localhost? The Address That Always Means This Computer
- What llms.txt Does and Does Not Do for a Small Business Site | How-to Guide
- WhatsApp Link Preview: Why It Fails and How to Fix It
- White-Label Platform Contract Checklist for Agencies: What to Agree Before You Resell | How-to Guide
- White-Label AI App Builder for Agencies: Resell Apps
Product
Who It's For
- For Agencies
- For Freelancers
- For Hosting Providers
- For SaaS Platforms
- For Startups
- For Financial Services
- For Healthcare
Features
Resources
- Blog
- Help Center
- Free Business Tools
- Free UI Components
- Website Templates
- Template Collections
- Website Examples
- Guides
- Comparisons
- Alternatives
- Best Lists
- Reviews
- Pricing Guides
- Use Cases
- Glossary & Guides
- Integrations
- Developers
- Benchmark
- Windows App