LLM API Key Management: Budgets, Rotation, and Safer App Access
By Nicho
An LLM API key is a credential that can authorize spending and access. Managing it well means answering four questions: where is it stored, what can it do, how much can its workload consume, and how quickly can you revoke it?
A successful first request answers none of those questions. Before a prototype becomes a shared application, establish a key lifecycle and an access boundary that you can explain without opening anyone's raw credentials.
Keep the provider key behind your application
Do not embed a long-lived provider API key in browser JavaScript, a mobile application bundle, or browser storage. Sending a secret to an end user's device makes it available outside your server's control. OpenAI explicitly recommends routing requests through a backend rather than exposing keys in client-side environments. OpenAI API key safety guidance
For a conventional web application, use this boundary:
Signed-in user → your authenticated backend → LLM provider
The browser authenticates to your application. Your backend chooses the allowed model and retrieves the provider credential from server-side secret storage.
But moving a key to a backend is not enough. An unauthenticated proxy can still let strangers spend your balance without ever seeing the secret. Enforce user authorization, request-size limits, allowed operations, and per-user usage controls before forwarding work. Do not let an arbitrary client-supplied URL decide where your backend sends its authorization header.
Separate workloads before sharing credentials
Avoid one key for production, staging, a developer laptop, and a scheduled import. Separation makes it easier to identify usage and revoke one workload without breaking everything else.
A useful starting inventory contains no raw secrets:
| Field | Example |
|---|---|
| Workload | Customer-support summarizer |
| Environment | Production |
| Owner | Application team |
| Secret reference | Secret-manager entry name |
| Intended access | Approved summarization model |
| Review trigger | Deployment change or owner departure |
| Revocation procedure | Link to internal runbook |
Use provider project or service-account boundaries where available, rather than merely renaming keys that retain identical permissions. OpenAI's project documentation, for example, describes project-scoped service accounts and resources. That is a provider-specific capability, not a guarantee that every compatible gateway offers the same isolation. OpenAI project management
Store secrets without distributing them unnecessarily
Prefer a designated secret-management system with access limited to the workloads and operators that need it. Record ownership and lifecycle metadata separately from the credential value. OWASP recommends fine-grained access and managing secrets across creation, rotation, revocation, and expiration. OWASP Secrets Management Cheat Sheet
For a small deployment, a protected server environment variable may be an integration mechanism, but it is not a complete security strategy. Review who can read deployment settings, run debug commands, or inspect crash reports. Never print the full environment when diagnosing a connection problem.
Keep credentials out of source files, container images, screenshots, tickets, and chat messages. Use redacted configuration examples in documentation. A teammate troubleshooting an error generally needs the endpoint, model, sanitized error, and request identifier, not the key itself.
Define what “budget” actually means
Do not treat every dashboard budget as an immediate hard spending ceiling. Before relying on a control, establish:
- Whether it sends an alert or rejects additional requests.
- Whether it applies to a key, project, account, or application user.
- Its reset period and time zone, if applicable.
- How concurrent requests and delayed usage accounting are handled.
- Who receives alerts and who can change the setting.
Document unknowns instead of assuming favorable behavior. Keep application-side admission controls and monitoring even when the provider offers a budget feature.
For example, a support application might allow only its approved model, constrain input size, cap requested output, and limit each customer's daily operations. These controls serve different purposes: a model restriction constrains choices, a request limit constrains volume, and a spending control constrains monetary exposure. None replaces the others.
Configure cheapaimodel's published key controls
cheapaimodel's public pricing page describes per-key budgets, expiration dates, model allowlists, and IP allowlists. It also states that a key's budget cannot exceed what the account balance can fund, and that depleted account balance causes gateway requests to return 403.
For a new integration, choose a narrow model allowlist and a budget appropriate to that workload. Give temporary integrations an expiry date. Consider an IP allowlist when your server has known, stable outbound addresses; account for failover infrastructure before enabling it.
These recommendations rely on the published product description, not an independent audit of enforcement timing. Do not promise zero overspend under concurrency or confuse an IP restriction with a replacement for credential secrecy. Check the current cheapaimodel documentation before configuring a deployment.
Rotate deliberately; revoke urgently when exposed
For planned rotation, use a controlled handover:
- Identify every deployment and background job using the old credential.
- Create a replacement with the intended restrictions.
- Update the secret reference or value through your normal deployment process.
- Confirm the affected workloads are using the replacement.
- Revoke the old credential and record completion.
Any overlap should be deliberate and short. Do not leave an old key active indefinitely “just in case.” Expiry also needs an owner: an expiring credential without a renewal plan can become an avoidable outage.
An exposed key is different. Prioritize revocation and containment rather than preserving a comfortable migration window. Inspect usage, identify affected deployments, and restore service with a replacement delivered through the approved secret channel.
Deleting a leaked key from the latest Git commit does not invalidate it or remove existing copies. GitHub's guidance puts credential revocation or rotation before repository-history cleanup and explains why cleanup requires coordination. GitHub sensitive-data removal guidance
Make key ownership operational
Before launch, confirm that someone can answer: who owns this key, which service consumes it, what stops abusive usage, and how do we disable it?
A manageable integration has specific answers. If the answer is “everyone uses the same key,” fix that boundary before scaling traffic. Safer key management is less about a clever storage trick than keeping access narrow, spending visible, and revocation practical.