Redacting credentials before code and logs reach a model

APIFreeKeyOpenAI · Updated 2026-11-24 · 8 min read

Printed pages with lines covered by black tape on a clipboard
Redact before the text leaves your machine.

Every day developers paste config files, logs and code snippets into AI assistants without a second look. Somewhere in that text there is often a database connection string, a cloud access key or a bearer token. Once it is sent to a third-party service, you cannot pull it back. A growing number of people worry about exactly this, and some have started building browser extensions just to scan text before it leaves the clipboard.

This article is for developers who use chat assistants, coding agents or LLM APIs in their daily work. It explains where secrets usually hide, how to strip them automatically before a request is sent, what to do when one slips through, and how to think about what any AI service can see about you, including the free endpoint on this site.

The advice is provider-neutral. This site is not affiliated with OpenAI or any other model vendor, and the redaction code works in front of any OpenAI-compatible client.

Frequently asked questions

What counts as a secret in a prompt?

Anything that grants access or identifies a person: API keys, passwords, tokens, private keys, connection strings with credentials, session cookies, signed URLs, and personal data such as emails, phone numbers or addresses. Internal hostnames and account IDs are lower risk but still worth removing.

How does a secret scanner differ from a redactor?

A scanner detects suspicious strings and warns you or blocks the action. A redactor replaces them with placeholders and lets the request proceed. Scanners are good as a final gate; redactors are better inside automated pipelines that must keep running.

Which is better: regex rules or entropy detection?

Regex rules catch known formats precisely, such as cloud key prefixes or connection strings, with few false alarms. Entropy checks catch unknown random-looking tokens but flag hashes and IDs too. Most effective tools combine a curated rule set with a modest entropy threshold.

Does an AI provider store what I send?

It depends on the provider and the product, and policies differ between consumer apps and APIs. Read the provider's current data and privacy pages. As a rule of thumb, assume anything you send may be logged somewhere and plan accordingly.

What does the free endpoint here log?

Each request produces a technical record with time, IP, User-Agent, country, endpoint, status, latency, sizes and token counts. Conversations are not kept between calls since the API is stateless. That is still a third party, so the same redaction rules apply.

What should I do if I pasted a real key?

Rotate it immediately at the issuer, then check the issuer's logs for unexpected use. Deleting the chat or message does not undo the exposure. Rotation is fast and removes doubt; investigation can follow.

Are keyless APIs safer from this problem?

They remove one category of secret, the API key for the model itself, from your code and config. They do nothing about secrets inside the text you send. Redaction is still your job.

Can mobile AI apps see more than the text I type?

Apps can request device permissions and make integrity or analytics calls, and privacy-focused users sometimes notice more background traffic than expected. Review app permissions in your operating system and prefer the web or API when you want tighter control.

Where secrets hide in everyday prompts

Most leaks are not someone pasting a key on purpose. They happen when a whole file goes into a prompt because it was faster than picking the relevant lines. Environment files, YAML configs, Docker compose files, CI definitions and Terraform state are frequent culprits.

Logs and stack traces are the second big source. Error messages often include the full request that failed, complete with authorization headers, or a connection URL with username and password embedded. Debugging with an AI assistant is exactly when you are most likely to paste those.

Connection strings

Database URLs in the form scheme, user, password, host are easy to overlook because they look like ordinary addresses. Treat any URL containing an at sign before the host as suspect.

Headers in logs

HTTP clients in debug mode print request headers. A single verbose log line can contain a bearer token that grants full access to an account.

Redact before the request leaves your machine

The most reliable fix is to put a redaction step in front of every model call your own code makes. It runs automatically, so it does not depend on anyone remembering. Replace each match with a typed placeholder such as [REDACTED_AWS_KEY] so the model still understands the structure of the text.

The code below wraps a chat call with a small set of patterns. Extend the list with formats your organization uses. It works against any OpenAI-compatible endpoint, including the keyless one at https://api.apifreekeyopenai.com/v1.

Keep placeholders typed

A generic marker loses information. A typed one tells the model that a value was a connection string or a token, which is often all it needs to help debug.

Test the redactor itself

A redactor that silently stops matching after a refactor is worse than none, because people trust it. Keep a small test file with fake but realistic secrets in every supported format, and run it in CI. If a pattern stops catching its sample, the build fails before anyone sends a real credential through the broken filter.

import re
from openai import OpenAI

PATTERNS = [
    ("AWS_KEY", re.compile(r"\bAKIA[0-9A-Z]{16}\b")),
    ("PRIVATE_KEY", re.compile(r"-----BEGIN [A-Z ]*PRIVATE KEY-----[\s\S]+?-----END [A-Z ]*PRIVATE KEY-----")),
    ("BEARER", re.compile(r"(?i)bearer\s+[a-z0-9._\-]{20,}")),
    ("URL_CREDS", re.compile(r"(?i)([a-z][a-z0-9+.\-]*://)[^\s:/@]+:[^\s@]+@")),
    ("GENERIC_KEY", re.compile(r"\bsk-[A-Za-z0-9_\-]{20,}\b")),
    ("EMAIL", re.compile(r"\b[\w.+-]+@[\w-]+\.[\w.]+\b")),
]

def redact(text: str) -> tuple[str, int]:
    hits = 0
    for name, rx in PATTERNS:
        repl = (lambda m: m.group(1) + "[REDACTED]@") if name == "URL_CREDS" else f"[REDACTED_{name}]"
        text, n = rx.subn(repl, text)
        hits += n
    return text, hits

client = OpenAI(base_url="https://api.apifreekeyopenai.com/v1", api_key="not-needed")

def safe_ask(text: str) -> str:
    clean, hits = redact(text)
    if hits:
        print(f"redacted {hits} item(s) before sending")
    r = client.chat.completions.create(
        model="free-ai",
        messages=[{"role": "user", "content": clean}],
        max_tokens=400,
    )
    return r.choices[0].message.content

print(safe_ask("Why does this fail? postgres://app:[email protected]:5432/main"))
A sieve catching small keys while sand falls through
A redactor filters out the dangerous parts and lets the rest through.

Scanners as a last line of defense

For text that you paste by hand into chat interfaces, a scanner that checks the clipboard or the input box is a useful safety net. Browser extensions and editor plugins in this category look for known key formats and warn before you submit.

Repository scanners that run in pre-commit hooks and CI serve the same purpose for code. They catch secrets before they land in version control, which is upstream of most prompt leaks since many prompts are built from files in the repo.

False positives

Scanners that cry wolf get disabled. Tune them so that the common case, such as test fixtures and example values, is explicitly allowed rather than turning detection off.

  • Use a pre-commit secret scanner in every repository.
  • Enable push protection features your code host offers.
  • Install a paste-time warning tool in the browser you use for AI chats.
  • Review scanner exceptions periodically so they do not grow into blind spots.

Agents and coding assistants read more than you think

A coding agent with file access does not wait for you to paste. It reads whatever files look relevant to the task, and those reads may end up in the prompt. If your project directory contains a credentials file, assume the agent can see it.

Restrict what agents can open. Many tools support ignore files or allowed-path lists; use them for environment files and secret stores. Better still, keep production secrets out of development machines entirely and use short-lived, scoped credentials for local work. If you run agents on a server, the same thinking applies, as covered in subscription sign-in vs API keys for agents.

Ignore files

Add environment files, key directories and local databases to the agent's ignore list. It is a one-time change that prevents a whole class of accidental reads.

Scoped tokens for local work

A token that can only read one test database is far less dangerous to leak than a full admin credential. Issue narrow tokens for development.

A robot vacuum approaching an open office drawer
Agents explore files on their own, so lock the drawers that matter.

What to do after a slip

When a secret has been sent to any third party, treat it as compromised. Rotate it at the issuer first, because that closes the window regardless of what the third party does. Then look at the issuer's audit logs for any use you do not recognize.

Deleting the conversation is fine for hygiene but does not count as remediation. You cannot verify what was logged or cached on the other side. Write down what happened and add a rule to your redactor or scanner so the same format is caught next time.

Rotation drill

Practice rotating your most important keys before an incident. If rotation requires a deploy and a long checklist, simplify it now, while nothing is on fire.

Tell your team without blame

People hide mistakes they expect to be punished for. Make it normal to report a leaked credential immediately, and treat the report as the good outcome it is. A key rotated within minutes of a slip is a non-event; a key that stays exposed for weeks because someone was embarrassed is a real incident with real cleanup work.

What any AI service can see about you

Beyond prompt content, every API call carries metadata: your IP address, a User-Agent string, timing and size. A service can link requests by these even without an account. The free endpoint here records exactly that set of technical fields per request, plus the endpoint, status, latency and token counts, and keeps no conversation between calls.

Mobile and desktop apps can collect more, depending on permissions. Privacy-conscious users who monitor network traffic sometimes notice frequent integrity checks and analytics requests from AI apps. If that bothers you, the API with your own client gives you more control over what leaves your device.

Read the provider's policy

Retention periods, training use and opt-outs vary by provider and by product. For OpenAI, the official privacy and data usage pages on openai.com/policies are the place to check, not secondhand summaries.

An old lock taken apart beside a new lock and keys
After a slip, change the lock first and investigate second.

Personal data needs the same care

Secrets are not only keys. Customer names, emails, addresses and support tickets are just as sensitive, and in many jurisdictions sending them to a processor without an agreement creates legal obligations. The same redaction approach works: detect, replace with typed placeholders, and keep a mapping locally if you need to restore values in the answer.

For document-heavy features, consider extracting only the fields the model needs instead of sending whole files. Our guide on adding document analysis to a web app shows how to keep documents small and focused.

Reversible placeholders

Replace each email with a token like PERSON_1 and store the mapping on your side. After the model answers, swap the tokens back. The model never sees the real values.

A short policy you can adopt today

Teams do not need a long document to get most of the benefit. A few clear rules, written where everyone will see them, prevent most incidents.

Make it easy to comply

Ship the redactor as a shared library and the ignore list as a template. Rules that require extra effort get skipped under deadline pressure.

  • Never paste whole config or environment files into an AI tool.
  • Run every programmatic prompt through a redactor.
  • Keep agents away from secret files with ignore lists.
  • Rotate any credential that reached a third party, immediately.
  • Prefer synthetic or anonymized data for experiments.
A corkboard with three pinned index cards
A few clear rules prevent most leaks.
Try the free API

Send a prompt to the keyless free-ai endpoint from the home page and see a reply in seconds, no sign-up needed.

Read also