Skip to content

Security and governanceGuide

AI API keys leaked on GitHub: what secret scanning catches

GitHub scans public repositories for AI provider keys and forwards many of them to the provider for revocation. That safety net has holes: private repositories without the paid feature, other hosts, notebooks, images and logs. Here is what is covered, key type by key type, and what to add.

By INFRO Editorial

Published

9 min read

A grid of dark glass cards with small bar charts, a few of them lit amber, on a dark ground

In short

GitHub secret scanning runs on every public repository and forwards partner-format keys, including OpenAI and Anthropic API keys, to the provider, which can revoke them; push protection blocks many AI key formats before they land. It does not cover Google's Gemini API key format as a partner pattern, private repositories without GitHub Secret Protection, other Git hosts, or keys in images, logs and notebooks outside GitHub. Add a pre-commit scanner such as Gitleaks or TruffleHog and treat every exposed key as compromised.

Key takeaways

  • GitHub scans all public repositories and forwards partner-format secrets, including OpenAI and Anthropic API keys, to the provider, which decides whether to revoke.
  • Push protection for users is on by default for public repositories; push protection for repositories needs GitHub Secret Protection and is off by default.
  • GitHub's pattern table lists the Google Gemini API key format with neither partner reporting nor push protection, so Gemini key leaks rely on Google's own detection.
  • Private repositories, other Git hosts, container images, notebook outputs, CI logs on other platforms and chat transcripts are outside the partner safety net.
  • Run a pre-commit scanner such as Gitleaks or TruffleHog, and treat any exposed key as compromised even after the provider revokes it.

What happens when an AI API key is leaked on GitHub? If the repository is public and the key is in a format GitHub's partner program knows, GitHub sends it to the provider within seconds, and the provider can deactivate it. OpenAI and Anthropic API keys are partner formats; Anthropic says it deactivates exposed keys automatically and emails the owner. Push protection can also stop many AI key formats before the push lands. Everything outside that path — private repositories without GitHub's paid feature, other Git hosts, container images, notebook outputs, logs — is not covered, and Google's Gemini key format is not a partner pattern at all.

Treat secret scanning as a backstop, not a control you depend on. This guide sets out what GitHub covers for each major AI key type, where the gaps are, and the pre-commit and provider-side checks that close them. If a key has already leaked, start with what to do about a leaked OpenAI key or a leaked Anthropic key and come back here afterwards.

Why AI keys are a common leak

AI keys sit in the same places as every other secret — .env files, notebooks, CI variables — but they spend money and expose data the moment they work. GitGuardian's State of Secrets Sprawl 2026 counts 28,649,024 new secrets in public GitHub commits in 2025 and 1,275,105 secrets for AI services, which it reports grew 81% year over year1. The same report says 32.2% of internal repositories contain at least one secret against 5.6% of public ones, that commits co-authored by Claude Code leak secrets at roughly twice the baseline rate, and that 64% of valid secrets it detected in 2022 were still valid four years later1. That last number is the one to remember: a leaked key that nobody revokes stays useful for years.

How GitHub secret scanning works

Secret scanning runs automatically, at no cost, on every public repository. For organization-owned private and internal repositories it needs GitHub Secret Protection on GitHub Team or Enterprise Cloud2. When it runs, it covers the whole Git history on all branches, plus issue descriptions and comments, pull request titles, descriptions and comments, discussions, wikis and secret gists2.

What happens to a match depends on two things: whether the key format belongs to a partner, and whether the repository is public.

  • Partner format, public repository. GitHub sends the token, its type and the URL where it was found to the provider's endpoint. The provider decides how to revoke and notify; GitHub recommends providers treat every reported secret as public and compromised3. These partner alerts are reported to the provider and do not appear in the repository's own alerts2.
  • Public npm packages. The partner program also covers public npm packages3.
  • Private repository. Matches raise alerts for the repository's admins and the committer. They are not sent to the provider3, so nothing is revoked for you.

What GitHub covers, key by key

GitHub's supported patterns table is the authority here; it changes, so check it before relying on a row. As read on 2026-10-214:

Key type (GitHub's name)Partner: sent to providerPush protectionValidity check
OpenAI API KeyYesYesYes
Anthropic API KeyYesYesYes
Anthropic Admin API KeyYesYesYes
Anthropic Service Account / User API KeyYesYesNo
Google API KeyYesNoYes
Google Gemini API KeyNoNoNo
Google Cloud Service Account CredentialsYesYesYes
Azure OpenAI KeyYesYesNo
Azure AI Services KeyYesYesYes
Hugging Face User Access TokenYesYesYes
xAI API KeyYesYesYes
Groq API KeyYesYesYes
Mistral AI API KeyNoYesYes
DeepSeek API KeyNoYesYes
Perplexity API KeyNoYesNo
Cohere API KeyNoYesYes

Three rows deserve attention.

OpenAI. GitHub began scanning public commits for OpenAI keys in June 2021; its announcement says the issuing service deactivates a found key and alerts the owner, in seconds5. That is GitHub's description; confirm in your own organization's notifications what OpenAI did with a specific key.

Anthropic. Anthropic says that when GitHub finds a Claude API key in a public repository, it notifies Anthropic, which deactivates the key and emails the affected user6. On 2026-10-13 GitHub added Anthropic's service and user key detectors to push protection by default, blocking matching commits in repositories with secret scanning enabled, including free public ones7.

Google Gemini. The Gemini key type has neither partner reporting nor push protection in GitHub's table; the generic Google API Key type is a partner pattern but is not blocked at push time4. Google's own side has changed this year: since 2026-05-28 new keys created in Google AI Studio are auth keys bound to a service account, with what Google calls "fast-acting leaked key enforcement", and the Gemini API rejects unrestricted standard keys8. Restrict every Gemini key to the Gemini API, and see Google API keys and Gemini exposure for the older Maps and Firebase keys that gained Gemini access.

Push protection: blocking the push itself

Push protection stops a push that contains a supported secret before it reaches the repository9. It comes in two forms:

  • Push protection for users is on by default, only on GitHub.com, and stops you pushing secrets to public repositories9.
  • Push protection for repositories is off by default, needs GitHub Secret Protection, and can be enabled per repository, organization or enterprise9.

It covers command-line pushes, commits in the web interface, file uploads, REST API requests and, for public repositories, interactions through GitHub's MCP server — relevant now that coding agents push code9. By default anyone with write access can bypass it by giving a reason; a bypass is recorded in the audit log, raises an alert and emails owners and security managers, and "I'll fix it later" leaves an open alert9. Use delegated bypass so a bypass needs a reviewer.

What secret scanning does not see

The partner path is narrow: public GitHub repositories and public npm packages. A key in any of the following is outside it:

Where the key isWhy GitHub's partner path misses it
Private repository without Secret ProtectionNot scanned at all2
Private repository with Secret ProtectionAlert only; the provider is not told3
GitLab, Bitbucket, self-hosted GitNot GitHub
Container images in a registryNot a repository; a COPY .env layer ships the key
Notebook outputs on hosted notebook servicesPrinted os.environ values live in output cells outside Git
CI logs on other platforms, crash reports, APM tracesLogs are not repositories
Packages on registries other than npmThe partner program documentation names only npm
Chat threads, tickets, agent transcriptsText outside GitHub
Browser bundles and mobile binariesShipped to users by design; see AI API keys in frontend and mobile apps

A key in a Gemini format leaked even to a public repository relies on Google's detection, not GitHub's partner path.

Add your own scanning before the push

A pre-commit hook catches the key on the developer's machine, before it reaches any host. Two widely used open-source scanners:

Gitleaks detects secrets in Git repositories, directories and standard input, and ships a pre-commit hook; its README notes the project is now feature complete and receiving security patches only, with the maintainer's focus moving to a successor project, Betterleaks10.

.pre-commit-config.yaml (Gitleaks)
repos:
  - repo: https://github.com/gitleaks/gitleaks
    rev: v8.24.2
    hooks:
      - id: gitleaks

Run pre-commit autoupdate to move to the latest tag and pre-commit install to activate it10.

TruffleHog classifies over 800 secret types and can verify whether a found credential is live by calling the issuer's API, labelling each result verified, unverified or unknown11. It scans Git, GitHub and GitLab organizations, Hugging Face, Docker images, S3 and GCS buckets, filesystems, Postman workspaces and CI systems — useful for the places in the table above11. In CI, fail the build on verified or unknown results for the changes on a branch:

TruffleHog in CI
trufflehog git file://. --since-commit main --branch "$BRANCH" \
  --results=verified,unknown --fail

With --fail, exit code 183 means results were found11.

Scanners also run on the history you already have. Scan every repository once, including archived and forked ones, then rotate whatever is live.

When a scanner fires

The steps are the same whoever found the key:

  1. Revoke and replace at the provider first. Removing the commit does not revoke anything; GitHub's own guidance is to rotate immediately and treats history rewriting as optional2. Google's order for Gemini keys is generate a new key, deploy it, then disable the leaked one8.
  2. Check usage for the exposure window in the provider's console, per key or project.
  3. Find every copy. Forks, clones, CI caches, images built from that commit.
  4. Ask why the key was in a file that could be committed. A key that only exists in a secret manager and is injected at runtime cannot be committed.

The deeper fix is to have fewer long-lived provider keys in developer hands at all: short-lived credentials where the provider supports them, and one tightly held key per service elsewhere.

How INFRO handles keys that leak

INFRO is a control plane in front of the provider accounts you own, so two different keys can leak, and they behave differently.

A provider key you connected to INFRO is not in your repositories at all: it is sealed when you save it (AES-256-GCM, the key held outside the database), never shown again, and replaced through the console or the management API when you rotate it at the provider. But be plain about the limit: INFRO's budgets, allowlists and caps govern traffic that goes through INFRO. A provider key stolen from anywhere — a repository, a laptop, or a platform such as INFRO that also holds it — can be used directly against the provider, and none of INFRO's controls see that call. The backstops are at the provider: scoped keys, provider spend limits and revocation there. On the Business plan, reconciliation compares INFRO's records with OpenAI's and Anthropic's own cost data each day, and with usage access on it reports which usage on a provider key did not go through INFRO.

An INFRO gateway key (sk_infro_) is what your applications hold instead. It is not in GitHub's partner program, so nothing revokes it for you if it is pushed. What limits it is how you issued it: one key per service and environment, an IP allowlist so a copy used from elsewhere is refused with 403 ip_not_allowed before any provider call, a spend limit checked before the provider is called, an expiry, and rotation with an overlap window. On the Business plan, INFRO's guardrails can also detect OpenAI, Anthropic, Google and INFRO key formats in prompts and responses and block or redact them. Gateway key controls covers the setup, and Authentication the key format.

Summary

GitHub's secret scanning gives public repositories a fast, free safety net: OpenAI and Anthropic keys are forwarded to the provider, and push protection blocks most AI key formats at the push. It does not cover Gemini's key format as a partner pattern, private repositories without the paid feature, other hosts, images, notebooks or logs. Add a pre-commit scanner, scan your existing history, rotate at the provider whenever a key is exposed, and reduce how many long-lived provider keys exist in the first place.

Questions readers ask

Does GitHub automatically revoke a leaked OpenAI API key?
GitHub does not revoke keys itself. For partner formats found in public repositories, it sends the key to the provider, and the provider decides what to do. OpenAI has been a partner since 2021, and GitHub's announcement says the issuing service deactivates the key and alerts the owner. Rotate the key yourself anyway and check usage for the exposure window.
Does secret scanning work on private repositories?
Only if the organization has GitHub Secret Protection (GitHub Team or Enterprise Cloud). Even then, matches in private repositories raise alerts for the repository's admins and the committer; they are not sent to the provider, so nothing is revoked for you.
Will GitHub catch my Gemini API key?
GitHub's supported patterns table lists the Google Gemini API Key type with no partner reporting and no push protection. The generic Google API Key type is a partner pattern but is not blocked by push protection. Google says its newer auth keys include fast-acting leaked-key enforcement on its side.
Is deleting the commit enough after a key leaks?
No. Anyone who cloned or scraped the repository has the key, and deleting a commit does not revoke it. Revoke and replace the key at the provider, then review usage. Rewriting history is optional clean-up, not remediation.

From the team that builds it

Where this shows up in INFRO

INFRO is a control plane in front of the provider accounts you already hold. The capabilities below are the parts of it this article touches, each with the documentation that defines its behaviour.

  • Key limits and rotation

    Available with a plan

    Limit a gateway key to chosen providers or IP ranges, and rotate it with an overlap window so the old key keeps working while you deploy the new one.

    Read the documentation for Key limits and rotation
  • Provider connections

    Available with a plan

    Connect provider accounts you already hold. Each credential is encrypted when saved, scoped to your organization and never shown again; applications use INFRO gateway keys instead.

    Read the documentation for Provider connections
  • Budgets and spend ceilings

    Available with a plan

    A hard cap per organization, project, member, and key, with alerts at your own thresholds.

    Read the documentation for Budgets and spend ceilings
  • Spend anomaly and drift alerts

    Available with a plan

    Each scope's usual day is learned from its own history; a day that departs from it, a budget forecast to be exceeded, cost estimates drifting from the provider's own figures, unpriced traffic and failing connections become findings in the console. Routed to email on every plan, and to Slack and signed webhooks from the Startup plan.

    Read the documentation for Spend anomaly and drift alerts
  • Provider cost reconciliation

    Available with a plan

    Daily comparison of estimated spend against the cost reported by OpenAI's and Anthropic's own cost APIs, using a separate admin credential, with the likely cause of a persistent gap and a suggested rate you can apply. Included on the Business plan.

    Read the documentation for Provider cost reconciliation
  • Guardrails

    Available with a plan

    Pattern-based checks on chat completion prompts and responses: block, redact or flag email addresses, phone numbers, card numbers, IBANs, US Social Security numbers, IP addresses, API keys and your own terms, plus optional classifier checks on your own connection to a decision model's provider. Detection can miss things. Included from the Business plan.

    Read the documentation for Guardrails

INFRO accounts are self-serve. Provider usage is billed to you by your providers; INFRO charges a software subscription and takes 0% of model spend. See plans.

Sources

Numbered in order of first citation. Each was opened and checked against the claim on the date shown.

  1. 1.The State of Secrets Sprawl 2026 (opens in a new tab) — GitGuardian. Accessed Oct 21, 2026.
  2. 2.About secret scanning (opens in a new tab) — GitHub Docs. Accessed Oct 21, 2026.
  3. 3.Secret scanning partner program (opens in a new tab) — GitHub Docs. Accessed Oct 21, 2026.
  4. 4.Supported secret scanning patterns (opens in a new tab) — GitHub Docs. Accessed Oct 21, 2026.
  5. 5.RubyGems, Adobe and OpenAI are now GitHub secret scanning integrators (opens in a new tab) — GitHub Changelog. Accessed Oct 21, 2026.
  6. 6.API key best practices: keeping your keys safe and secure (opens in a new tab) — Anthropic. Accessed Oct 21, 2026.
  7. 7.Secret scanning blocks Anthropic keys by default, adds Salesforce (opens in a new tab) — GitHub Changelog. Accessed Oct 21, 2026.
  8. 8.Using Gemini API keys (opens in a new tab) — Google AI for Developers. Accessed Oct 21, 2026.
  9. 9.About push protection (opens in a new tab) — GitHub Docs. Accessed Oct 21, 2026.
  10. 10.gitleaks/gitleaks (opens in a new tab) — GitHub. Accessed Oct 21, 2026.
  11. 11.trufflesecurity/trufflehog (opens in a new tab) — GitHub. Accessed Oct 21, 2026.

About this article

On 2026-10-21 we opened GitHub's secret scanning, push protection and partner program documentation, GitHub's supported patterns table and its 2021 and 2026-10-13 changelog entries, Anthropic's API key best practices article, Google's Gemini API key documentation, the Gitleaks and TruffleHog repositories, and GitGuardian's State of Secrets Sprawl 2026 page. OpenAI's own key safety article could not be opened that day, so OpenAI's revocation behaviour is described from GitHub's announcement only. Written by the team that builds INFRO.

Last checked against its sources on . The next review is due by . No separate named reviewer is recorded for this article.

How articles are written, sourced and corrected is set out in the editorial standards.