Almost every agent fleet starts with one API key in one environment variable, shared by every agent the team will ever build. It feels like a shortcut. It is actually the decision that makes every later incident harder.
The short answer
Issue one credential per agent identity, scoped to only the providers and actions that agent needs, stored in a secrets manager rather than in code or prompts, and rotated on a schedule and instantly on suspicion. Per-agent keys are what make everything else work: spend attributes to a named agent, a kill switch can stop one agent without stopping the fleet, and a leaked key becomes a one-agent revocation instead of a rebuild of every integration you own.
Check your own setup as you read: run the free Spend Guard self-check or test a policy in the playground — five minutes, no signup, and the gaps it names map to the controls below.
Worked example: one leaked key, eleven agents down
Harbourline Freight, a fictional regional logistics firm, ran 11 agents — tracking updates, document extraction, customer replies — on one shared provider key. When the key appeared in a debug log that was attached to a support ticket, the only safe move was to revoke it, and all 11 agents stopped at once, mid-day, including the tracking agent customers actually noticed. Rebuilding access took 9 hours because nobody had a record of which systems used the key or where it was stored.
Harbourline now issues a key per agent, recorded in a registry: owner, purpose, providers, spend cap, rotation date. When the document-extraction agent's key was later flagged in a routine scan, revocation and reissue took 22 minutes and no other agent noticed. The registry also ended a quieter problem — two of the original 11 'agents' turned out to be abandoned experiments still holding live access, which the per-agent inventory made visible for the first time.
A key is an identity, so treat it like one
Every control in agent governance hangs off identity: caps need someone to cap, audit logs need someone to blame accurately, kill switches need a scope. A shared key collapses all of that into 'the account did it'. Issuing per agent is therefore not hygiene theatre — it is the precondition for attribution, scoped stops and honest postmortems. Name keys after the agent and its job, never after a person or a project phase, so the name still means something in a log two years later.
Scope each key to the smallest useful surface
A summariser does not need the provider account's full model catalogue, and a drafts-only agent does not need tool access with write verbs. Where the gateway mediates calls, scoping lives in the agent's policy: its allowlist of actions, its providers, its caps. Where a provider offers restricted keys, use them as a second fence. The test for scope is simple: if this key leaked tonight, what is the worst the holder could do, and how much could they spend before the cap refuses them?
Store keys where rotation is boring
Keys belong in a secrets manager or the gateway's own credential store — injected at runtime, never in repositories, prompts, screenshots or ticket attachments, which is where Harbourline's key escaped. Rotation should be a procedure a tired person can do: issue new, deploy, verify, revoke old, log it. If rotation requires hunting through systems, it will not happen on schedule, and it certainly will not happen quickly during an incident.
Rotate on a calendar and on suspicion
Set a rotation interval per risk tier — high-privilege agents quarterly, low-risk readers twice a year is a workable starting point — and rotate immediately on any suspicion: a key in a log, a departed contractor who had access, an unexplained spend blip. Pair every rotation with the registry entry so the fleet's access inventory is always current; an inventory that is wrong is worse than none, because people trust it during incidents.
What to do about the keys already in the wild
Most teams starting this migration find the shared key in more places than expected: a CI variable, a notebook, a contractor's laptop, a screenshot in a wiki. Treat the migration as a small amnesty: inventory without blame, issue the per-agent replacements, cut over system by system, and only then revoke the shared key and watch the logs for a week for anything still trying to use it. Anything that surfaces gets its own identity and an owner — including the embarrassing forgotten experiment, which is exactly the kind of thing the registry exists to catch while it is still a conversation rather than an incident.
Five actions to move to per-agent keys
- Inventory every place the shared key is used, and list every agent it serves — expect to find abandoned ones.
- Issue one scoped credential per agent and record owner, purpose, providers and cap in a registry.
- Move all keys into a secrets manager or gateway credential store; remove them from code, prompts and tickets.
- Cut agents over one at a time, verifying each works on its own key before revoking the shared one.
- Set rotation dates per risk tier and rehearse a single-key revocation until it takes minutes, not hours.
Source note and related guides
Figures in the worked example are illustrative, drawn from a fictional company created for this guide; the controls, failure patterns and procedures described are the gateway's documented behaviour — see the Agent Auth Gateway documentation and the policy patterns in allowlists vs denylists, spend caps and the agent kill switch. Reviewed by the Ingenious AI team, 2026-11-14.
Sources
- RFC 6749, The OAuth 2.0 Authorization Framework, the IETF standard behind scoped, expiring access tokens: rfc-editor.org, 2012
- Model Context Protocol specification — Authorization, the MCP standard for OAuth-based authorization of MCP servers: modelcontextprotocol.io, 2025
- NIST AI Risk Management Framework (AI RMF 1.0), the voluntary framework for managing AI risk across design, development and use: nist.gov, 2023