Skip to content

Credential detector

OpenAI API key: format and detection

Updated Credentialspassword or access keyDetector key openai_api_key

Short answer

OpenAI keys start with sk-. Current ones continue with proj, svcacct or admin, then a long run of letters, digits, underscores and hyphens split in two by the marker T3BlbkFJ. Older ones are sk- plus 20 characters, the marker, and 20 more.

What it is

An OpenAI API key lets whoever holds it call OpenAI models and bill the account. Maskflare's Credentials pack includes a dedicated detector and masks it by default.

In Maskflare this is the detector openai_api_key, labelled "OpenAI API key", category password or access key, in the Credentials pack.

Format

  • Current keys: sk-, then proj, svcacct or admin, a hyphen, a run of 58 or 74 characters from letters, digits, underscore and hyphen, the literal marker T3BlbkFJ, and another run of 58 or 74 characters.
  • Legacy keys: sk-, then 20 letters and digits, T3BlbkFJ, then 20 letters and digits.
  • T3BlbkFJ is the base64 text of the word OpenAI, which is why it makes a useful anchor inside an otherwise random string.

How Maskflare recognises it

There is no check digit. The detector relies on the sk- prefix, the T3BlbkFJ marker, the exact run lengths, and an entropy floor.

The catalogue prefilters on the marker: a text without T3BlbkFJ is not run through the full pattern.

After a match, the secret part must have a Shannon entropy of at least 3.0 bits per character. That rejects keys made of a repeated character or a short repeating run, which are almost always placeholders.

Why this page shows no sample key

A realistic sample key would look like a live credential to secret scanners and to anyone skimming the page, and an obviously fake one would not pass this detector's length and entropy rules. The format above is enough to recognise the key: the prefix, the length and the character set.

Regex and validation caveats

  • The pattern wants the key to be followed by a quote, a backtick, whitespace, a semicolon, an escaped newline or the end of the text. A key directly followed by a comma or a closing bracket is therefore not matched by this pattern.
  • Values that look like template variables (${KEY}, {{ key }}, %KEY%), a single repeated letter, true, false or null, and a few file paths are on the detector's allow list and are not masked. A value containing the run abcdefghijklmnopqrstuvwxyz is also treated as an example.
  • Other providers also begin with sk-. DeepSeek keys, for example, are sk- followed by 32 hex characters, a different detector, so the two do not collide.
  • In docs and tickets, write a placeholder such as sk-proj-<your key> rather than a real or realistic-looking key.

How to detect it in LLM traffic

In LLM traffic the key often arrives inside code: a Python snippet with api_key set to a string, a curl command with an Authorization header, a .env file pasted for debugging, or a notebook cell.

Maskflare reads the whole request body, including the system prompt, earlier messages and tool arguments, and replaces each match with a token such as mf_mask_d7e0 before the request goes out. Coding agents are covered through hooks that mask tool inputs and results, so a key printed by a shell command does not travel onward in the next prompt. On ChatGPT, browser protection blocks prompts that contain API keys, tokens or private keys outright.

If you build the detection yourself

  1. Scan the raw text rather than parsed fields: keys sit in code, JSON strings, headers, shell output and pasted logs, often with no label at all.
  2. Match the prefix and the exact length for the OpenAI API key. Where the key has no fixed prefix, require the provider's name and an assignment next to the value instead of matching any long string.
  3. Compute the Shannon entropy of the candidate and reject low values, and keep an allow list of placeholders (${KEY}, repeated characters, the alphabet run), because documentation and templates are full of them.
  4. Mask the value before the text is sent anywhere. If the key was already sent, treat it as exposed and rotate it; masking later does not recall it.

How Maskflare handles it

  • Protect now, Finance - Protect now, Healthcare, Developer and Monitor first: mask (a reversible token).

The available actions are mask (reversible token), redact, partial, hash, format-preserving encryption, generalize, alert and block. Masked values are kept encrypted for 30 days so that answers can be restored, then they expire; prompts and responses are not logged. The full list of detectors is in the detector reference.

Compliance profiles that include it

All 6 compliance profiles include the Credentials pack, and applying them turns this detector on: HIPAA Safe Harbor, GDPR - EU/EEA, UK GDPR, PCI DSS, US personal data and Switzerland - nDSG health data. A profile is a floor: it never turns anything off or weakens a rule that is already stricter.

Frequently asked questions

What does T3BlbkFJ mean in an OpenAI key?

It is the base64 encoding of the word OpenAI. Maskflare uses it as an anchor because it appears in the middle of both the current and the legacy key formats.

Does Maskflare detect project and service-account keys?

Yes. The pattern covers sk-proj, sk-svcacct and sk-admin keys as well as the legacy format.

Is a key in a prompt masked or blocked?

Masked by default in every starter template. On ChatGPT, browser protection blocks prompts that contain API keys, tokens or private keys outright.

Is the OpenAI API key detector on by default?

Yes. It belongs to the Credentials pack, which the default Protect now template turns on with the action mask.

Does Maskflare store the keys it masks?

Prompts and responses are not logged. A masked value is kept encrypted for 30 days so the answer can be restored, then it expires.

Rules on this page describe what Maskflare's detectors and validators check. They are read from the detection catalogue and are not the specification of the body that issues the identifier. No sample key is shown on purpose.

Related pages

See it on your own data

Try Maskflare free.
Bring your hardest prompts.

28-day free trial or 10,000 requests, whichever comes first. Point one app at the gateway or enroll a few laptops,
and watch what gets masked. Or talk to us first.