← Back to blog

API Key Management for Founders: Store, Rotate, Protect

November 19, 2026
API Key Management for Founders: Store, Rotate, Protect

Good API key management comes down to four habits. Keep secret keys on the server and out of your code. Give every key one owner and the least access it needs. Rotate keys on a schedule with an overlap period, so nothing breaks. Know the exact steps to revoke a key the hour it leaks. If you can't say where each key lives within a few minutes, you don't manage your keys yet. You just have them.

This guide is written for founders who are not engineers: you built a prototype in a tool like Lovable, Bolt or Bubble, or inherited code from an agency, and now real users, payments and an investor or auditor are in the picture. I'll explain each term once, then give you routines you can check yourself or hand to whoever builds your product.

Hanad Kubat
hanadkubat.com
Build With Secrets Kept Server-Side
If your prototype has outgrown its platform, Hanad builds working software in maintainable code, with fixed scope and you owning the code from day one.
Visit

Key Takeaways

  • An API key identifies your app to another service. It does not identify a person, and anyone who copies it can act as your app.
  • Publishable keys may sit in browser code. Secret keys belong only on a server, in environment variables or a secrets vault, never in source code or a repository.
  • Rotate with an overlap: create the new key, deploy it, confirm it works, then revoke the old one. Many providers and guides recommend at least every 90 days.
  • When a key leaks, fix the cause, revoke the key, then review usage and billing. Spend limits cap the damage while you work.
  • Write down every key's owner, purpose, storage location and replacement steps. That list is the most useful security document an early product can have.

Table of Contents

What an API key is and what it can do

An API (application programming interface) is how one piece of software asks another to do something: charge a card, send an email, generate text with an AI model. An API key is a unique string your app sends along with each request. The service uses it to identify the caller, apply limits, track usage or decide whether to allow the request.

Two details matter for a non-technical owner.

First, a key identifies a project, not a person. Google Cloud's documentation says keys provide project identification and project authorization, but do not identify individual users. So a stolen key lets someone behave as your whole application.

Second, keys do not expire by themselves. The same documentation notes that a stolen key has no expiration unless the project owner revokes or regenerates it. A key pasted into a chat window two years ago can still work today.

That is why an AI provider key, a payment key or a database key is closer to a bank card than a password. Whoever holds it spends your money or reads your customers' data.

Which keys may be public and which must never be

Many services issue two kinds of key, and mixing them up is the most common mistake in a first build.

Publishable keys are designed to ship in browser or mobile code. They act as an app identifier, not a credential. Stripe's publishable key is the well-known example.

Secret keys are credentials. One provider's documentation puts the rule well: secret keys are treated like a database password and belong in server environment variables or a secrets manager. The same page gives a useful test: what a logged-in user does for their own account sits on the publishable side, and what an admin does on behalf of a user sits on the secret side.

The browser is the boundary that matters. Anything delivered to a browser can be inspected by whoever visits your site. If your prototype calls an AI model, a payment API or your database directly from the front end with a secret key, that key is public the moment the page loads.

A quick check you can do without reading code:

  1. Open your live app in Chrome or Safari.
  2. Open the developer tools and look at the Network tab while you use the app.
  3. Look at the requests going out. If you see a long key starting with something like sk_ or a bearer token for a paid service in the request headers of a call made straight from the page to that service, the secret is exposed.

If you find one, skip ahead to the leak section. Treat that key as compromised.

This is also where prototypes tend to hit their wall. A tool that generates an app fast often calls services directly from the page because that is the shortest path to a demo. A real version puts a small server layer in between, so the browser asks your server and your server holds the secret. I cover that rebuild pattern in Bubble app security: 5 checks before rebuilding, and the same logic applies to Lovable and Bolt builds.

Where to store keys

The rule from Stripe's documentation is blunt: never put secret keys in source code or client-side apps. Use a secrets vault, or environment variables if a vault isn't available. Scan code and deployment pipelines for secrets, and use a pre-commit hook (a check that runs before code is saved to the repository) that rejects anything that looks like a key.

A secrets vault is a locked store for credentials that is separate from your code. The application asks for the key at runtime, so the value never appears in source files. The same Stripe page lists what you gain beyond hiding values: an audit log of every access, automatic rotation and the ability to revoke access instantly without redeploying. Its examples include AWS Secrets Manager, Google Cloud Secret Manager, Azure Key Vault and HashiCorp Vault.

For a young product, environment variables on the hosting platform are a reasonable first step, with a few habits attached:

  • Add .env, .env.local and similar files to .gitignore, and commit a .env.example with placeholder values so the next developer knows which keys exist. Airbyte's documentation adds that .env files are a development convenience, not a security boundary.
  • Send keys in HTTP headers, not in URLs, because URLs end up in logs and browser history.
  • Never pass a secret as an inline command-line argument. The same source warns that command-line history is a common leak path.
  • Use separate keys for development, staging and production, so a test mistake can't touch real customers.
  • Never paste a key into a chat, a ticket or an AI assistant. Those copies live far longer than you expect.

Keep a key register

OWASP's guidance is that manual secret handling raises both leak risk and human error, so the goal is to limit or remove human interaction with actual secrets through automated pipelines and rotation. A solo founder can't automate everything on day one, but you can start with a one-page register. For every key, record:

FieldExample
ServicePayments provider, live mode
PurposeCharging customers on the checkout page
OwnerYou, or the named developer
StorageHosting platform environment variables, production only
Access levelRestricted: only the permissions the app needs
Last rotatedDate
Replacement stepsLink to the checklist below

The test I give founders: can you say where each secret is stored within a few minutes, without asking a former contractor or searching old messages? If not, treat that credential as unmanaged and plan a controlled replacement. That is the situation founders often meet after an agency hands over code nobody can read.

Limit what a stolen key can do

Storage protects against leaks. Scope and limits protect you when one happens anyway.

Restrict each key to what the app needs. Most providers let you create keys that can only perform certain actions, or only work from certain servers. Google Cloud's guidance for exposed keys includes adding API key restrictions. The same principle applies inside your own product: a clear map of role permissions that decide who can see and change what keeps one compromised account from reaching everything.

Four controls that limit API key exposure

Set spend limits for paid APIs. For AI services, a leaked key shows up as a surprise bill. OpenAI's Help Center advises monthly spend limits with hard enforcement at organization or project level, noting that alerts alone don't stop traffic. It also suggests creating keys with an expiration date, and, for supported workloads, using workload identity federation instead of a long-lived key. In plain terms: where a platform can grant your server short-lived access, prefer that to a key that lives forever. The same idea underlies single sign-on for applications, which reduces long-lived credentials and automates secure access.

Rate-limit your own API. If you issue keys to your customers, per-key limits stop one customer or one thief from flooding you. I walk through the design in API rate limiting: how to design, set and enforce limits.

Protect the people, not only the keys. Keys identify apps. The humans logging into your dashboards, your hosting and your vault need strong sign-in too. My piece on MFA for SaaS covers that, and the SaaS security checklist for B2B teams puts keys in the wider picture.

How to rotate an API key without breaking your app

Rotating means replacing a key with a new one on purpose. The goal is that a stolen key stops working after a short time. OWASP notes that regular rotation ensures stolen credentials work only for a short time, with lifetimes from minutes to years depending on the secret.

CISA's countermeasure guidance defines rotation as generating a new key, replacing the compromised key, and revoking it while securely deleting the old one. It recommends rotating at least every 90 days and confirming up front that you have the permissions needed to change the key. That second point trips up founders constantly: the key was created under a former developer's account and you can't log in to replace it.

The safe order uses an overlap, so there is never a moment when production has no working key:

  1. Confirm access. Make sure you can log in to the provider account that owns the key.
  2. Create the new key with the same restricted scope as the old one, not a broader one.
  3. Store it in the vault or hosting environment variables, never in code.
  4. Deploy the change so the app uses the new key.
  5. Test. Run one real or sandbox transaction: a test payment, a test email, one AI request.
  6. Watch for a short time. Check logs for failed authentication from services you forgot about.
  7. Revoke the old key and delete it from every place it was stored, including old notes and chats.
  8. Update the register with the date.

Some providers build the overlap in. One security guide describes old and new keys staying valid together during a configurable grace period, so servers can be updated without downtime. If your provider offers that, use it. If it doesn't, the same result comes from running two keys side by side for a short window.

How often to rotate

A schedule matters for two reasons. It shortens the life of any undetected leak. And Stripe's documentation frames periodic rotation as practice: it confirms you know where each key is used and that your team can replace a key on short notice, and it recommends writing a contingency plan so an exposed key costs the business as little as possible.

A workable rhythm for an early product: rotate high-risk keys (payments, AI providers, database, admin) every 90 days, and rotate any key immediately when a developer or contractor with access leaves. OWASP adds a nuance worth knowing: per NIST, user passwords are not rotated on a schedule and only on suspicion of compromise. Scheduled rotation is for machine keys.

What to do the hour a key leaks

You find a key in a public repository, a screenshot, a support email or a provider alert. Work in this order.

  1. Find the cause first. Supabase's guidance is to fix the root cause of the leak before rotating. Otherwise the new key leaks the same way. Public repository, front-end bundle, shared document: remove it from there.
  2. Revoke fast if someone is using it. Airbyte's documentation says to revoke first and coordinate dependent services second, because waiting leaves the compromised key live during the most dangerous window. Some parts of your app will stop working. That is the lesser harm.
  3. Issue a replacement and deploy it. If you later find a service you missed, move it to the new key. Supabase notes that deleting a secret key can't be undone, so never re-enable the compromised one.
  4. Review usage and billing. OpenAI advises checking whether usage aligns with your team's work and contacting the provider's support if it doesn't. For keys that were meant to be public, Google Cloud suggests reviewing API and billing activity and adding restrictions.
  5. Close the attack path. CISA's guidance includes identifying how the key was stolen, taking down a publicly leaked source where possible and reviewing which applications use the affected API.
  6. Write it down. Note what happened, when, and what changed.

If customer personal data may have been reached through the key, involve your lawyer, because breach notification duties depend on your jurisdiction and your customers' locations.

When a prototype's keys are beyond a quick fix

Sometimes the audit above shows the problem is the structure: secrets in the front end, one shared admin key, no separate environments, nobody who knows what else was connected. At that point, rotating keys treats a symptom. The prototype needs a server layer, proper environments and a clean handover.

That is the work I do. I take a prototype that validated an idea and rebuild it as maintainable code on a deliberately boring, widely known stack, with fixed price and fixed scope, so the next developer can pick it up. My app builds start from €12,000, and you own the code from the first commit. Details are on my services page.

Perspective

Almost every key problem I meet is an ownership problem, not a cryptography problem. The key was created by someone who has left, pasted somewhere convenient, and never written down. Nobody planned to be careless. Nobody was assigned to be careful.

That is why I build the boring parts first: secrets on the server, separate environments, a register of what exists and who owns it, and a rotation routine the next developer can follow in an afternoon. You speak to the person who writes the code, so the person who knows where every key lives is the same person you phone.

If you are unsure whether your prototype can pass a security or due-diligence review, a fixed-price look at the code answers that before you spend on anything else.

Hanad Kubat

FAQ

What is the safest place to store an API key?

On the server, in a secrets vault or in your hosting platform's environment variables, never in source code or in browser code. A vault adds an access log, rotation and instant revocation, according to Stripe's key guidance. Keep .env files out of your repository.

How do I change or rotate my API key?

Sign in to the provider's dashboard, create a new key with the same restricted scope, store it in your vault or environment, deploy, test one request, and only then revoke the old key. Doing it in that order avoids downtime. If you can't sign in because a former developer owns the account, resolve that first.

How often should I rotate API keys?

CISA recommends at least every 90 days. Rotate sooner after any suspected exposure and immediately when someone with access leaves. Provider-specific rules may be stricter, so check the provider's own documentation.

Is it safe to put an API key in my Lovable or Bolt front end?

Only if it is a publishable key designed for browsers. Secret keys for payments, AI models or your database must stay on a server, because anything sent to the browser can be read by visitors. If your prototype calls those services directly from the page, move the calls behind a server and rotate the keys already exposed.

Hanad Kubat
Discuss Your Prototype’s Security
Email Hanad about your API key setup and get a conversation about building or rebuilding your software in maintainable code.

Sources