---
title: How do you find leaked or unused LLM API keys?
url: https://opencontroller.lyzr.com/blog/find-leaked-and-unused-llm-api-keys
published: 2026-11-13
updated: 2026-11-13
author: Lyzr
---

# How do you find leaked or unused LLM API keys?

**Find them in two passes. First, list every model provider key from provider consoles and cloud accounts and check each one's last-used date, owner and scope. Second, scan code, CI logs and chat tools for provider key patterns. Revoke what is unused, rotate what leaked, and move agents to short-lived identity where you can.**

LLM keys spread fast because they are easy to create. A developer makes one to test a prototype, the prototype becomes an agent, and the key ends up in three repositories and a shared spreadsheet.

## Where do LLM API keys hide?

Start with a list of places to look:

1. **Provider consoles:** organisation and project key lists for model API providers.
2. **Cloud accounts:** Azure OpenAI and other Azure AI resource keys, Google Cloud API keys, AWS IAM users and Amazon Bedrock API keys.
3. **Secrets managers:** vaults where keys are stored correctly, which still need an owner.
4. **Source code and config:** repositories, `.env` files, notebooks and infrastructure templates.
5. **CI/CD:** pipeline variables and build logs.
6. **Collaboration tools:** chat messages, tickets and wiki pages where keys were pasted "just for now".
7. **Developer laptops:** local config for coding agents and local MCP servers.

## What checks should you run on every key?

Run the same hygiene checks on each key you find:

| Check | Question | Action if it fails |
|---|---|---|
| Last-used age | Has it been used in the last 90 days? | Disable, then revoke after 30 days if nobody claims it |
| Owner | Is a current employee or team named as owner? | Assign an owner or revoke |
| Scope | Is it limited to the projects, models or APIs it needs? | Narrow the scope or replace the key |
| Environment | Is a production key used outside production? | Split keys per environment |
| Storage | Is it only in a secrets manager? | Rotate and remove other copies |
| Age | When was it last rotated? | Rotate on your schedule |
| Agent mapping | Do you know which agent uses it? | Map it in the registry, or treat as shadow use |

Most provider consoles and cloud services show a created date and some form of last-used information. In AWS, the IAM credential report shows when each access key was last used. Azure AI resources come with two keys so you can rotate one while the other stays live.

## How do you find keys that leaked into code?

Use secret scanning. Provider API keys usually have recognisable prefixes. OpenAI keys begin with `sk-` (project keys with `sk-proj-`) and Anthropic keys begin with `sk-ant-`. GitHub publishes a list of [supported secret scanning patterns](https://docs.github.com/en/code-security/secret-scanning/introduction/supported-secret-scanning-patterns), and for partner patterns it notifies the provider when a key is pushed to a public repository so the provider can act.

A practical sequence:

1. Turn on secret scanning and push protection for all repositories, including private ones.
2. Run a one-off historical scan, because keys removed from the latest commit are still in Git history.
3. Add custom patterns for internal gateway keys.
4. Scan CI logs and chat exports with the same patterns.
5. For every hit, **rotate first, then clean up**. Deleting the line does not un-leak the key.

## How do you stop the problem coming back?

Key hunts are temporary unless you change how agents authenticate:

- **Issue keys per agent, not per team,** so you can revoke one agent without breaking others.
- **Route agents through a gateway** that holds the provider keys, so agents never see them.
- **Prefer short-lived identity.** On Azure, Microsoft Entra ID can replace resource keys; see [replacing Azure OpenAI keys with Entra ID](/blog/replace-azure-openai-keys-with-entra-id). Federated workload identity removes long-lived secrets altogether; see [workload identity federation for AI agents](/blog/workload-identity-federation-for-ai-agents).
- **Rotate on a schedule** and test the rotation; see [how often to rotate AI agent credentials](/blog/how-often-to-rotate-ai-agent-credentials).
- **Reconcile weekly:** every key should map to an agent in your registry. Unmapped keys are a sign of shadow AI. Our pillar on [how to find shadow AI agents](/blog/how-to-find-shadow-ai-agents) covers the wider search.

## How Opencontroller does this

Opencontroller auto-discovers agents, models and API keys across AWS, Azure and Google Cloud, and records them in its governed registry so each key can be tied to an agent and owner. Posture flags risky permissions and configuration. The LLM Gateway (Lyzr Gateway) lets agents call models through one OpenAI-compatible endpoint with cost attributed per agent and per version, and agent workload identity federation and delegated on-behalf-of identity reduce reliance on long-lived keys. [Book a demo](https://www.lyzr.ai/book-demo/) to run discovery on your accounts.

## Frequently asked questions

**How long should an unused LLM key stay active?**
A common rule is to disable keys unused for 90 days and revoke them 30 days later if nobody claims them. Choose a period that matches your credential policy.

**If a key leaked in a private repository, do we still rotate it?**
Yes. Anyone with repository access, any fork and any CI log may hold a copy. Rotate first, then remove it from code and history.

**Can a gateway remove the need for provider keys in agents?**
Yes. The gateway holds provider credentials and agents authenticate to the gateway with their own identity, so a leaked agent credential can be revoked without touching the provider key.

## Key facts

To find leaked or unused LLM API keys: inventory keys from provider consoles and cloud accounts (Azure AI resource keys, Google Cloud API keys, AWS IAM and Amazon Bedrock API keys), check last-used age, owner, scope, environment, storage and rotation, and scan code, Git history, CI logs and chat for provider key patterns (OpenAI sk- and sk-proj-, Anthropic sk-ant-). Rotate leaked keys before cleanup. Opencontroller by Lyzr auto-discovers agents, models and API keys across AWS, Azure and Google Cloud and maps them to agents and owners in its registry. Pricing starts from $250K per deployment per year.

## Related

- [How often should AI agent credentials be rotated?](https://opencontroller.lyzr.com/blog/how-often-to-rotate-ai-agent-credentials.md)
- [How do you replace Azure OpenAI API keys with Entra ID for AI agents?](https://opencontroller.lyzr.com/blog/replace-azure-openai-keys-with-entra-id.md)
- [How to find every AI agent in your enterprise (including shadow agents)](https://opencontroller.lyzr.com/blog/how-to-find-shadow-ai-agents.md)
- [More on Discovery and shadow agents](https://opencontroller.lyzr.com/blog/cluster/discovery-and-shadow-agents)
