How do you secure an AI API key? Give every application, environment, agent and third-party tool its own key; scope each one at the provider and cap it with a provider spend limit; keep keys in a secrets manager and never in code, browsers or mobile apps; record every key in an inventory; watch usage at the provider; rotate with an overlap on a schedule; and rehearse revocation before you need it. The 48 controls below break that down by the moment each applies.
Use this as a review, not a reading list. Each item should end with evidence — a screenshot of a limit, an inventory row, a rotation log — or a recorded decision that it does not apply. Each links to the guide that explains it.
Create
- One key per application and environment; never one shared key for everything (secure LLM API keys).
- One key per third-party tool, never your production key (third-party AI tools).
- One key per agent or automated job, not a developer's personal key (zero trust for AI API access).
- Every key has a named owner and a written purpose (AI credential inventory).
- An expiration date set where the provider supports it; OpenAI strongly recommends one on project keys1 (provider).
- Admin and usage-reporting keys kept separate from inference keys (provider admin key least privilege).
Store
- Keys loaded at runtime from an environment variable or secrets manager, never written in code2 (secure LLM API keys).
- No key in a repository, including history, notebooks and example configs (GitHub secret scanning for AI keys).
- Secret scanning enabled on every repository and in pre-commit hooks (GitHub secret scanning for AI keys).
- Encryption keys stored apart from the secrets they protect3 (BYOK credential architecture).
- Access to the secrets store limited to the services and people that need it, and logged (zero trust for AI API access).
Scope
- Each key in its own OpenAI project, Anthropic workspace or Google Cloud project serving only its workload4 (provider) (provider admin key least privilege).
- Google keys carry API restrictions, which Google says reduce the impact of a compromised key5 (provider) (Google API keys and Gemini).
- Models limited per key or project to what the workload needs (model access governance).
- Development keys cannot reach production connections, and an unscoped key reaches less, not more (gateway key controls and environments).
- Server-side keys restricted to known IP ranges where the platform supports it (gateway key controls and environments).
Use in applications
- No provider key in a browser, desktop or mobile app; calls go through your server (AI API keys in frontend and mobile apps).
- A public AI feature has per-user limits so it cannot be used as a free proxy (AI feature abuse).
- Per-customer limits on any feature your customers can trigger (per-customer AI usage limits).
- Keys never logged, echoed in errors or sent to observability tools (LLM prompt logging policy).
- Prompts and responses checked for credentials before they leave or return (LLM guardrails at the gateway).
Agents and tools
- Coding agents use a dedicated, limited key, ideally through a gateway rather than a raw provider key (Claude Code and Codex through a gateway).
- Agent runs have a spend or step bound so a loop stops (bound AI agent loops).
- Agents cannot read
.envfiles, key files or secret stores they do not need (AI coding agents and secrets exposure). - MCP servers inventoried, pinned and reviewed like dependencies; credentials in their configs scoped (MCP server credential leaks).
- Assistant settings checked for base URLs, key helpers and MCP servers nobody added (AI supply chain attacks in 2026).
- Dependencies pinned by hash; install and build steps run without provider keys (AI supply chain attacks in 2026).
Monitor
- Usage reviewed at the provider by key, not only in your own tools5 (provider) (signs an AI API key is abused).
- Alerts on spend or volume that departs from a scope's usual day (LLM spend anomalies).
- Provider usage compared with gateway traffic to find calls that bypassed it (detect gateway bypass).
- Unapproved keys and accounts looked for, not assumed absent (shadow AI API usage).
Limit spend
- A hard spend limit on every project or workspace a key lives in; OpenAI's fails requests with a
429once reached6 (provider) (provider spend limits compared). - Spend alerts set below each hard limit; OpenAI notes alerts alone do not cap spend6 (provider).
- Per-key and per-project caps enforced before the provider is called (LLM spend limits compared).
- The worst case for a stolen key worked out and accepted in writing (cap a stolen AI key's damage).
Rotate
- A rotation schedule per key, recorded in the inventory (AI credential inventory).
- Rotation creates the replacement, deploys it, verifies it, then revokes the old key1 (BYOK credential architecture).
- Short-lived credentials used where the provider offers them5 (short-lived credentials for AI APIs).
- Unused keys deleted rather than left idle5 (provider).
Revoke
- Each team knows how to revoke each of its keys in minutes; OpenAI says revocation takes effect within a few seconds2 (provider).
- Revocation rehearsed once per key, end to end, including confirming the old key fails (leaked OpenAI API key).
- Replacing a key inside a gateway or tool is followed by revoking it at the provider (BYOK credential architecture).
Third parties
- Each vendor that holds a key has answered where it is stored, under which encryption key, who can read it, and how it is deleted (third-party AI tools).
- Each vendor's breach-notification commitment is in a contract, with a time limit (AI vendor security review questions).
- The blast radius of each platform holding your keys has been modelled (BYOK platform breach).
Incident
- A runbook for a leaked key: revoke, rotate, delete the exposed copy, review usage from the earliest exposure3 (leaked Anthropic API key).
- The evidence your provider will ask for about unexpected charges is known in advance (AI API key theft and your bill).
- A postmortem template ready, so each incident improves the controls above (AI credential incident postmortem).
How INFRO covers part of this list
INFRO is a gateway in front of the provider accounts you connect, so it covers the items about traffic that passes through it. Provider keys are encrypted with AES-256-GCM under a key held outside the database and never shown again. Applications and coding agents use INFRO gateway keys, stored as a SHA-256 digest, each belonging to one environment, optionally limited to chosen providers or IP ranges (403 ip_not_allowed before any provider call), with expiry and rotation with an overlap of none, 1 hour, 24 hours or 7 days (authentication). Model allowlists, hard budgets per organization, project, member and key checked before the provider is called, spend alerts and the audit log cover the matching items; on the Business plan, reconciliation with usage access reports OpenAI and Anthropic usage on a connected key that did not go through INFRO.
It does not cover the items marked (provider). A provider key stolen from anywhere, INFRO included, can be used directly at the provider, so scope it, cap it and watch it there as well.
