Skip to main content
There are four patterns teams usually reach for when giving agents API access. Each solves the immediate problem quickly, but each leaves security or operability gaps.

Hardcoded API keys

The simplest pattern: read one token from an environment variable and use it for every request.
A common MCP server pattern looks like this:
It works for demos. In production, every caller gets the same long-lived power.

Shared service account

A step up from a raw key: create one bot account per platform and share it across agents, scripts, and pipelines.
Audit logs show one actor (github-bot) for many systems. Attribution becomes guesswork.

User token passthrough

Here, the agent receives the user’s OAuth token directly.
This feels natural but usually overgrants permissions.
The agent inherits the user’s full authority, not the task’s minimum authority.

Long-lived personal access tokens

Common in CLI agents and unattended automations: users paste PATs/API keys into .env.
Over time, the same token spreads widely:
These tokens are broad, long-lived, and hard to rotate without outages.
These patterns ship quickly. They fail when agents move into production and teams need least privilege, attribution, and controlled revocation.