Over 39 million secrets (API keys, tokens, credentials, etc.) were leaked across GitHub in 2024.
Postman's State of the API report revealed that for APIs, functionality and integration lead the priority list for developers, with only 37% prioritizing security testing, leaving APIs vulnerable.
API keys might work in the early stages of product development, but as B2B SaaS products mature and scale, they quickly reveal their limitations. When companies get serious about security, compliance, and multi-tenant architectures, the migration to JWTs and OAuth2 becomes inevitable.
Modern machine-to-machine (M2M) authentication is built specifically to replace insecure, legacy methods like API keys with secure, scoped, standards-based token auth. Using OAuth2 and JWTs enables contextual access for multi-tenant environments, AI integrations, and partner ecosystems—scenarios where API keys simply don't cut it.
This article breaks down the key differences between:
- API keys: Simple identifiers that work for basic scenarios
- JWTs: Self-contained tokens that scale with complex systems
By understanding when and why to make the transition, you'll avoid the painful refactoring that has become a rite of passage for growing B2B platforms.
Understanding API key and JWT
What is an API key?
An API key is a long, unique identifier that a client presents when calling an API to prove its identity. In simplest form, it works like a password shared between the client and the API provider.
How API keys work:
- The API provider generates a key (often per client)
- The client includes it with every request (typically in an Authorization header)
- The server looks up the key to identify the client and determine access rights
API keys are opaque identifiers - they don't carry information about permissions within the key itself. All metadata is stored server-side and associated with that key.
Real-world example: Stripe, the payment processing platform handling millions of transactions, uses API keys. They have Secret, Publishable, and Restricted API keys. These API keys can be operated in two modes, namely Sandbox mode (Using test keys) and live mode.
Here’s a table from Stripe documentation:
What is a JWT?
A JWT (JSON Web Token) is a standardized token format that contains JSON data (called "claims") and is digitally signed. Unlike API keys, JWTs are self-contained—the token itself carries information about the client and its permissions, verified via signature rather than lookup.
Components of a JWT:
- Header: Contains metadata about the token (algorithm, type)
- Payload: Contains claims about identity and permissions
- Signature: Ensures the token wasn't tampered with

Real-world example: Salesforce implements JWT-based access tokens as a transparent and efficient authorization mechanism, particularly beneficial for services built outside the Salesforce platform. Here's how it works in practice:
When a B2B SaaS company integrates with Salesforce, the system issues JWT tokens that contain the three critical parts as listed above:
Header: Contains metadata about the token itself
- The algorithm used (always RS256 for Salesforce)
- A key ID that helps verify authenticity
- Tenant key identifying which Salesforce org issued the token
Payload: Carries the essential authorization data:
- Who is the token for (aud - audience)
- When it expires (exp)
- Who issued it (iss - the domain)
- Who the user is (sub - with prefixes like uid: for B2B users)
- What permissions are granted (sc - scopes)
- Optional role information (roles)
Signature - Cryptographically signs the token for verification:
The advantage is that external services can validate these tokens locally without calling back to Salesforce, significantly improving performance in authorization flows.
For example, when a user authenticates through Salesforce SSO, the external B2B application receives a JWT that contains everything needed to verify the user's identity and permissions without additional API calls to Salesforce.
This approach is valuable for high-volume enterprise applications where authentication performance is critical.
API key vs JWT: 5 key differences
API keys are simple, long-lived identifiers best suited for straightforward authentication and identifying clients, with easy revocation but less built-in granular control.
JWTs are rich, self-contained tokens that shine in stateless, scalable architectures, offering embedded access control data and short-lived credentials for security, at the cost of more complexity in setup and less instant revocability.
The table below summarizes these differences.
When to use API keys
API keys are best when simplicity and long-term access are priorities.
Ideal scenarios for API keys:
- Simple service-to-service communication: When one backend service calls another under your control, an API key provides a quick and sufficient solution. For example, a payment processing service calling a currency conversion API within your architecture.
- Third-party integrations and public APIs: When you expose APIs to third-party developers (clients, partners, or the public), API keys provide a low-friction way for them to authenticate. Developers can sign up and get an API key to start using your service immediately. SaaS companies like Twilio provide multiple APIs to integrate with other services.
- Internal or private APIs in controlled environments: In an internal microservice call where security requirements are moderate (e.g., within a secured network or VPN), you might use API keys simply to assert identity without setting up a full token service. Similarly, scripts or cron jobs that call your API can use a static API key configured via environment variables. Provided these keys are kept secret, this approach is straightforward.
- Long-term processes or IoT devices: If you have machine clients that run continuously (like IoT devices or background jobs) and you don’t want them dealing with token refresh logic, an API key works as a persistent credential. For instance, an IoT sensor posting data to a cloud endpoint could use an API key baked into its firmware.
- Low-risk endpoint: If an endpoint only serves non-sensitive data (e.g. a public dataset) and you just want to prevent anonymous abuse, a simple API key is fine. It acts as a basic gatekeeping mechanism rather than full auth.
When to use JWTs
As B2B SaaS platforms scale, tokens don’t just gate access, they power visibility, usage insights, and compliance.
JWTs are structured tokens. Every token carries rich metadata like tenant ID, scopes, roles, and expiry, which means every API call can be:
- Traced to a specific customer or user
- Logged without server-side lookups
- Audited for abuse, billing, or troubleshooting
This kind of fine-grained access tracking is near-impossible with static API keys. Tokens become a foundation for everything from rate limits to usage-based pricing.
JWTs are great when you need a more robust, flexible, and scalable solution, especially as your system grows in complexity.
Ideal scenarios for JWTs:
- Microservices and distributed architectures: In a microservice-heavy environment, dozens of services may be talking to each other. JWT token authentication enables a unified auth system where each service can independently verify tokens, rather than calling a central auth service on each request. If you want to implement SSO or machine identity that all services recognize, JWT is a natural fit. JWTs essentially lay the foundation for a “single credential” that’s accepted by all parts of your system.
- Multiple clients or tenants with granular access (Multi-tenancy): If your API is serving multiple external clients or tenants, and especially if each client’s data and permissions differ, JWT token authentication provides a scalable way to enforce that. Each client (or each of the client’s users) can receive a JWT with claims that indicate who they are and what they can do. For example, a SaaS analytics platform serving many customer companies (tenants) can issue JWTs to each tenant’s integration that include a
tenant_id
claim. Each API call carries that JWT, and all microservices can enforce isolation by checking that claim. This avoids issuing and managing separate API keys for each combination of tenant and permission; instead, the JWT’s claims handle it. - Stateless authentication and performance-sensitive APIs: If your API needs to be stateless (no session storage) and able to handle high load, JWT token authentication is advantageous. High-traffic APIs benefit from the fact that verifying a JWT is just CPU work (verifying a signature and parsing JSON) which is often faster than an I/O operation to a database or cache for session or key data. You can spin up new instances of your service and they don’t need to share session state or key caches, they just need the public key for token verification.
- Short-lived or limited-use credentials: If you want credentials that auto-expire quickly for security, JWTs fit naturally. For instance, if you could issue a JWT that lasts 20 minutes, just long enough to complete a process, rather than a permanent API key. JWT flows automate the expiration/refresh process. Many security standards recommend using short-lived tokens for accessing critical resources.
- Integration with OAuth2/OpenID Connect: If you plan to integrate with an OAuth2 or OIDC provider (Okta, Azure AD, etc.) for issuing tokens, JWT is often the format you’ll get for access tokens or ID tokens. Adopting JWT in your system aligns with these industry-standard protocols, making it easier to later introduce things like user-facing OAuth flows, single sign-on, or federation. It also means you can leverage well-tested security features (signing algorithms, standard claims like exp, aud, iss)
A hybrid approach: Combining API keys and JWTs
You’ll sometimes see teams combine API keys and JWTs—for example, using an API key to authenticate the client, and then using a short-lived JWT token authentication for data access. While this might seem like a “best of both worlds” setup, it often ends up being a band-aid.
Hybrid auth introduces more complexity than it solves:
- You now have two sources of truth for authentication
- It's harder to trace actions across your system — who did what, with which credential?
- You’re managing multiple moving parts: storing and rotating keys, issuing and verifying tokens, and handling scopes across both
This setup can make sense as a temporary scaffold — for example, when migrating from an older key-based system to a more robust token-based model. But it’s not the right long-term foundation for modern B2B SaaS, especially if you're building:
- Multi-tenant APIs
- Platform extensibility
- Ecosystems involving AI agents or internal automation
In those cases, JWT token authentication should be the core of your auth model — with proper scoping, expiration, and verification. API keys might play a limited role during migration or for specific legacy integrations, but they shouldn’t drive your security architecture.
A clean, token-based model:
- Keeps things simpler
- Makes security easier to reason about
- Scales better as your product grows
So if you’re reaching for a hybrid model, ask yourself: is this just a bridge? And if so — what’s your plan to phase it out?
Decision framework: Choosing the right method
In the comparison between API key vs. JWT, or a combination, evaluate your specific requirements:
- How complex are your use cases and clients?
- Simple audience + simple needs → API keys
- Diverse audience or roles → JWT
- What are your security requirements?
- Highly sensitive data → JWT (short lifetimes, stronger flows)
- Lower risk + ease of use priority → API keys
- What are your scalability needs?
- High-volume, distributed system → JWT (stateless validation)
- Single service, small scale → API keys (simpler)
- Developer experience considerations
- External developers need simplicity → API keys
- Internal services or sophisticated partners → JWT
- Infrastructure and expertise
- Already using identity providers → JWT
- Small team without auth expertise → Start with API keys
Plan auth as infra from Day 1
Authentication between services isn't just an implementation detail — it’s infrastructure. And like all infrastructure, it shapes what you can build on top of it. The choice between API keys and JWTs will influence how easily your platform can grow, how securely it handles customer data, and how seamlessly you support integrations.
It’s tempting for a young SaaS product to slap in a simple API key auth and consider it “solved”. But if your roadmap includes things like multi-tenancy, microservices, or AI agents, you’re likely taking on future technical debt.
At Scalekit, we’re seeing modern teams go all-in on JWTs to:
- Secure M2M APIs with org-level scopes and fine-grained access control
- Use short-lived tokens with built-in rotation for tighter security
- Gain visibility into every token and machine identity
- Enable secure, scoped access for AI agents and automation
Authentication is foundational. The decisions you make today — especially about how machines talk to each other — will shape how quickly and safely you can scale tomorrow.