Skip to content

Control what the AI Gateway stores

Know where the content of a Gateway request can persist, for how long, and which switch removes it. This page lists every store, shows how to turn off message capture and response caching, and states what the Gateway does with each provider’s retention settings.

Two terms appear throughout:

  • A built-in provider uses a credential that Pydantic owns and shares across organizations. A custom provider uses your own provider account. See Add your own provider.
  • Zero data retention (ZDR) means the model provider does not keep your prompts or responses after it answers the request.

What the Gateway stores

The Gateway holds request and response bodies in memory while it proxies them. It does not write them to disk. These are the places where data persists after the request ends.

DataContains prompts or responsesWhereHow longHow to turn it off
Request spans: model, token counts, cost, status, timing, URL, request and response headersNo. The URL, baggage, and every header except the credential headers are recorded as you sent them.Your Logfire projectYour organization’s retention period. The default is 30 days.No setting turns it off. See Request spans have no off switch.
Message content on those spans: prompts, responses, system instructions, stop sequences, and raw HTTP bodiesYesYour Logfire projectYour organization’s retention periodTurn off Include messages for the project. It is on by default.
Response cache entriesYes. The entry holds the response body. The request is only hashed into the cache key.The Gateway’s cache24 hoursOff by default. You turn it on for each API key. Send Cache-Control: no-store to skip it for one request.
Spend totals for each key, member, project, and organizationNo. Amounts in US dollars only.The Gateway’s databaseNo fixed expiryYou cannot turn it off. Spending limits need it.
Built-in provider usage: cost and request count for each keyNoThe Gateway’s databaseHourly rows for three months. Monthly totals have no fixed expiry.You cannot turn it off. Billing needs it.
Provider block events: key ID, provider type, and a fixed reason codeNoThe Gateway’s databaseUntil you delete the API keyYou cannot turn it off.
Routing metrics: request, error, and latency counts for each provider, route, and model, in one-minute bucketsNoThe Gateway’s database90 daysYou cannot turn it off. Gateway endpoints need it to route around a failing provider.

A span is one unit of work, with a name, a start, and a duration. The Gateway records one span for each attempt to reach a provider.

The Gateway does not store the raw payload for these features:

  • Files and batches. The Gateway refuses these endpoints on a built-in provider, because the files of every organization would share one provider account. On a custom provider, the Gateway forwards the request unchanged, and the file or batch lives only in your provider account. The provider’s retention rules apply.
  • Realtime sessions. The Gateway relays audio and text frames and reads token usage from them. It records usage and cost. It does not record frames or transcripts.
  • Audio uploads. A span for a transcription request records the file name and size, not the audio. The transcript text counts as message content.
  • Guardrail matches. Guardrails record which protection ran, its action, and the number of matches. They do not record the matched text.

Request spans have no off switch

The Gateway writes its spans to the project that owns the API key. No setting stops that export, because usage, cost, and spending limits are only auditable when every request leaves a record. Include messages decides whether those spans also carry content.

There is one exception. The Gateway honors the sampling decision in a traceparent header. If your app marks its trace as not sampled, the Gateway exports no span for that request.

Your organization’s retention period decides how long the spans live. The default is 30 days. Growth organizations can set up to 90 days, and Enterprise organizations can set a longer period.

Turn off message capture

Message capture is a project setting. It is on by default, so a new project shows you the prompts and responses behind each cost without extra setup.

You need permission to change project settings.

  1. Open AI Engineering → Gateway and select the Settings tab.
  2. In the Telemetry card, select the project.
  3. Turn off Include messages.

The setting applies to every API key in that project. It can take up to 60 seconds to reach requests in flight.

With Include messages off, the Gateway removes these attributes from each span before it exports the span:

RemovedKept
gen_ai.input.messagesModel, token counts, cost, status, and timing
gen_ai.output.messagesRequest and response headers, except credentials
gen_ai.system_instructionsurl.full
gen_ai.request.stop_sequencesBaggage entries under other keys
http.request.body.text and http.response.body.texthttp.request.body.size
The text of error and error.messageGuardrail and optimization metadata

Check that capture is off

Send a request with a key from that project, then run this query in the project’s Explore view:

SELECT
    start_timestamp,
    span_name,
    attributes->>'gen_ai.input.messages' AS input_messages
FROM records
WHERE otel_scope_name = 'pydantic-ai-gateway'
ORDER BY start_timestamp DESC
LIMIT 5

The newest rows have an empty input_messages column.

Turn off response caching

The response cache answers a repeated, identical, non-streaming request from a stored copy of the first response. It is off by default, because a cache entry is a copy of a model response that outlives the request. You opt in for each API key.

The cache has these limits:

PropertyValue
ScopeOne API key. A key never reads the entry of another key.
RequestsChat Completions, Responses, and Anthropic Messages. Non-streaming only.
StoredThe response body of a successful response, up to 256 KiB. The request body is hashed, not stored.
Lifetime24 hours. Entries expire. You cannot purge them earlier.

For an API key

  1. Open AI Engineering → Gateway and select the API Keys tab.
  2. Open the key and edit it.
  3. Set Response caching to Disabled.

Default also means off today. Choose Disabled when the key must stay uncached even if the default changes.

The Gateway stops reading and writing the cache for that key. Entries that the key already stored are no longer served, and they expire within 24 hours.

For one request

Send Cache-Control: no-store. The Gateway neither reads nor writes the cache for that request, even when the key has caching on.

from openai import OpenAI

client = OpenAI(
    api_key='<YOUR_GATEWAY_API_KEY>',
    base_url='https://gateway-us.pydantic.dev/proxy/openai',
)

response = client.chat.completions.with_raw_response.create(
    model='gpt-5.2',
    messages=[{'role': 'user', 'content': 'Say only hi'}],
    extra_headers={'Cache-Control': 'no-store'},
)

print(response.headers.get('x-cache-status'))
#> BYPASS
print(response.parse().choices[0].message.content)
#> hi

Copy the API key and the base URL for your region from Gateway → Connect. This output is for a key with Response caching set to Enabled. For any other key the header is absent and the first line prints None.

The X-Cache-Status response header reports what the cache did:

ValueMeaning
HITThe Gateway answered from the cache. The provider did not receive the request.
MISSThe Gateway called the provider and stored the response.
BYPASSThe Gateway called the provider and did not read the cache.
Header absentCaching is off for the key, or the request is not cacheable.

Cache-Control: no-cache skips the read but still stores the new response. Use no-store when the response must not persist.

Provider zero data retention

The settings above control what the Gateway stores. They do not control what the model provider stores. Two things decide that: the retention terms of the provider account, and the retention fields in your request.

Provider kindWhose accountWho sets the retention terms
Custom providerYoursYou, in your agreement with the provider. The Gateway does not change it.
Built-in providerPydantic’sPydantic. A built-in provider is ZDR only after Pydantic confirms it for that provider account.

Pydantic has confirmed these built-in providers as ZDR:

Built-in providerZDR
DoublewordYes
Google Vertex AIYes
GroqYes
Every other built-in providerNot confirmed

You can use the ZDR built-in providers on every plan. Send your request to a route whose only built-in providers are ZDR. A Gateway endpoint that also includes another built-in provider can share traffic with it or fail over to it, so that route does not guarantee ZDR.

Two controls depend on your plan:

ControlPlan
The ZDR badge on a built-in provider, on the Providers tabGrowth, Enterprise, or self-hosted Logfire
The organization setting that keeps every request away from the other built-in providersEnterprise Cloud or self-hosted Logfire

Both are experimental, and you turn them on with the same Early Access option as the requirement below.

How request fields pass through

The Gateway sends your request body to the provider with only the changes listed below. On a custom provider, it never adds, removes, or changes a retention field. If you leave a field out, the provider applies its own default. On a built-in OpenAI or Azure OpenAI provider, it turns off response storage.

ProviderForwarded unchangedChanged by the Gateway
OpenAI, Azure OpenAImetadata, prompt_cache_key, prompt_cache_retention, user. On a custom provider, also store and previous_response_id.safety_identifier: the Gateway puts an identifier for your organization in front of your value. Streaming Chat Completions: the Gateway sets stream_options.include_usage to true. Built-in providers only: the Gateway sets store to false.
Anthropiccache_control, the anthropic-beta and anthropic-version headers, other metadata keysmetadata.user_id: the Gateway puts an identifier for your organization in front of your value.
Google Vertex AI, Google AI StudioThe whole generateContent body, including cachedContentNothing
AWS BedrockThe whole Converse bodyNothing
Groq, and custom OpenAI-compatible or Anthropic-compatible providersThe whole bodyNothing
MistralThe whole bodyStreaming chat: the Gateway sets stream_options.include_usage to true.

The Gateway changes safety_identifier and metadata.user_id because those are the fields that providers use to attribute abuse. On a shared built-in credential, the organization identifier lets the provider act on one organization and not on every organization that uses the credential. The identifier is derived from your organization ID. It contains no prompt content.

The Gateway forces include_usage on streams because it reads token usage from the stream to record cost and enforce spending limits.

The Gateway forwards your request headers, except these:

Not forwardedWhy
Authorization, X-API-Key, X-Goog-Api-KeyThey hold your Gateway API key. The Gateway attaches the provider credential in their place.
Cookie, Origin, Referer, Forwarded, Via, X-Real-IP, and headers that start with X-Forwarded-They identify the caller. No provider needs them.
baggage, and headers that start with X-Pydantic-, X-Gateway-, or X-Routing-They address the Gateway.

The Gateway appends its own name to User-Agent.

Built-in OpenAI providers never store a response

The OpenAI Responses API stores each response in the provider account unless the request says otherwise. A built-in provider account is shared across organizations, so a stored response there could be named by a request from another organization.

On a built-in OpenAI or Azure OpenAI provider, the Gateway sets store to false on every Responses and Chat Completions request. A store=True in your request has no effect. The Gateway also refuses, with a 400 that names the field, a request that refers to an object the provider account stores:

Refused on a built-in providerWhy
previous_response_id, conversationThey name a stored response or conversation.
An input item that refers to a stored item by id, such as an item_referenceThe provider loads the stored item into the model’s context.
A container ID on a tool or an input itemThe container belongs to the shared account. container: {"type": "auto"} still works.
A Chat Completions message with audio.idIt names stored audio.

To continue a conversation on a built-in provider, send the full message history in each request. To use stored responses, add your own provider.

Ask OpenAI not to store a response on a custom provider

On a custom provider, the Gateway forwards store as you sent it. Set store=False to keep the response out of your provider account:

from openai import OpenAI

client = OpenAI(
    api_key='<YOUR_GATEWAY_API_KEY>',
    base_url='https://gateway-us.pydantic.dev/proxy/openai',
)

response = client.responses.create(
    model='gpt-5.2',
    input='Say only hi',
    store=False,
)

print(response.output_text)
#> hi

Require zero data retention for built-in providers

Among built-in providers, a request that requires ZDR can only reach one that Pydantic confirmed as ZDR. Custom providers are not affected, because their retention terms are yours.

Send the x-pydantic-zero-data-retention header to require ZDR for one request or one client:

from openai import OpenAI

client = OpenAI(
    api_key='<YOUR_GATEWAY_API_KEY>',
    base_url='https://gateway-us.pydantic.dev/proxy/openai',
    default_headers={'x-pydantic-zero-data-retention': 'true'},
)

response = client.chat.completions.create(
    model='gpt-5.2',
    messages=[{'role': 'user', 'content': 'Say only hi'}],
)

print(response.choices[0].message.content)
#> hi

To require ZDR for every request in the organization, open Gateway → Settings, find the Zero data retention card, and turn on Require for the whole organization.

These rules apply:

CaseResult
The route has a ZDR built-in provider or a custom providerThe request goes to that provider.
Every provider of the route is a built-in provider that is not ZDR403 with error_code: zero_data_retention_required. The provider receives nothing.
The header value is not true or false400 with error_code: zero_data_retention_header_invalid. A typo never sends data to a provider that retains it.
The organization requires ZDR and the header is falseZDR is still required. The header can add the requirement. It cannot remove it.

The Gateway removes the header before it forwards the request. Realtime sessions follow the same rules.

Troubleshooting

  • A span still shows prompts after you turned off Include messages. The span is older than the change, or the request used a key from another project. The setting is per project. Check the Telemetry card for the project that owns the key.
  • X-Cache-Status is HIT on a request that must not be cached. The key has Response caching set to Enabled. Send Cache-Control: no-store on that request, or set the key to Disabled.
  • A request returns 403 with zero_data_retention_required. No provider of that route is confirmed as ZDR. Use a route with a custom provider, or remove the requirement.
  • A request to a files or batches endpoint returns 404. The route uses a built-in provider. Add your own provider and send the request through it.

Next steps