Your Secrets Can Still Leak with OpenRouter ZDR. Here's the Fix
OpenRouter ZDR didn't stop breached providers from copying prompts. Add five guards to keep your API keys, passwords, and private data safe.
OpenRouter ZDR didn't stop breached providers from copying prompts. Add five guards to keep your API keys, passwords, and private data safe.
Have you ever turned on "Zero Data Retention" in OpenRouter and assumed your prompts were now safe?
Zero Data Retention (ZDR) is a setting that sends your requests only to providers that promise not to store your prompts or the model's answers.
Security firm Dragos tested this. From July to November 2026, they sent about two million prompts to AI providers. Each prompt held a fake password or key that alerted Dragos if anyone used it.
Some of those prompts were sent with ZDR on, so you'd expect no one to ever see the keys inside them. But some of those keys got used. Unknown attackers had broken into three providers and copied the prompts.
This article explains what ZDR does and doesn't protect, how OpenRouter responded, and five guards you can add to protect what ZDR can't.
ZDR is a promise about storage, not protection from attackers. It only sends your prompts to providers that promise not to store them.
But Dragos found that the attacker copied each prompt the moment it arrived at the provider, before it even reached the model. Deleting it afterward didn't matter.
Dragos also found that a provider that promises ZDR can still pass the prompt on to another company that doesn't. So OpenRouter might send your prompt to a company that promises ZDR, but your prompt could end up with one that doesn't.
In response to Dragos's findings, OpenRouter says its own systems were not breached. On November 22, 2026, it posted a few changes for better security, including:
OpenRouter is also working on three more changes:
These changes help, but they can only detect a breach after it happens. So don't rely on OpenRouter alone. The next five sections show five simple guards you can add yourself.
Even with ZDR on, self-serve accounts still allow Safety Retention by default. It lets a provider keep any prompt to scan for misuse like hacking or weapons questions, but not train on it.
To opt out, follow the ZDR docs to stop allowing Safety Retention. However, some models such as Gemini on Vertex require Safety Retention, so you won't be able to use them once you stop allowing it.
By default, OpenRouter can send your request to any provider that serves the model, which can include providers that you don't trust.
To keep your prompt away from them, list the providers you trust in provider.only. OpenRouter then sends the request only to those providers:
response = client.chat.completions.create(
model="openai/gpt-4o",
messages=[{"role": "user", "content": prompt}],
extra_body={"provider": {"only": ["azure"]}},
)
To apply the same list to every request made with your API keys, set allowed providers in your privacy settings.
If a key is written in your script, it goes into the prompt every time you or a coding agent send that code to a model. Instead, store the key in a .env file or a secret manager, and read it from an environment variable. The prompt then holds only the variable's name, not the key.
Before:
client = OpenAI(api_key="sk-or-v1-abc123def456ghi789")
After:
import os
client = OpenAI(api_key=os.getenv("OPENROUTER_API_KEY"))
Here are two places to keep the key.
.env FileA .env file is a text file that lists environment variables and their values. Store the key in it:
OPENROUTER_API_KEY=sk-or-v1-abc123def456ghi789
Then load it in your code with the python-dotenv package:
import os
from dotenv import load_dotenv
load_dotenv()
client = OpenAI(api_key=os.getenv("OPENROUTER_API_KEY"))
A .env file helps, but it isn't foolproof, since the key is still on your disk, where a coding agent can read it. A secret manager such as Infisical is safer because it keeps the key off your disk entirely.
Once you've set it up, start your app with infisical secrets-manager run to pass the key in as an environment variable:
infisical secrets-manager run -- python app.py
A .env file keeps the key out of your code, but the key can still reach a prompt. Your app may include a log or error message that prints the key.
If a key does end up in a prompt, masking replaces it with a label such as [secret: OPENROUTER_API_KEY], so the real value never reaches OpenRouter.
It can be tricky to find secrets in a prompt. Let's walk through three ways to find them.
Let's say your app sends this error log to a model:
ERROR: failed to start, config was:
OPENROUTER_API_KEY=sk-or-v1-abc123def456ghi789
SESSION_TOKEN=tok_8f3k2m9x7q4w
JWT_SECRET=s3cr3t-signing-k3y
DB_PASSWORD=Sup3rS3cret!
Secret names often end in KEY, TOKEN, SECRET, or PASSWORD. We can find each name with one of these endings and mask the value after it.
If you already keep your secrets in one place, such as a .env file or a secret manager, mask their values in the prompt.
What if a secret doesn't have a name ending in KEY, TOKEN, SECRET, or PASSWORD?
Another way to find secrets is to look for known key formats. AWS access keys, for example, start with AKIA.
You don't need to write these format rules yourself. Betterleaks already has them for AWS, GitHub, OpenAI, OpenRouter, Anthropic, and other common keys.
Sometimes a URL, such as a database URL, contains a password. The password has no name and no format, but it always sits between user: and @, so a regex can find it.
Keys aren't the only secrets in a prompt. A prompt can also hold a customer's name or the details of an unreleased product. These have no fixed format, so a regex can't find them.
To find them, scan the prompt with a small local model. Since the model is local, the prompt it reads stays on your machine.
There are two kinds of local models for this.
OpenAI Privacy Filter is a small open-weight model that runs on a laptop. It finds personal data and secrets, such as emails, account numbers, and API keys, and replaces each with its label.
Let's say a prompt holds an email and the ship date of an unreleased product called Falcon. OpenAI Privacy Filter replaces the email and the date with its labels.
But "Falcon" stays, because Privacy Filter doesn't know your product names are secret, and you can't add new labels to it. To catch secrets like this, use a model that follows rules you write.
Guard models such as Shieldstral 1.0 3B, Granite Guardian 4.1 8B, and gpt-oss-safeguard-20b read a rule written in plain words, such as "Does this prompt mention our unreleased products, Falcon or Osprey?", and answer yes or no. If the answer is yes, your code blocks the prompt.
It is best to combine masking with a local model. Masking is fast and exact for keys it knows, while the model is slower but can find secrets with no fixed pattern.
Even if you follow all the guards, a key may still leak. To limit the damage, keep the key short-lived and scoped to only the permissions it needs. Dragos saw one stolen key still in use three weeks later.
If a key may have been in a prompt, create a new one and revoke the old one right away. In Dragos's test, attackers tried stolen AWS keys within a few hours.
ZDR decides who gets your prompt. It can't stop someone who has already broken into that provider. OpenRouter's response makes breaches less likely, but breaches can still happen.
So assume any prompt can leak, and remove secrets before they leave your machine.
Here's the checklist to protect your prompts:
[ ] Safety Retention no longer allowed
[ ] Only providers you trust are allowed
[ ] Keys live in .env or a secret manager, not in code
[ ] Mask secrets before the prompt leaves your machine
[ ] Scan prompts with a local model for personal data and trade secrets
[ ] Rotate any key that has ever appeared in a prompt
[ ] New keys are short-lived and scoped
These guards lower the risk, but they can't remove it. Masking and local models can both miss a secret. To keep every secret off someone else's servers, send your prompts only to a model on your own machine or network.
only.zdr flag, and Google's Safety Retention on Vertex.Benchmarks, deep dives, and lessons from OpenTeams engineers. Get the Engineering newsletter once a month, or follow the feed.