Sphere wins 2026 Global Recognition Award
Sphere Partners
Stopping Secret Leakage: Keeping API Keys Out of Prompts and Completions

Stopping Secret Leakage: Keeping API Keys Out of Prompts and Completions

A pasted stack trace, a hardcoded password, a model that echoes back a credential it retrieved — secret leakage is common and costly, and one of the most reliably catchable patterns in AI traffic.

3 min read
In this article

A pasted stack trace, a config file dropped into a prompt for help, a model that echoes a credential it saw during retrieval — secret leakage is one of the most common and most costly ways enterprise AI goes wrong. It is also one of the most preventable, because credentials have shapes a deterministic runtime can recognize on sight.

How secrets end up in AI traffic

Nobody sets out to send an API key to a model. It happens because prompts are where people paste things: a failing log that contains a bearer token, a code snippet with a hardcoded password, a config someone wants explained. On the way back, a model that retrieved a document containing a credential can repeat it in an answer. Both directions are live, and both are routine.

The cost is asymmetric. A leaked credential isn't an embarrassment; it's a working key to a system, sitting in a prompt that may have crossed your boundary or landed in a log. Treating it as a first-class thing to catch is not paranoia — it's proportionate to what a single leaked secret can unlock.

Why secrets are the easy case — and the inexcusable one

Unlike fuzzy risks, secrets are structured. Keys, tokens, and credentials follow recognizable formats and conventions, which makes them among the most reliably detectable patterns on the wire. That's the uncomfortable part: because they're so catchable, letting one through is not a hard problem you lost — it's an easy problem you skipped.

The point

A risk this structured and this costly is exactly the kind a deterministic check should own. There is no excuse for a credential-shaped string crossing your boundary unnoticed.

Both directions, always

  • Outbound: a secret in a prompt is caught and masked before the prompt leaves your boundary, so it never reaches the model or a downstream log.
  • Inbound: a completion that contains a credential — echoed, retrieved, or inferred — is caught on the way back, before it reaches a user or an action.

Checking only the prompt is a half-measure that feels like coverage. The model can surface a secret it read during retrieval just as easily as a user can paste one, so the return path needs the same scrutiny as the outbound path.

Detect, then decide

Detection is deterministic; the response is a policy you set. A caught secret can be redacted so the interaction continues without it, or the call can be blocked outright for the most sensitive classes. Either way the event is recorded on the audit ledger — what was caught, in which direction, and what was done — so a security team can see exactly how often it's happening and where the paste habit lives.

Where it sits

Secret detection is one of the checks the deterministic firewall runs on every call, alongside injection, PII, and exfiltration. Because it runs inside your boundary, a secret is caught before it can leave — which is the only place catching it actually protects you.

Frequently asked questions

You can, and you should, and it won't be enough. People paste logs and configs to get help; the secret rides along without their noticing. A control that catches credentials on the wire protects you regardless of whether the human remembered the rule — which is the only kind of protection worth relying on.
API keys, access tokens, passwords, private keys, and connection strings — the structured credentials that grant access to a system. Because they follow recognizable formats, they're among the most reliably detectable patterns in AI traffic.
It's caught and, per your policy, redacted so the interaction can continue safely or blocked for the most sensitive cases — and the event is recorded on the audit ledger with its direction and disposition, so security can see the real frequency.
Yes. Detection runs in both directions, because a model can echo a credential it encountered during retrieval just as a user can paste one. The return path gets the same inspection as the outbound path.

Catch the key before it leaves. See how the security runtime detects API keys, tokens, and credentials in AI traffic — in both directions — and records every catch. Book a walkthrough.

We'd love to hear from you!

Please provide your contact details, and our team will get back to you promptly.