Agent Auth Gateway v1.0

Guides / 7 min read

How to Give Every AI Agent Its Own API Key

Published 2026-11-14 · Reviewed 2026-11-14 · By the Ingenious AI team

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

  1. Inventory every place the shared key is used, and list every agent it serves — expect to find abandoned ones.
  2. Issue one scoped credential per agent and record owner, purpose, providers and cap in a registry.
  3. Move all keys into a secrets manager or gateway credential store; remove them from code, prompts and tickets.
  4. Cut agents over one at a time, verifying each works on its own key before revoking the shared one.
  5. 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

Frequently asked questions

Why not share one API key across all my agents?

Because a shared key destroys attribution, scoping and incident response: you cannot tell which agent spent what, cannot stop one agent, and must rebuild the whole fleet's access when the key leaks. Harbourline lost 11 agents for 9 hours to one leak.

How many keys should one agent have?

One identity, with a credential per provider it legitimately uses where providers require their own keys. The identity is the unit of policy; the credentials are its keys to each provider, all recorded against that identity.

How often should agent keys be rotated?

Quarterly for high-privilege agents and twice a year for low-risk readers is a workable start, plus immediately on any suspicion — a key seen in a log, a change in who had access, or an unexplained spend change.

Where should agent API keys be stored?

In a secrets manager or the gateway's credential store, injected at runtime. Never in source code, prompts, environment files committed to a repo, screenshots or support tickets.

What do I do first if an agent key leaks?

Revoke that agent's key, reissue, and review the audit log for calls made under it. With per-agent keys that is a 20-minute, one-agent event. Then find how it escaped and close that path before rotating anything else.

Governing agents in production?

Spend caps, approval queues, policy simulation, burn forecasting, and step-up lockdowns — all built into the gateway. Free tier to start. Or test policies in the playground with no signup.

Share this: X Facebook LinkedIn WhatsApp
← How to Add Spend Guardrails to the OpenA… All guides Scoped Tokens for AI Agents: Least Privi… →