Back to Blog
AuthenticationAI AgentsSecurity

Macaroon Tokens vs API Keys: Why Capability-Based Auth Beats Identity-Based Auth for AI Agents

API keys answer "who are you?" Macaroon tokens answer "what can you do?" When autonomous agents need to delegate tasks and respect budget limits, the difference between identity and capability determines success or failure.

March 31, 2026 12 min read

Every API authentication system makes a fundamental choice: identify who the caller is, or specify what the caller can do. For twenty years, web APIs have chosen identity. Get an API key, prove you're legitimate, access everything your account allows. This worked beautifully when humans called APIs through carefully written code.

AI agents break that model. An agent doesn't just call your API — it delegates to sub-agents, spawns parallel tasks, and operates under budgets set by entities three delegation layers up the chain. Your API key knows the agent's identity, but it has no idea what that agent is authorized to spend, which sub-tasks it can delegate, or when its authority expires.

This is why the agent economy needs capability-based authentication instead of identity-based authentication. And the best implementation of capability-based auth for APIs is macaroon tokens.

Let's break down why API keys fail for AI workloads, how macaroons solve the problem, and what this means for your API's security model.

The API Key Model: Identity Without Constraints

API keys are fundamentally about who, not what. When you authenticate with an API key, you're proving your identity to the system. The system then checks its access control list: does this identity have permission to access this resource? If yes, full access. If no, complete denial.

This binary model works for human developers because humans make deliberate, accountable decisions. A developer with access to the `/admin` endpoints uses that access responsibly because their career depends on it. A developer with a production API key doesn't accidentally burn through a $10,000 budget because they're watching the dashboard.

But AI agents aren't humans. They don't have careers to protect or dashboards to watch. They have objectives to optimize and constraints to respect — but those constraints have to be encoded into the authentication system, not left to agent discretion.

Problem 1: All-or-Nothing Access

API keys grant binary access: you either have permission to access an endpoint, or you don't. There's no concept of "partial permission" or "permission with constraints." If an agent has access to the `/translate` endpoint, it can make unlimited translation requests until the monthly quota is exhausted.

In a multi-agent system, this creates impossible tradeoffs. Either you give every agent full account-level access (unsafe), or you create separate API keys for every agent (unmanageable), or you implement a proxy layer that enforces constraints before forwarding to your API (complex).

Problem 2: No Delegation Support

API keys can't be safely delegated. If Agent A needs to give Agent B limited access to an API, Agent A has two bad options: share its full API key (no constraints), or ask the API owner to issue a separate key for Agent B (manual process that doesn't scale).

There's no cryptographic way for Agent A to create a "sub-key" that has fewer permissions than the original. The API key model has no concept of attenuated delegation — giving someone less access than you have.

Problem 3: No Context About Authority

When an API receives a request with an API key, it knows who is calling, but nothing about the context of that call. Is this agent operating under a $10 budget or a $10,000 budget? Is this call part of a low-priority background task or a critical production workflow? Should this agent be able to delegate authority to other agents?

The API key carries identity, but not authority. The API has no way to make different decisions based on the caller's economic constraints, delegation status, or operational context.

The Macaroon Model: Capabilities With Built-In Constraints

Macaroons flip the authentication model. Instead of asking "who are you?" they embed the answer to "what can you do?" directly into the token. A macaroon is a capability token — it carries specific permissions, constraints, and delegation rules as part of its cryptographic structure.

Think of it this way: an API key is like a driver's license (proves identity, grants general permission to drive). A macaroon is like a rental car agreement (specifies exactly which car, for how long, with what mileage limit, and whether you can add additional drivers).

How Macaroons Work: Capabilities + Caveats

A macaroon has two parts: a root capability (what you can access) and a set of caveats (constraints on that access). Both are cryptographically bound together, so you can't remove caveats without invalidating the token.

# Root macaroon: access to translation API
root_secret = "ultra-secure-shared-key"
location = "https://api.example.com/translate"
identifier = "user-12345-translate-access"

# Create basic macaroon
macaroon = new_macaroon(root_secret, identifier, location)

# Add constraining caveats
macaroon.add_first_party_caveat("budget_max = 50.00")
macaroon.add_first_party_caveat("endpoints = /translate/*")
macaroon.add_first_party_caveat("expires = 2026-04-01T00:00:00Z")
macaroon.add_first_party_caveat("rate_limit = 100/hour")

# Result: a token that grants translate access with:
# - $50 maximum spend
# - Only translate endpoints
# - Expires April 1st
# - Max 100 calls per hour

The critical insight: these constraints are enforced by the authentication system, not by the application code. The API gateway validates the macaroon, checks each caveat, and either allows or denies the request based on the embedded constraints. The API itself never has to think about budgets, rate limits, or expiration — it's all handled at the auth layer.

Attenuation: The Secret Sauce of Delegation

Here's where macaroons get powerful: anyone holding a macaroon can add more caveats to create a more restricted token. This is called attenuation, and it's the foundation of safe delegation.

# Agent A has a macaroon with $50 budget
agent_a_macaroon = <root macaroon with budget_max = 50.00>

# Agent A delegates to Agent B, but with stricter limits
agent_b_macaroon = attenuate(agent_a_macaroon, [
  "budget_max = 10.00",      # Stricter than parent ($10 vs $50)
  "endpoints = /translate/en-es",  # More specific endpoints
  "expires = 2026-03-31T12:00:00Z"  # Shorter duration
])

# Agent B delegates to Agent C, even stricter
agent_c_macaroon = attenuate(agent_b_macaroon, [
  "budget_max = 1.00",       # Even stricter ($1 vs $10)
  "rate_limit = 5/hour"      # Additional constraint
])

# Critical: Agent C can NEVER spend more than $1, 
# even if Agent A's original macaroon had $50.
# Attenuation only restricts, never expands.

This solves the delegation problem elegantly. Any agent can safely create more restrictive tokens for sub-agents without involving the original API provider. The math is guaranteed by cryptography: attenuated tokens can only have fewer permissions, never more.

Side-by-Side Comparison: API Keys vs Macaroons

Let's look at how each authentication model handles real AI agent scenarios:

Scenario 1: Budget-Aware Translation Agent

Requirement: Agent needs access to translation API, but spending must be capped at $25.

❌ API Key Approach

Give agent the account-wide API key. API has no knowledge of $25 budget limit. Need to:
• Build proxy service that tracks spend per agent
• Implement budget enforcement outside the API
• Monitor spending dashboard manually
• Hope the agent doesn't exceed budget before checks run

✅ Macaroon Approach

Mint macaroon with budget_max = 25.00 caveat. Gateway enforces budget on every request. When $25 is spent, further requests return 402 Payment Required. No proxy needed. No dashboard monitoring. Hard enforcement at the protocol level.

Scenario 2: Multi-Agent Content Pipeline

Requirement: Main agent delegates to research agent ($10 budget), writing agent ($15 budget), and fact-check agent ($5 budget). Each sub-agent should only access relevant endpoints.

❌ API Key Approach

Either share one API key (all agents see all endpoints, no budget controls) or request three separate API keys from provider (manual process, doesn't scale). No way to ensure research agent can't access writing endpoints.

✅ Macaroon Approach

Main agent attenuates its macaroon three ways:
• Research agent: budget_max = 10.00, endpoints = /search/*
• Writing agent: budget_max = 15.00, endpoints = /generate/*
• Fact-check agent: budget_max = 5.00, endpoints = /verify/*
Each agent gets exactly the access it needs. Main agent never shares full credentials.

Scenario 3: Time-Limited Demo Access

Requirement: Give prospect agent 24-hour access to test API with $5 demo budget.

❌ API Key Approach

Create demo account, issue API key, set calendar reminder to revoke access in 24 hours, hope you don't forget. Budget enforcement requires custom billing logic. If demo user exceeds $5, bill arrives 30 days later.

✅ Macaroon Approach

Mint macaroon with expires = 2026-04-01T12:00:00Z, budget_max = 5.00. Access automatically expires. Budget automatically enforced. No manual cleanup needed. Demo user cannot exceed $5 by design.

Security Implications: Why Capability-Based Auth is Safer

Beyond delegation and budgets, macaroons provide better security properties than API keys for autonomous systems:

1. Principle of Least Privilege by Default

API keys typically grant broad access that gets refined through application-level authorization. Macaroons start with specific capabilities and can only become more restricted. This inverts the security model: instead of "grant access, then restrict," it's "define minimum necessary access from the start."

2. Temporal Authority

Every macaroon can include expiration caveats that are cryptographically enforced. API keys typically live forever unless manually revoked. For AI agents that might operate for minutes or hours, automatic expiration eliminates the risk of zombie credentials.

3. Context-Aware Authorization

Macaroons can embed context into the authorization decision. A caveat like time_of_day = business_hours or request_rate < 10/min lets you enforce policies that API keys can't express.

4. Cryptographic Audit Trail

Every macaroon embeds its delegation history. You can cryptographically verify not just that a request is authorized, but how many delegation steps led to that authorization and what constraints were added at each step.

When to Use Each Approach

API keys aren't bad — they're just optimized for a different use case. Here's when each approach makes sense:

Stick with API Keys When:

  • You're building for human developers who manage credentials manually
  • Your API has simple binary permissions (access or no access)
  • You don't need delegation (one developer, one key, one application)
  • Your existing auth infrastructure is working well
  • Budget enforcement happens at the account level, not the request level

Switch to Macaroons When:

  • You're building for AI agents that need bounded authority
  • You need fine-grained permissions (different budgets, different endpoints, different rates)
  • You want to enable safe delegation without manual key management
  • You need real-time budget enforcement at the request level
  • You want time-limited access tokens that expire automatically
  • You're implementing micropayments or pay-per-use billing

Implementation: Adding Macaroon Support to Your API

You don't have to choose between API keys and macaroons. Most implementations support both — API keys for human developers, macaroons for AI agents. Here's how to add macaroon support incrementally:

Step 1: Deploy an Economic Gateway

Add a macaroon-aware gateway in front of your existing API. The gateway handles macaroon validation, caveat enforcement, and budget tracking. Your API continues to work exactly as it does today for API key users.

┌─────────────┐     ┌─────────────────────┐     ┌──────────┐
│ API Key     │────▶│                      │────▶│          │
│ Request     │     │  Economic Gateway    │     │ Your API │
└─────────────┘     │                      │     │          │
┌─────────────┐     │ • Macaroon validation│     │          │
│ Macaroon    │────▶│ • Budget enforcement │────▶│          │
│ Request     │     │ • Caveat checking    │     │          │
└─────────────┘     └─────────────────────┘     └──────────┘

# Two auth paths, same API backend

Step 2: Define Capability Mappings

Map your API endpoints to capabilities and define which caveats you'll honor. Start simple:

# Example capability mapping
capabilities:
  translate-api:
    endpoints: 
      - /translate/*
      - /languages
    supported_caveats:
      - budget_max
      - rate_limit  
      - expires
      - source_lang
      - target_lang

  premium-translate:
    endpoints:
      - /translate/premium/*
    supported_caveats:
      - budget_max
      - expires
      - customer_tier >= premium

Step 3: Mint Your First Macaroons

Create restricted tokens for your first AI agent users:

import { Macaroon } from 'macaroons.js';

// Mint a macaroon for agent demo access
const demo_macaroon = new Macaroon({
  rootKey: process.env.MACAROON_ROOT_KEY,
  identifier: 'agent-demo-march-2026',
  location: 'https://api.yourservice.com/'
});

demo_macaroon.addFirstPartyCaveat('budget_max = 10.00');
demo_macaroon.addFirstPartyCaveat('expires = 2026-04-07T00:00:00Z');
demo_macaroon.addFirstPartyCaveat('endpoints = /translate/*');

// Agent gets this serialized macaroon as bearer token
const token = demo_macaroon.serialize();

Step 4: Enable Agent Self-Attenuation

Agents can create more restricted tokens for delegation. Provide simple SDK methods:

# Agent A has demo macaroon, delegates to Agent B
attenuated_token = agent_a_token.add_caveats([
  "budget_max = 2.00",           # Subset of parent budget
  "endpoints = /translate/en-es", # Subset of parent endpoints  
  "expires = 2026-04-01T12:00:00Z" # Shorter expiration
])

# Agent B can't spend more than $2 or access other endpoints
# even if Agent A's original token allowed more

Real-World Impact: The Numbers

Moving from API keys to macaroons isn't just a security improvement — it's an economic enabler. Consider the operational impact:

Before: API Key Management Overhead

  • Manual provisioning: 30 minutes per new agent integration
  • Budget monitoring: Daily dashboard checks, quarterly budget reconciliation
  • Access revocation: Manual cleanup when projects end
  • Incident response: Hours to identify which agent caused usage spikes

After: Capability-Based Automation

  • Self-service provisioning: Agents mint restricted tokens instantly
  • Automatic budget enforcement: Hard limits prevent overages
  • Cryptographic expiration: No manual cleanup needed
  • Built-in attribution: Every macaroon carries delegation history

The productivity gain is significant, but the risk reduction is transformative. With API keys, a runaway agent can blow through a monthly budget in hours. With macaroons, an agent can spend exactly what it's authorized to spend, no more.

The Strategic Advantage

API providers who adopt capability-based authentication early gain a significant competitive advantage in the agent economy. Here's why:

1. Safe Agent Integration

Enterprises hesitate to integrate AI agents with critical APIs because of cost and security risks. Macaroons eliminate both concerns. Agents can't exceed their budgets or access unauthorized endpoints by design.

2. Zero-Friction Micropayments

Macaroons enable the holy grail of API monetization: agents that discover your API, pay for access, and start consuming — all without human intervention. Combined with Lightning Network payments, you get sub-second payment settlement for sub-cent API calls.

3. Delegation-Native Architecture

As agent systems become more sophisticated, the ability to delegate safely becomes a core requirement. APIs that support capability-based delegation will integrate seamlessly with multi-agent workflows. APIs that don't will require complex proxy layers.

Getting Started Today

You don't need to rebuild your API to add macaroon support. Start with these three steps:

1. Deploy SatGate (or another macaroon-aware gateway) in front of your API. Configure it to pass through API key requests unchanged while adding macaroon validation for new requests.

2. Define your first capability: Pick one API endpoint and create a macaroon that grants access with a budget limit. Test it with a simple agent script.

3. Enable agent self-service: Publish a tool manifest that lets agents request macaroons with specific constraints. Watch how agents interact with budget-aware APIs differently than unlimited-access APIs.

The Bottom Line

API keys were designed for a world where humans authenticate to access machine resources. Macaroons were designed for a world where machines authenticate to access machine resources on behalf of humans with specific constraints.

The difference isn't academic. In the agent economy, the authentication model determines which integration patterns are possible, which business models work, and which APIs can safely operate at machine speed and scale.

Your API's next million customers are autonomous agents. The question is whether your authentication system can handle them safely, or whether you'll need proxies, workarounds, and manual oversight to bridge the gap between identity-based auth and capability-based workloads.

Choose capability-based authentication. Choose macaroons. Choose an auth model that scales with autonomous systems instead of fighting them.

Ready to Add Capability-Based Auth to Your API?

SatGate implements macaroon authentication with budget enforcement and delegation support. Deploy in minutes, test with your first AI agent, and scale to autonomous workloads.