An API key is a long secret string that lets one app talk to another. It connects your website to payments, your CRM to email, and your automations to everything else. If it leaks, anyone who finds it can use it as if they were you.
Leaks are usually boring. A key is pasted into a chat, committed to a code repository, emailed to a freelancer, or left in a shared spreadsheet. Nobody meant to share it. The damage happens anyway, often weeks later when the key is found and used.
This guide shows small businesses how to handle API keys safely. You will learn where keys hide, how to store them, how to limit what each key can do, and what to do when one leaks.

Key Takeaways
- An API key identifies an app, not a person. Treat it like a password.
- Never put keys in code, chats, emails, or spreadsheets. Use a secret manager.
- Give each integration its own key with the narrowest permissions possible.
- Use separate keys for test and production, and rotate them on a schedule.
- If a key may have leaked, revoke it first and investigate second.
What Is an API Key, in Plain English?
An API key is a credential that a program sends with each request to prove it is allowed in. Think of it as a backstage pass for software. The payment service sees the key and knows the request comes from your business.
Keys are different from passwords in one important way. A password belongs to a person and can be changed with a reset. A key belongs to an integration, and it often lives in code, servers, and third-party tools at the same time.
That spread is what makes keys risky. A single key can sit in five places, and any one of them can leak. The fix is to know where your keys live and to limit what each one can do.
Where Do API Keys Usually Leak?
The most common leak is a code repository. A developer commits a key to Git, even a private repo, and it stays in the history forever. Automated scanners search public repos constantly, and private repos are not safe once a contractor or ex-employee has access.
The second most common leak is chat and email. Someone pastes a key into Slack or Teams to unblock a colleague, and it sits in the message history. Months later, a new team member or a compromised account can read it.
The third is the front end. Keys shipped inside a mobile app or a JavaScript bundle can be extracted by anyone who downloads the app. Anything delivered to a user device should be treated as public.
How Should a Small Business Store API Keys?
Keys belong in a secret manager, in your hosting platform’s environment variables, or in the encrypted connection settings of your automation tool. These are the only places designed to hold secrets safely.
A password manager with shared vaults works for small teams that do not have a dedicated secret manager. Store the key there, share access through the vault, and never copy the value into a message. Audit logs show who opened it and when.
Never store keys in a spreadsheet, a notes app, or a document. Those tools are built for sharing, not for secrets. If a key is in a spreadsheet today, move it to a vault and rotate it, because it should be treated as exposed.
What Does Least Privilege Mean for API Keys?
Least privilege means each key can do only what its job needs, and nothing more. An integration that only creates invoices should not be able to read salary data. A reporting job that only reads orders should not be able to delete customers.
Many services offer scopes or roles for keys. Use them. A read-only key for a dashboard, a payments-only key for checkout, and a separate key for each integration are all cheap to set up and limit the damage of any single leak.
If a service only offers all-or-nothing keys, note that as a risk. Ask the vendor whether scoped keys are coming, and consider whether a different tool fits better. All-or-nothing access should never be the default choice.
Should You Use API Keys or OAuth?
API keys suit server-to-server calls, where one system talks to another without a person involved. They are simple, and that simplicity is their weakness. A key is a long-lived secret that anyone can reuse if they find it.
OAuth is the better choice when an app acts on behalf of a user. It lets someone authorize an app without sharing a password. The app gets a temporary token with limited permissions, and the token can be revoked without changing a shared secret.
As a rule, use OAuth for third-party services that support it, and use keys only for internal integrations between your own systems. When you do use keys, give them expiry dates and make them easy to revoke.
How Often Should You Rotate API Keys?
Rotate high-risk keys every thirty to ninety days, and standard keys at least every six months. Put the dates in your key inventory so rotation is a calendar event, not a vague intention.
Rotate immediately when the risk changes. That means when an employee or supplier with access leaves, when a key may have been exposed, or when you suspect a breach. Do not wait for the scheduled date in those cases.
Plan rotation so it does not break work. Create the new key, update the integration, confirm it works, and only then revoke the old one. A zero-downtime rotation takes a few extra minutes and avoids a midnight outage.
What Is an API Key Inventory?
An inventory is a simple list of every key and connection your business has. For each one, record the system, the type of credential, its permissions, where it is stored, who created it, and when it was last rotated.
Build the list from your code, your automation tools, your payment dashboard, and your team. Ask who connected what, and check the connected apps in each service. Most small businesses are surprised by how many keys they find.
Review the inventory every quarter and whenever someone leaves. Remove keys for tools you no longer use, and move any key still held by a departed employee or supplier to a service account. This review is where most exposure is found.
API Key Security Checklist
Use this checklist to bring your keys under control. It fits in a single afternoon for most small teams.
- List every API key and integration in one inventory.
- Move all keys into a secret manager or encrypted vault.
- Remove every key from code, chats, emails, and spreadsheets.
- Give each integration its own key with narrow scopes.
- Use separate keys for test and production environments.
- Set expiry dates and a rotation schedule for each key.
- Turn on secret scanning for your code repositories.
- Add API access to your staff offboarding checklist.
How Do You Monitor API Key Usage?
Logging tells you what an integration did, and alerts tell you when it did something unusual. Turn on access logs where your services provide them, and review them weekly for patterns that do not fit.
Watch for failed calls, sudden spikes in volume, calls from new locations, and access to data the integration does not normally touch. Any of these can mean a key is compromised or a bug is hammering the service.
Log the key identifier, not the full key value. The identifier lets you trace which integration made a call without putting the secret itself into your logs. Logs that contain real keys create a second leak.
API Keys vs OAuth vs JWT: Which Fits Where?
Choosing the right credential matters more than most teams realize. The wrong choice turns one leak into full access, while the right choice keeps the damage small and the fix fast.
API keys are best for simple server-to-server calls with limited scope. OAuth fits anything acting for a user. JWTs suit mobile apps and services you build yourself, where tokens must be checked quickly without a database lookup.
| Method | Best for | Strength | Weakness |
|---|---|---|---|
| API key | Server-to-server calls | Simple to set up | Long-lived, easy to leak |
| OAuth 2.0 | Third-party access for users | Scoped, revocable tokens | More setup work |
| JWT | Your own apps and APIs | Fast, stateless checks | Hard to revoke early |
Whatever you choose, send credentials in headers, never in URLs. URLs end up in logs and browser history, and a key in a URL is a key you have already shared. For the wider security picture, see our guide on how to write an IT security policy for a small business.
What Happens When a Supplier Holds Your Keys?
Many small businesses discover that a supplier or agency created the API keys and never handed over control. The web agency holds the payment keys, the marketing firm holds the email keys, and nobody in the business can revoke them.
Fix this by moving every key into a vault you control and reissuing any key a supplier created. Give the supplier access through the vault, not by sharing the value. When the relationship ends, you revoke their access in one place instead of chasing keys across their systems.
Frequently Asked Questions
What should I do if an API key leaks?
Revoke it immediately, then investigate. Create a replacement key, update the integration, and check logs for what the old key was used for. Do not investigate first while the key still works.
Is it safe to store API keys in a .env file?
A .env file on your server is far safer than code or chat, as long as it is never committed to Git. Add .env to your ignore file, restrict who can read it, and prefer a secret manager when you can.
How long should an API key last?
Give every key an expiry date. Standard keys should last no more than a year, and high-risk keys should rotate every thirty to ninety days. Short-lived keys limit the damage when one leaks.
Can I use the same API key for test and production?
No. Test keys should never reach production data, and production keys should never sit in test code. Separate keys let you revoke one without breaking the other, and they make leaks easier to trace.
Why should API keys never go in a URL?
URLs are logged by servers, proxies, and browsers. A key in a URL ends up in log files that many people can read. Send keys in headers over HTTPS instead, where they are encrypted in transit.
What is secret scanning, and do I need it?
Secret scanning checks your code for keys and tokens that were committed by mistake. GitHub offers it built in, and tools like TruffleHog and GitGuardian do the same. Turn it on, because humans will commit a key eventually.
Conclusion: Treat Every Key Like a Password
API keys are small strings with large consequences. One leaked key can read customer data, move money, or send email as your business. The good news is that the fix is mostly discipline, not technology.
Start today with the inventory. List your keys, move them into a vault, give each one narrow permissions, and set a rotation date. Those four steps close most of the gaps that cause real breaches.
Then add the habit. Review the inventory quarterly, rotate on schedule, and revoke fast when something changes. For a broader review of your security basics, work through our small business cybersecurity checklist for beginners alongside this guide.



