API keys
Give a deployed app a model key without ever putting it in the browser.
An app that talks to a model needs a key. The rule is one line long: the key lives on the server, the browser never sees it, and the key is never committed.
Where keys come from
- Freebuff API — an OpenAI-compatible endpoint, with a key you create and fund in your account at freebuff.com/account/api.
- Another provider — the same pattern applies; only the base URL and model names change.
Keys are billed to their owner. A key in a template that strangers can find is a key that spends your balance, which is why every serious template keeps it server-side and shows a setup card until it is configured.
Setting it on a deployed site
- Deploy onceSecrets attach to a deployment, so the environment has to exist first.
- Add the secretPut the key into the environment's secrets, where it becomes an environment variable for the Worker.
- Read it server-sideThe Worker reads the variable, calls the API, and returns only the result.
Never send a key to the client, never inline it into a build, and never bake it into a static asset. A key in JavaScript is a public key, whatever the variable is called.
Setting it locally
- Keep it in an untracked env file, and list that file in
.gitignore. - Provide a committed example file —
.env.examplewith variable names and no values — so the project documents what it needs. - If the app ships a development stub, a missing key should produce the setup card, not a crash or a silent fallback to a fake model.
If a key leaks
- Revoke itGenerate a new key and delete the old one; rotating is faster than investigating.
- Purge it from historyThe old value must leave the repository, not just the latest commit.
- RedeployThe old deployment still has the old value until you set the new one.
If the key was pasted into a chat or a public channel, treat it as compromised even if nobody appears to have used it.