Where should the API keys go in an app you built with AI?
Your tool needs a Stripe key, a Slack token or an OpenAI key. The places a key should never be, the places it can safely live, and what to type so your agent never sees it.
Updated
The tool your agent built is about to do something useful outside itself. It will read invoices from Stripe, post a summary to Slack, or ask a language model to tidy up a ticket. Each of those needs a key: a long string that says "this request is from our account".
Whoever has the key can act as your account. A Stripe secret key can see your payments. A Slack bot token can post as your bot. An OpenAI or Anthropic key can run up a bill. So the question of where it goes is the question of who can get it.
We make Spryloom, which runs apps for teams behind sign-in and keeps their keys, and it is one of the options below. Read that section knowing who wrote it.
Where a key should never be
- In the code.
const apiKey = 'sk_live_...'stays in the repository's history, in every clone, fork and zip, even after you delete the line. - In a committed
.env. Fine on your laptop; a leak the moment it is committed. - In the page. JavaScript that runs in the browser shows the key to every visitor, through "View source" or the network panel.
- In the chat with your agent. A pasted key is in the transcript, and possibly in a file the agent wrote.
- In the file that describes the app. A
docker-compose.yml, a host's settings file orspryloom.yamlis committed, so a key there is a key in the code.
If a key was ever committed, treat it as leaked: make a new one at the provider and revoke the old one. Check that .env is in .gitignore before the first commit, not after. And a good agent gives you the command to run and lets you type the value yourself.
Where a key can live
The rule underneath every good option is the same: the code reads the key from an environment variable, and the value is set somewhere outside the code.
const apiKey = process.env.STRIPE_API_KEY;
The code can be shared and committed freely, because it holds a name, not a value. What changes between the options is where the value is kept and who can see it.
Your host's environment variables
Enter the value in the host's settings; the app gets it when it starts.
- Right for most small apps, nothing extra to pay
- Check who on the account can see values
- Check they stay out of build logs
A secrets manager
AWS, Google, Vault, 1Password, Doppler: one place for many apps.
- Scheduled rotation and a record of who read what
- One place to revoke when someone leaves
- Setup, and usually more than one small tool needs
A host that treats keys as write-only
Set a key and never read it back.
- A key nobody can retrieve can't leak through whoever retrieves it
How Spryloom does it
This is the third kind. When your agent writes an app that needs a key, Spryloom's instructions tell it to read the key from the environment and give you the command instead of asking for the value in the chat. You run it in your own terminal. list shows each name, who set it and on which day, never the value:
spry secrets invoice-checker set STRIPE_API_KEY=sk_live_... spry secrets invoice-checker list Values are not shown. Nothing can read one back. # to remove one spry secrets invoice-checker remove STRIPE_API_KEY
What holds once it is set:
- Encrypted before it is stored, and tied to the app it belongs to. A secret moved to another app doesn't decrypt.
- Given to the app when it starts, and to its scheduled jobs. It is in no image layer and no log line.
- Recorded, not revealed. The audit log records that a secret was set and what it is called, never the value.
Two things to know before you meet them
Publish again after setting a secret. Secrets reach the app when it is published. Setting one doesn't change the version already running, and a job run straight after secrets set still has the old value.
The first publish may fail, and the second will work. An app can't be given a secret before it exists. Your agent should tell you this in advance.
spry secrets … set in your terminal.Keys for the outside services, too
A key is only half of reaching a service. An app on Spryloom can reach its own database and nothing else, unless it names a service in spryloom.yaml from a fixed list, such as api.stripe.com or slack.com. So a leaked key is still a problem, but a dependency inside the app can't send it, or your data, anywhere you didn't declare. How to add an AI feature to an internal tool without leaking data goes through that part.
What it doesn't do
- You can't read a key back. No command, page or API returns a value. If you lose the only copy, get a new key from the provider and set it again.
- No automatic rotation. Changing a key is: make a new one at the provider,
spry secrets ... set, publish again, then revoke the old one. - The value goes on the command line, so it can end up in your shell's history like any command you type. If your shell is set to skip commands that start with a space, start the line with one.
- 20 secrets per app. Plenty for a small tool. If you need more, the app is probably several apps.
- It doesn't check the key. A wrong or expired key is stored like a right one. You find out when the app calls the service.
A short check before you share the app
- Search the repository for the start of your keys (
sk_,xoxb-) and for.envin the history. - Confirm
.envis in.gitignore. - Confirm no key appears in front-end code.
- Rotate any key that was ever committed or pasted somewhere it shouldn't be.
Start here
In Claude Code, add the plugin once:
/plugin marketplace add spryloom/claude-plugin
/plugin install spryloom@spryloom
Then say "publish this with Spryloom". When the app needs a key, the agent gives you the spry secrets line to run. Without the plugin, from the app's folder:
npx -y spryloom publish