API Key Expiration Policy for LLM APIs: Enforce It, Don't Document It
An API key expiration policy only works when the system that issues keys enforces it. Here is how to require every LLM Gateway key to expire, roll leaked secrets without losing usage history, and automate rotation from your backend with the master API.
By LLM Gateway

Every security questionnaire has the same line: API keys are rotated at least every 90 days. Most teams answer yes and mean that a wiki page says so. Meanwhile the key someone created for a hackathon two years ago still works, still has access to every model, and lives in a .env file on a laptop nobody remembers.
An API key expiration policy is only real when the system that issues keys enforces it. This post covers how to do that for LLM traffic with LLM Gateway: a maximum lifetime the gateway enforces, rolling secrets without losing history, and rotation driven from your own backend.
Why LLM keys need an expiration policy
LLM API keys are more dangerous to leak than most credentials:
- They spend money directly. A leaked key is a credit card with no PIN. Scrapers look for them in public repositories within minutes.
- They carry data. Whoever holds the key can send anything to any model the key allows, under your organization's name.
- They end up everywhere. Notebooks, CI variables, agent configs, coding tools. The more places a key lives, the less likely anyone rotates it by hand.
Expiry limits the damage of the key nobody knows about. A key that expires in 90 days is a problem for at most 90 days.
Enforce a maximum key lifetime
Owners and admins set the policy under Settings → Policies → Maximum API Key Lifetime, anywhere from 1 to 3650 days. Once a limit of N days is in place, the gateway enforces it everywhere keys are created or changed:
| Action | What the policy does |
|---|---|
| Create a key in the dashboard | Expiration is required, pre-filled with the lesser of 30 days and N |
| Create a key from the API/CLI | A missing expiration defaults to N days; a later one is rejected (400) |
| Edit a key's expiration | Cannot remove it or push it more than N days out |
| Reactivate a key | Needs an expiration at most N days away |
| Roll a key | Keeps its current expiration |
The auto-managed Lounge key is exempt. The same setting is available as maxApiKeyLifetimeDays on PATCH /orgs/{id}, and each change is recorded in the audit log as organization.api_key_lifetime.update, which is the evidence an auditor asks for.
Rolling it out without an outage
Setting the policy does not disable anything. Existing keys that never expire, or expire later than the limit allows, keep working and are flagged Exceeds max lifetime on the API Keys page. The Policies page shows how many active keys are affected. Work through them with each key's Set Expiration action, starting with the oldest, and give owners of production keys time to schedule a rotation.
The maximum key lifetime is part of the Enterprise access control feature.
Roll leaked secrets, keep the history
When a secret leaks, the usual fix is to create a new key and delete the old one. That throws away the key's usage history, its spend limits, its IAM rules and its compliance policy, and someone has to rebuild them under pressure.
Rolling replaces only the secret. In the dashboard, choose Roll Key from the key's menu. The old secret stops working immediately with 401, and the new one is shown once. Everything else about the key stays: name, usage statistics, all-time and recurring limits including the current window, IAM rules and expiration. One thing does not carry over: credentials stored for the key's pending batches are dropped, so remaining batch requests fail. Let active batches finish before a scheduled roll.
Automate rotation with the master API
Manual rotation fails because it depends on someone remembering. The master API lets your own backend do it. Master keys are available on the Enterprise plan.
Issue a short-lived key for a CI run or a contractor, with EXPIRES_AT set to a future ISO 8601 time such as tomorrow:
1curl -X POST https://internal.llmgateway.io/v1/master/keys \2 -H "Authorization: Bearer $MASTER_KEY" \3 -H "Content-Type: application/json" \4 -d '{5 "projectId": "'$PROJECT_ID'",6 "description": "CI run 4812",7 "expiresAt": "'$EXPIRES_AT'"8 }'1curl -X POST https://internal.llmgateway.io/v1/master/keys \2 -H "Authorization: Bearer $MASTER_KEY" \3 -H "Content-Type: application/json" \4 -d '{5 "projectId": "'$PROJECT_ID'",6 "description": "CI run 4812",7 "expiresAt": "'$EXPIRES_AT'"8 }'Roll a key on a schedule and hand the new secret to your secret manager. The new token is returned only once and the old one stops working immediately, so check the response before writing it anywhere, and keep it until the write succeeds:
1set -euo pipefail2response=$(curl -sf -X POST https://internal.llmgateway.io/v1/master/keys/$KEY_ID/roll \3 -H "Authorization: Bearer $MASTER_KEY")4token=$(jq -er '.apiKey.token' <<<"$response")5until vault kv put secret/llm-gateway token="$token"; do sleep 5; done1set -euo pipefail2response=$(curl -sf -X POST https://internal.llmgateway.io/v1/master/keys/$KEY_ID/roll \3 -H "Authorization: Bearer $MASTER_KEY")4token=$(jq -er '.apiKey.token' <<<"$response")5until vault kv put secret/llm-gateway token="$token"; do sleep 5; doneThen restart or reload every client that read the old secret at startup; until it picks up the new one, its requests fail with 401.
Rolling keeps the key's expiry, so a key rolled every 30 days still stops at its original expiry. Extend it with PATCH /v1/master/keys/{id} and a new expiresAt in the same job, within the policy, or issue a replacement key. Rolls are recorded as api_key.roll, attributed to the master key's creator.
A rotation policy that holds up in an audit
- Set a maximum key lifetime that matches your written policy, for example 90 days.
- Fix the flagged keys over a few weeks, production first.
- Issue short-lived keys for CI, demos and contractors instead of sharing long-lived ones.
- Roll on a schedule from your secret manager, extend the expiry in the same job, and roll immediately when a secret may have leaked.
- Export the audit log entries as evidence.
For how LLM Gateway stores keys and rotates provider credentials, see API key rotation: how we secure your API keys.
Lock down your LLM keys
Frequently asked questions
- What is an API key expiration policy?
- A rule that every API key must expire within a set time, so a leaked or forgotten key stops working on its own. In LLM Gateway, owners and admins set it as a maximum key lifetime of 1 to 3650 days, and the gateway rejects any new key or change that would outlive it.
- What happens to existing keys when I set a maximum key lifetime?
- Nothing breaks. Existing keys are not changed or disabled. Keys that never expire, or expire later than the limit allows, are flagged Exceeds max lifetime on the API Keys page, and the Policies page counts them, so you can set compliant expirations on your own schedule.
- What is the difference between rolling and rotating an API key?
- Rotating usually means creating a new key and deleting the old one, which loses its usage history and settings. Rolling in LLM Gateway replaces only the secret: the old secret stops working immediately, while the key's name, limits, usage, IAM rules, compliance policy and expiry stay.
- Is the maximum key lifetime available on every plan?
- No. The maximum key lifetime is part of the Enterprise access control feature. Per-key expiration and rolling in the dashboard work on every plan. The master API, including the roll endpoint, needs master keys, which are also an Enterprise feature.
One API key for every model.
Route to 200+ models with automatic failover, caching, and real-time cost analytics. Free to start — no credit card required.
Not ready to switch yet?
Follow new model releases instead.
A short roundup when new models land. Unsubscribe anytime.