API Key Masking
NanoGPT replaces recognisable API keys in your prompts with placeholders before they reach a model provider, and puts the real keys back in the reply. It is on by default, free, and works the same on BYOK requests (the usual BYOK fee is unchanged). Masking is separate from PII redaction, which is opt-in, paid and covers personal information.How It Works
Your request already passes through NanoGPT’s servers on its way to the provider. While it does:- NanoGPT runs a pattern match for known key formats. No AI model or third party is involved.
- Each key it finds is swapped for a placeholder such as
⟦APIKEY_k3x9qabc⟧, which can’t be turned back into the key. The same key keeps the same placeholder for your account, so prompt caching keeps working. - Memory, web search, moderation and the model provider see only the placeholder.
- As the reply comes back, NanoGPT swaps the placeholders for the real keys, including in streamed replies and in tool calls your own client runs.
In the Web App
In the NanoGPT web app, recognised credentials are also replaced in your browser before a request is sent, on chat, titles, memory analysis, multi-model chat, Fusion, and image and video prompts. The keys go back into the reply in your browser too. The link between each placeholder and its key stays in that tab’s memory for your recent conversations, so keys can go back into later replies; the keys aren’t written to the browser’s storage. The server’s pass still runs behind it, and it covers anything the browser missed.Turning It On or Off
Change it for your account under Settings > Privacy & analytics, or for one request with a header:
The request header wins over your account setting, and your account setting wins over the default.
x-nanogpt-api-key-masking: on. It says only that masking ran, not whether a key was found.
What It Covers
POST /v1/chat/completions, including predicted output (prediction) and custom tool inputsPOST /v1/messagesPOST /v1/responses, native or through chatPOST /v1/completions, for string prompts and string arraysPOST /v1/decisions, and Decisions models through chat
.env files and extracted documents, is covered once it’s part of the message. It only recognises known key formats there too.
Plain-text document blocks and inline UTF-8 text files up to 3 MiB, such as code, config or .env files sent as base64, are covered too.
It doesn’t cover images, audio, embeddings or private (TEE) models, or binary files passed to a provider as files, such as URL file parts, PDFs and Office files. Text read from a scanned document is also sent to an OCR provider before masking runs.
On /v1/completions, echo, logprobs, token-ID prompts and batched streaming aren’t covered.
Background Responses API requests and stored Responses API conversations are only masked if you turned masking on yourself, with the header or your account setting. Those results keep their placeholders, because they are fetched after the request’s mapping is gone.
Hosted-tool credentials you deliberately supply, encrypted reasoning, signatures, correlation IDs and data URLs are left unchanged.
Where Keys Stay Masked
Real keys go back into the reply and into tool calls your own client runs, so your tools keep working. These stay as placeholders:- A key inside a URL in the text of a reply, when the URL’s host isn’t one you sent that key to. This stops a reply from turning a key into a link or image that hands it to someone else.
- A key in a link or image address with no host in a reply, such as
or<img src="/x?key=…">. The web app would load that address from NanoGPT, so the key would end up in a request. - Web search, provider-hosted tools and connected tools in the web app.
- Requests using Redact on this device, where API keys aren’t put back.
⟦APIKEY_…⟧, in the same way people write sk-.... There’s no key to put back in that case, so you see the text as the model wrote it.
Other Credential Types
Masking also covers the credential types below. You can turn each one off under Settings > Privacy & analytics, or for one request by listing them, comma-separated, inx-nanogpt-api-key-masking-exclude:
Strict Tool Calls
By default, real keys go back into tool calls your own client runs, so agents can write config files and call APIs. A model that has been tricked can use a key the same way. To restrict this, turn on strict tool calls under Settings > Privacy & analytics, or for one request sendx-nanogpt-api-key-masking-tool-calls: strict.
In strict mode, a credential in a tool call’s arguments goes back only when it sits inside a URL on a host you sent that credential to. Everywhere else it stays a placeholder, including echo KEY > .env or a request header flag, so a tool that needs the real value there will get the placeholder instead. x-nanogpt-api-key-masking-tool-calls: default turns strict mode off for one request.