← Guides

How to give an AI agent API access without handing it your keys

By Jacob Holm · October 20, 2026

An API key is a bearer credential: whoever holds a copy can run billable requests on your account until you revoke it. If an agent can read the key, so can anything that tricks the agent, plus its logs, its config files, and every service that stores it. The safer pattern is to keep the real key somewhere the agent can't reach and give the agent something weaker: a placeholder, a scoped token, or a session that expires.

Why this matters now: the OpenCode Console breach

In October 2026, OpenCode said an intruder reached a legacy system on the night of October 16 and may have exposed the provider keys (OpenAI, Anthropic, Google) that 1.4% of OpenCode Console users had saved there. Some users reported unauthorized charges on their own accounts, ranging from a few hundred dollars to about $1,700, according to BleepingComputer and The Hacker News. OpenCode says refunds are underway. Deleting a key from a tool doesn't revoke it, and a tool's own budget can't cap use of a copied key. Only the provider can do that.

1. Credential brokers and injection proxies

The agent sends requests through a proxy. The proxy holds the real credential and attaches it on the way out, so the key is never in the agent's environment, files, or context.

2. Vaults with per-agent access

3. Managed auth for tool calls

If your agent mainly needs SaaS tools such as GitHub, Gmail, or Slack, tool platforms can hold the OAuth tokens for you. Composio says its execution proxy injects credentials into outbound requests server-side, so the agent only sees tool definitions and results. Arcade likewise keeps per-user tokens in its runtime and returns only tool results, never the tokens, to the model or MCP client.

4. Scoped, short-lived tokens

When a real key has to exist, shrink what it can do. OpenAI lets you create restricted keys with None, Read, or Write access per endpoint. Anthropic API keys belong to a single workspace. Use OAuth scopes and fine-grained tokens wherever a provider offers them, and prefer sessions that expire (Infisical sessions, Keycard tokens) over keys that never do.

5. Spend caps

A spend cap is the backstop for when everything else fails. OpenAI projects can enforce a hard monthly limit, after which requests return a 429 (there may be a small overage while settings propagate). In the Claude Console, each workspace can have its own monthly spend limit and alerts. Give each agent its own project or workspace so one leaked key can only burn that budget.

Checklist

Related: how to track and cap what your agent spends and how to debug AI agents. For sandboxes that inject secrets at egress, see E2B vs Daytona vs Modal. See every option in Identity/Auth for AI agents.

Options at a glance

ToolWhat it doesPricingLicense
Infisical Agent VaultCredential-brokering proxy: agents call APIs with a time-bound session token while the proxy attaches the real key, with method/path rules and audit logsFree for 5k brokered requests/mo; then $2 per 1k requestsPartly open source
LatchCredential proxy for agents: store the real key once and give the agent a revocable lat_ token, with policies and spend limitsUnknownUnknown
KeycardIdentity and access for AI agentsUnknownUnknown
1PasswordService accounts and SDKs for scoped, runtime secret access by agents, plus agentic autofill that signs Claude into sites without exposing passwordsPaid plansProprietary
WireboxAgent identities with inboxes, phone numbers, webhook tunnels and a zero-knowledge credential vault with per-agent grantsFree (3 identities); Pro $30/mo for 25 identitiesProprietary
ComposioTool integrations and auth for agentsFree tier; pay as you goOpen source
ArcadeTool-calling platform with user auth for agentsFree tier; $25/mo + usagePartly open source

We list what each vendor's own site says. Pricing changes often, so check it on the vendor's site before you commit.

Liked this guide? Get one new agent-infra guide a week.

One short email with a new guide and the tools worth knowing about. Free, and you can unsubscribe anytime.