Tokens vs API keys
One names an application, the other names a session — and that difference decides everything.
An API key identifies an application: it's a long-lived, coarse-grained secret good for metering and simple access. A token identifies a user or session: it carries scopes and an expiry, is short-lived, fine-grained and revocable. Keys answer 'which app is this?', tokens answer 'who is this, for how long, and allowed to do what?'.
What an API key is
An API key is a single long, random string the server issues to an application. Presenting it says 'this request comes from app X' — it identifies the caller as a whole, not any particular user. It is the simplest possible credential: one secret, attached to every call.
What a token is
A token — typically a signed JWT or an OAuth access token — identifies a user or session and carries claims inside it: who the user is, which scopes they hold, and when it expires. Instead of a bare 'this is app X', it says 'this is user Y, allowed to do these things, until this time'. That extra structure is the whole point.
Lifetime and granularity
Keys are long-lived and coarse: one key usually grants an app its full set of permissions and stays valid for months or years until manually rotated. Tokens are short-lived and fine-grained: they expire in minutes or hours and encode narrow scopes, so the same user can hold different tokens for different powers. Granularity is where the two most sharply diverge.
Revocation and blast radius
Because a token expires on its own and can be tied to a session, revoking access can be as simple as waiting for expiry or invalidating one session — its blast radius is naturally bounded. A leaked API key, by contrast, keeps working until a human notices and rotates it, potentially exposing everything the app can reach. This is the security case for preferring short-lived tokens for anything user-facing.
When to use each
Reach for an API key when the caller is a server or script and you mainly need to identify the app, meter usage and enforce quotas — machine-to-machine access where there is no human 'user'. Reach for a token when real users log in and you need per-user, per-scope, expiring, revocable permissions. Many systems use both: a key identifies the integrating app while tokens govern each user's session within it.
Two credentials, two different questions
API keys and tokens are constantly confused because both are secret strings you paste into an Authorization header to get past an API's front door. But they were designed to answer different questions, and conflating them leads directly to security mistakes. An API key answers "*which application* is calling?" A token answers "*who* is this, *what* are they allowed to do, and *for how long*?"
That single distinction — an application identity versus a user/session identity — cascades into every other difference between them: how long they live, how finely they can be scoped, and how easily they can be revoked. Get the mental model right and the "which should I use?" question mostly answers itself.
The API key — coarse, long-lived, about the app
An API key is the simplest credential imaginable: the provider generates one long random string and hands it to a developer, who attaches it to every request. Because the key represents the *whole application*, it is naturally coarse-grained — it typically unlocks the full set of permissions that app has been granted, with no notion of "this call is only allowed to read." And because rotating a key means updating it everywhere the app runs, keys are deliberately long-lived, often lasting months or years.
This makes keys excellent at a specific set of jobs. They are perfect for identifying an integrating application, for metering usage, for enforcing rate limits and quotas, and for straightforward server-to-server access where there is no human user in the picture at all — a backend cron job calling a data provider, for instance. What they are *not* good at is expressing per-user permissions or being revoked quickly. A key has no built-in expiry and usually carries no claims about scope, so if it leaks, it keeps working with full power until a human notices and rotates it — a large and open-ended blast radius.
The token — fine-grained, short-lived, about the user
A token flips every one of those properties. It identifies a user or session, and — especially as a signed JWT or an OAuth access token — it *carries claims inside itself*: the user's identity, the specific scopes they've been granted, and an expiry timestamp. So rather than a bare "this is app X," a token asserts "this is user Y, permitted to do exactly these things, until this moment."
That structure is what makes tokens fine-grained and short-lived by design. The same user can hold different tokens conferring different powers, and each one expires on its own after minutes or hours. Crucially, tokens are revocable: because they expire automatically and can be bound to a session, cutting off access can be as simple as letting the token lapse or invalidating one session server-side. A leaked token therefore has a naturally *bounded* blast radius — it dies at expiry regardless of whether anyone noticed the leak. The cost of all this is a little more machinery: tokens have to be issued, validated, refreshed, and sometimes tracked.
Choosing — and why real systems use both
The decision comes down to *who or what* is on the other end and *how much control* you need over permissions and lifetime.
- Use an API key when the caller is a machine — a server, a script, a batch job — and your main needs are identifying the app, tracking its usage, and applying quotas. There is no per-user permission story to tell.
- Use a token when real users are involved and you need per-user, per-scope, expiring, revocable access. Anything user-facing — a mobile app, a single-page app, a "sign in with…" flow — wants tokens so that permissions are precise and a compromise is self-limiting.
In practice the two are complementary rather than competing, and large platforms use them *together*. A common pattern: an integrating application authenticates itself to the platform with a long-lived API key (so the platform knows which app it is and can bill and rate-limit it), while each individual end-user's actions within that app are governed by short-lived, scoped tokens issued through OAuth. The key answers "which app," the tokens answer "which user, doing what, for how long" — and using each for the job it was built for is exactly what keeps an API both usable and secure.
API key = identity of an application; a token = identity of a user or session.
Keys are long-lived and coarse; tokens are short-lived, scoped and expiring.
Tokens are revocable and carry claims (who, scopes, expiry); keys usually don't.
Keys are great for server-to-server access, usage metering and quotas.
Tokens fit user-facing auth where permissions and sessions must be fine-grained.
A leaked key stays valid until rotated; a leaked token dies at expiry — so tokens limit blast radius.
Quick quiz
What does an API key primarily identify?
Why does a leaked token typically have a smaller blast radius than a leaked API key?
REST API authentication methods
Six ways to prove who's calling your API — and what each one costs you.
Top tips for API security
An API is a door into your data — these are the locks every one of them needs.
JWT explained
A signed, self-describing token that lets a server trust a request without looking anything up.
Sessions, cookies, JWT & OAuth 2.0
How a server remembers who you are — and who let you in.