Auth & Identity

API Keys vs OAuth

API keys and OAuth tokens both authenticate requests, but they differ in granularity, lifetime, and identity. Knowing when each fits helps you secure an integration appropriately.

What you'll learn

  • Contrast API keys with OAuth access tokens
  • Explain the granularity and lifetime differences
  • Identify where each approach fits best
  • Recognise why OAuth suits delegated access

6 min

Two different models

An API key is a static, long-lived string that identifies a calling application and little else. An OAuth access token, by contrast, is short-lived, carries scopes, and is obtained through a flow that can also capture user identity and explicit consent along the way. The first mechanism is deliberately simple; the second is considerably more expressive and carries far more context with each request.

The cleanest way to see the difference is in the question each can answer. An API key answers "which application is calling?" and stops there. OAuth can answer the richer question of "which user, allowing exactly what, and for how long?" That extra expressiveness is what drives most of the decision when you are choosing how to authenticate against the Merion API for a given task.

Granularity and lifetime

API keys are typically all-or-nothing in what they permit, and they rarely expire on their own without manual intervention. The combination means a leaked key is a serious and lasting exposure: it grants broad access and keeps doing so indefinitely until someone notices and revokes it. OAuth tokens, by contrast, carry scopes that narrow their permissions and an expiry that bounds their useful lifetime, with refresh tokens quietly handling renewal in the background.

This is why OAuth contains the blast radius of a leak along two independent dimensions at once — narrower permissions and a shorter window of validity — where a bare API key offers neither protection by default. A compromised access token is both less capable and shorter-lived than a compromised key, which materially changes how bad an incident becomes.

Where each fits

API keys can be acceptable for simple, low-risk, server-to-server access where rotation is genuinely disciplined and the permitted operations are tightly limited — although even in that niche, the OAuth client credentials flow is usually the stronger choice for the same job, since it adds scopes and expiry for little extra effort.

OAuth becomes the clearly right tool the moment a user's data or delegated access enters the picture. If you ever find yourself wishing you could attach per-user permissions, capture consent, or limit how long access lasts on top of a plain API key, that wish is the signal that you have outgrown the key and should move to OAuth. The mismatch only grows more painful the longer it is left in place.

Why OAuth for delegation

OAuth was purpose-built for delegated authorisation: letting one application act on behalf of a user without ever holding that user's password, and doing so with access that is both scoped and revocable. This is a fundamentally different problem from simply identifying which application is calling, and it is one an API key was never designed to solve.

An API key cannot express a statement such as "this application may read this particular user's records, but nothing else, and only until consent is withdrawn." Yet that is exactly the kind of fine-grained, user-centred permission that real integrations so often require. OAuth makes such statements first-class. For an end-to-end picture of how delegation actually works and why it matters, start with What Is OAuth 2.0 and build your understanding from there.

Key takeaways

  • API keys identify an application; OAuth tokens can also carry user identity
  • OAuth tokens are scoped and expiring; API keys often are neither
  • API keys may suit simple server-to-server cases with strict rotation
  • OAuth is the right model for delegated, per-user access

FAQ

Are API keys insecure?

Not inherently, but they are static and broad, so a leak is costly. Used with disciplined rotation and narrow privileges they can be acceptable for simple cases.

Can I use an API key to act on behalf of a user?

Not cleanly. API keys identify an application, not a user. For delegated, per-user access you want OAuth, which captures identity, scope, and consent.

Should I migrate from API keys to OAuth?

If you need scoped permissions, expiry, or user delegation, yes. For a stable internal job with tight controls, an API key may remain reasonable.

Integrate with Merion

Ready to build?

Read the API reference, grab the OpenAPI spec, and ship a resilient integration.