"Both ride the Bearer wire. The difference is the LIFETIME and the ISSUANCE process. That difference dictates everything — security posture, rotation policy, integration shape, support workload."
Same Wire, Different Lifecycle
From the HTTP perspective, an API key and a short-lived bearer token look identical — both are Authorization: Bearer <string>. The differences are entirely off the wire:
- API key: issued once (manually, via a dashboard), long-lived (months to years, until manually revoked), typically a single secret per integration. Server-to-server is the classic fit.
- Short-lived token: issued programmatically (login, OAuth flow, exchange), expires in seconds to hours, refreshable. End-user sessions and OAuth-grant flows are the classic fit.
Choosing one wrong for the context creates the wrong security posture.
The Leak Window Math
The decision often comes down to: if this credential leaks, how much damage does it do, and how long does the damage last?
Leaked API key: valid until manually revoked. May leak in a git commit, a frontend bundle, a customer-shared screenshot, a CI log. The discovery-to-revocation window can be days. During that window, the attacker has full integration access.
Leaked short-lived token: valid for the remaining seconds of its lifetime — often minutes. By the time the leak is noticed, the token is already invalid. The blast radius is bounded by the token's TTL.
That's why production AI APIs (Anthropic, OpenAI), payment APIs (Stripe), and any API with serious abuse potential lean on short-lived tokens for end-user flows. API keys are reserved for server-side use where the storage environment is tightly controlled.
When API Keys Are the Right Tool
API keys are simple, durable, and easy to integrate. They fit when:
- Server-to-server — the key lives in environment variables on a server you control. No browser, no end-user, no leak vector beyond your own infrastructure.
- Single tenant per key — the key represents one organization or service, not one human user.
- Low-frequency rotation acceptable — manual rotation every 90 days is workable.
- Stable identity — the integration won't change identities often.
Stripe's secret API keys (sk_live_...) fit all of these. Twilio's account SID + auth token, Anthropic's ANTHROPIC_API_KEY, GitHub's personal access tokens (when used by a server) — all server-to-server API keys.
When Short-Lived Tokens Are the Right Tool
- End-user sessions — the user logs in, receives a token, uses it for hours, refreshes or re-logs in. Browser-stored credentials with TTL.
- OAuth-granted access — third-party apps acting on a user's behalf. The user can revoke at any time; the token expires naturally as another layer.
- Multi-tenant with per-user scoping — each token represents a specific user + scope.
- Mobile or SPA contexts — anywhere the credential lives in environments where any leak could happen.
OAuth2 access tokens, JWT-based session tokens, and cwkPippa's PIN-issued bearer tokens all fit this pattern.
Rotation — The Forgotten Half
Both API keys and tokens need rotation policies:
- API keys: support multiple active keys per integration (so rotation doesn't require downtime), surface key age in the dashboard, encourage 90-day rotation, log usage per key (so you know which key to revoke if one looks suspicious).
- Tokens: short TTL is rotation by design. Add a refresh token (longer TTL, used only to mint new access tokens) and you get sliding sessions without re-authentication.
Stripe lets you have multiple secret keys active simultaneously so you can rotate without taking your integration down. JWT-based flows split short-lived access tokens (~15 min) from longer-lived refresh tokens (~30 days). Both patterns; both work.
cwkPippa's Mix
.env — server-to-server, single-tenant, low rotation risk because the env file never leaves the Mac. The two patterns coexist because the leak surface differs: a user token leak compromises one session; an Anthropic API key leak runs up a real bill until I notice. The protection matches the risk.