Zero data retention and training policies
Providers differ in what they do with the prompts and completions you send them. Some keep nothing, some keep data for a limited abuse-monitoring window, and some keep it longer or use it to train models. Data policy routing lets you record those terms on every deployment and then require zero data retention (ZDR) or forbid training for a request, a key, a team or a whole organization. The router drops every deployment that does not meet the policy before the routing strategy runs, and it refuses the request with a 400 that names the policy when nothing qualifies.
The gateway enforces the terms you declare. It does not read or verify your provider contracts, so declare data_retention: none only for deployments covered by a zero data retention agreement with that provider account.
A real-world scenario
A health company summarizes clinical notes with gpt-5.6, which the gateway serves from an Azure resource covered by a zero data retention agreement and from the standard OpenAI API. Patient data may only go to the Azure deployment. The admin records each deployment's terms, then gives the clinical notes key a policy that requires zero data retention and forbids training. Requests on that key now only ever reach the Azure deployment, and if that deployment is removed the gateway refuses the request instead of quietly sending patient data elsewhere.
Step by step
-
In the Admin UI open Models + Endpoints, pick the Azure deployment of
gpt-5.6, edit it and set the Data policy fields to retentionnoneand trainingfalse. Set the OpenAI deployment to its real terms, for example retentionlimited. The same fields can be declared inconfig.yaml, as shown in Declare deployment terms. -
Create the key with the policy:
curl -X POST http://localhost:4000/key/generate \-H "Authorization: Bearer $SPANWAY_MASTER_KEY" -H "Content-Type: application/json" \-d '{"key_alias": "clinical-notes", "data_policy": {"require_zdr": true, "forbid_training": true}}'To change it later, open the key on Virtual Keys, edit it and use the switches under Data policy.
-
Send a request with the new key and read the
x-spanway-model-idresponse header:curl -s -D - -o /dev/null http://localhost:4000/v1/chat/completions \-H "Authorization: Bearer $SPANWAY_CLINICAL_KEY" -H "Content-Type: application/json" \-d '{"model": "gpt-5.6", "messages": [{"role": "user", "content": "Summarize this visit note"}]}' | grep -i x-spanway-model-id
Expected result
Every request on the clinical notes key is served by the Azure deployment, and x-spanway-model-id names it. When no deployment meets the policy, the request is refused with a 400 that names the requirement and why each deployment was rejected, as shown in When nothing qualifies. Keys without a policy keep using every deployment of the group.
Declare deployment terms
Add the terms to model_info on each deployment.
model_list:
- model_name: gpt-5.6
spanway_params:
model: azure/gpt-5.6
api_base: https://my-eu-resource.openai.azure.com
api_key: os.environ/AZURE_API_KEY
model_info:
data_retention: none
trains_on_data: false
data_region: eu
data_policy_note: "Covered by the ZDR amendment signed 2026-03, abuse monitoring disabled"
- model_name: gpt-5.6
spanway_params:
model: openai/gpt-5.6
api_key: os.environ/OPENAI_API_KEY
model_info:
data_retention: limited
trains_on_data: false
data_region: us
| Field | Values | Meaning |
|---|---|---|
data_retention | none, limited or standard | none means the provider keeps no request data. limited means it keeps data for a short, bounded window such as abuse monitoring. standard means its default retention applies. |
trains_on_data | true or false | Whether the provider may use request data to train or improve models. |
data_region | text, for example eu, uk or eu-west-1 | Where the provider processes the data. When it is unset, the region is worked out from the deployment as Regions describes. It decides whether the deployment can serve a request held to allowed_regions or an end user's allowed_model_region, and a deployment with no region never qualifies. |
data_policy_note | text, up to 2000 characters | A free-form note for auditors, such as the agreement that covers the deployment. |
self_hosted | true or false | The deployment runs on infrastructure you control, such as a vLLM or Ollama server in your own network. It only matters for the code traffic rule. |
azure_deployment_type | regional, data_zone or global | The Azure deployment type, which decides whether an Azure resource location counts as the deployment's region. See Regions. |
In the Admin UI, open Models + Endpoints, pick a model and edit it. The Data policy fields sit in the model edit form, and the same fields appear when you add a model. Azure deployment type is among them, with a tooltip and a note that an Azure deployment without it never serves region-held traffic. Only a proxy admin can change these fields, and for anyone else they are disabled with a note saying so.
A deployment that leaves data_retention or trains_on_data unset counts as undeclared. Undeclared terms never satisfy a requirement, so an undeclared deployment is excluded whenever a policy asks for ZDR or no training, unless curated terms are turned on as described below. trains_on_data must be a real boolean, so "no" or 0 are not read as false.
Curated provider terms
Declaring terms on every deployment is work, so the gateway ships curated terms for some providers and models, for example that Anthropic does not train on API data. They are off by default. With router_settings.use_curated_data_terms: true, a deployment that declares nothing uses the curated value for that term when data policies filter deployments. A value a proxy admin declared always wins over the curated one, and a deployment with its own api_base never inherits curated terms, because the gateway cannot know which service is behind that address. Curated terms are what the provider published when the list was made, not something the gateway checks, so declare the terms yourself when a policy matters. The compliance report applies the same rule. See provider preferences for the list and its source.
A config.yaml deployment that sets a value outside the table above still loads, with a warning in the proxy log, and that term counts as undeclared. The other deployments are not affected. /model/new and the model update endpoints reject such a value with a 422 instead.
Only a proxy admin can declare or change a deployment's data terms. A team admin who adds or edits a team model may keep the terms it already has, but sending a different data_retention, trains_on_data, data_region, data_policy_note, self_hosted or azure_deployment_type gets a 403. Otherwise a team admin could mark their own deployment as ZDR and get around a policy only a proxy admin may set.
Policies on keys, teams and organizations
Set data_policy on a key, team or organization. Every switch defaults to false, and allowed_regions defaults to unset, which allows every region.
| Field | Effect |
|---|---|
require_zdr | Only deployments with data_retention: none may serve the requests. |
forbid_training | Only deployments with trains_on_data: false may serve the requests. |
restrict_code_traffic | Requests identified as code traffic may only go to deployments with data_retention: none or self_hosted: true. See Code traffic. |
scan_content_for_code | Also treat a request as code traffic when its messages contain code. Needs restrict_code_traffic, and a policy that sets it alone is rejected. |
allowed_regions | A list of regions, for example ["eu"] or ["eu-central-1", "eu-west-1"]. Only deployments in one of them may serve the requests. See Regions. Leave it out to allow every region, an empty list is rejected. |
curl -X POST http://localhost:4000/key/generate \
-H "Authorization: Bearer $SPANWAY_MASTER_KEY" \
-H "Content-Type: application/json" \
-d '{"key_alias": "clinical-notes", "data_policy": {"require_zdr": true, "forbid_training": true}}'
curl -X POST http://localhost:4000/team/update \
-H "Authorization: Bearer $SPANWAY_MASTER_KEY" \
-H "Content-Type: application/json" \
-d '{"team_id": "team-research", "data_policy": {"forbid_training": true}}'
curl -X PATCH http://localhost:4000/organization/update \
-H "Authorization: Bearer $SPANWAY_MASTER_KEY" \
-H "Content-Type: application/json" \
-d '{"organization_id": "org-health", "data_policy": {"require_zdr": true}}'
The policy is stored in the entity's metadata.data_policy, so it also accepts /key/update, /team/new, /organization/new and writes that send it inside metadata. A policy you send replaces the stored one as a whole, and fields you leave out fall back to false. Send "data_policy": null to clear it. Only a proxy admin can set, change or clear it. A team admin or organization admin who sends a different policy gets a 403, while edits that leave the stored policy as it is still go through. In the Admin UI the switches are under Data policy on the key edit form, in the team Settings tab and on the organization edit form.
Regions
A region in allowed_regions, an end user's allowed_model_region or required_model_region is either a family or an exact provider region. The families are eu (EU member states), uk, ch (Switzerland), us, ca and apac. A family admits the provider regions inside it, for example eu admits eu-west-1, europe-west4, westeurope and eu-de, while uk admits eu-west-2, europe-west2, uksouth and eu-gb, and ch admits eu-central-2, europe-west6 and switzerlandnorth. London and Zurich therefore never satisfy eu. A provider region outside every family, such as norwayeast or me-central-1, only satisfies a policy that names it exactly. An exact region admits only itself, so ["eu-central-1"] keeps requests in Frankfurt.
A deployment's region is the first of these that is set.
model_info.data_region, which always wins.- For Bedrock, the cross-region inference profile in the model id, with or without the
bedrock/prefix.eu.anthropic...is ineuandus.anthropic...inus, whateveraws_region_namesays, and aglobal.profile is inglobal, which no family admits. An application inference profile ARN has no region the gateway can see, so setdata_regionon it. spanway_params.region_name, thenaws_region_name,vertex_locationorwatsonx_region_name. For Azure this only counts as described below.- For Vertex AI, the gateway-wide
vertex_location, then theVERTEXAI_LOCATIONorVERTEX_LOCATIONenvironment variable, the same location the request is sent to. The environment lookup only happens when a region-held request reaches a Vertex AI deployment without its own location, and a location it finds is kept for the life of the process, so restart the proxy after changing it. A lookup that finds nothing is tried again on the next such request.
Azure Global Standard and Global Provisioned deployments can process a prompt in any Azure region, whatever the resource location. So for an azure/, azure_ai/, azure_text/ or azure_speech/ deployment without data_region, the resource location only counts when model_info.azure_deployment_type says the deployment type keeps prompts there.
azure_deployment_type | Region used for the policy |
|---|---|
regional (Standard, Provisioned) | The resource location, so swedencentral satisfies eu and ["swedencentral"]. |
data_zone (Data Zone Standard, Data Zone Provisioned) | The data zone of the resource location, eu or us. A Data Zone EU deployment in swedencentral satisfies eu but not ["swedencentral"], and a resource outside those two zones satisfies nothing. |
global (Global Standard, Global Provisioned, Global Batch) | global, which no family admits. |
| unset | None, so the deployment never serves region-held traffic. |
Azure deployments without a declared type fail closed, so set the field on every Azure deployment that serves a key, team or end user held to a region. An explicit data_region still wins over the deployment type. Only a proxy admin can set azure_deployment_type, like the other data terms.
model_list:
- model_name: gpt-5.6
spanway_params:
model: azure/gpt-5.6
api_base: https://my-eu-resource.openai.azure.com
api_key: os.environ/AZURE_API_KEY
region_name: swedencentral
model_info:
azure_deployment_type: data_zone
The key, team and organization lists, the end user's region and an enforced required_model_region are separate layers, and a deployment must be inside every one of them. A team on ["eu"] with a key on ["eu-central-1"] keeps the key in Frankfurt. Layers that never overlap, such as a team on ["us"] and a key on ["eu"], can never be satisfied, so every request from that key fails with a 400 that names both layers.
curl -X POST http://localhost:4000/team/update \
-H "Authorization: Bearer $SPANWAY_MASTER_KEY" \
-H "Content-Type: application/json" \
-d '{"team_id": "team-eu", "data_policy": {"allowed_regions": ["eu"]}}'
Per request
On /v1/chat/completions, /v1/responses and /v1/messages, a caller can add the same flags to the provider object.
curl -X POST http://localhost:4000/v1/chat/completions \
-H "Authorization: Bearer $SPANWAY_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-5.6",
"messages": [{"role": "user", "content": "Summarize this chart"}],
"provider": {"zdr": true, "data_collection": "deny"}
}'
zdr: true requires zero data retention and data_collection: "deny" forbids training. data_collection: "allow" and zdr: false add no requirement. Key and team provider_preferences defaults can carry the same two flags.
How policies combine
Every source adds requirements and none can remove one. The organization, team and key policies and the request flags are combined, and a deployment must meet every requirement any of them sets. A request can only make the policy stricter. A client that sends its own data_policy field has it removed before routing, and the gateway attaches the stored policies instead.
The filter runs for every router call type (chat, responses, messages, embeddings, images, audio and the rest), whether or not enable_pre_call_checks is on, for a deployment pinned by name, and again for each fallback model group, so a fallback never routes around the policy.
When nothing qualifies
The request fails with a 400 that names each requirement, where it came from and why each deployment was rejected.
No deployment of model 'gpt-5.6' satisfies the data policy: zero data retention (required by organization policy, provider.zdr). Rejected deployments: openai (id 3f2a...): data_retention=limited; groq (id 9c1d...): data_retention=undeclared
While a policy applies, the gateway also refuses requests it would send to a provider without a configured deployment, since there are no declared terms to check. That covers client-supplied api_key, api_base or user_config, pass_through_all_models, model-less video and eval calls that go straight to the provider, assistants and threads, container calls that name no model, Interactions calls that name only an agent, and the provider pass-through endpoints such as /openai/..., /anthropic/..., /milvus/... and /vertex_ai/discovery/.... A pass-through request that names a model group of the router is filtered like any other router call, and when no deployment of that group qualifies it is refused instead of being sent to the provider directly.
The files, batches and fine-tuning endpoints follow the same rule.
| Request | What happens while a policy applies |
|---|---|
POST /v1/files or POST /v1/batches that names a model, or a batch on a file whose id carries a model | The deployment behind that model is checked, and the request is refused when its terms do not meet the policy |
POST /v1/files, POST /v1/batches or POST /v1/fine_tuning/jobs that only names a provider (custom_llm_provider) | Refused |
| Managed files, managed batches and fine-tuning jobs on a managed file | Routed through the router, so the deployment filter applies |
| Batches that Spanway runs itself | Every row is routed with the key, team and organization policy, so a row with no qualifying deployment fails with the policy error |
Code traffic
Source code is often the most sensitive data a company sends to a model. restrict_code_traffic lets you keep requests from coding tools on deployments that either keep nothing (data_retention: none) or run on your own infrastructure (self_hosted: true), while other requests from the same key, team or organization keep routing to any deployment.
Mark the self-hosted deployments, then set the rule on the scope that coding tools use.
model_list:
- model_name: coder
spanway_params:
model: hosted_vllm/qwen3-coder
api_base: http://vllm.internal:8000/v1
model_info:
self_hosted: true
- model_name: coder
spanway_params:
model: anthropic/claude-opus-5-5
api_key: os.environ/ANTHROPIC_API_KEY
model_info:
data_retention: limited
trains_on_data: false
curl -X PATCH http://localhost:4000/organization/update \
-H "Authorization: Bearer $SPANWAY_MASTER_KEY" \
-H "Content-Type: application/json" \
-d '{"organization_id": "org-eng", "data_policy": {"restrict_code_traffic": true}}'
self_hosted is never guessed from the provider name, since an ollama/ or hosted_vllm/ base can point at a server someone else runs. Only true qualifies, and a deployment that leaves it unset or sets a non-boolean value is treated as not self-hosted. self_hosted: true does not satisfy require_zdr, which still asks for data_retention: none. When a scope sets both require_zdr and restrict_code_traffic, code traffic needs data_retention: none.
How a request is identified as code traffic
The gateway checks these signals in order and stops at the first match. It only checks them when some scope of the caller sets restrict_code_traffic.
| Signal | Matches |
|---|---|
| Client | A User-Agent from Claude Code (claude-cli/ or claude-code/), Codex (codex), or the Spanway VS Code extension (spanway-vscode/), the x-gateway-client: claude-code header, or a User-Agent prefix listed in general_settings.code_traffic_user_agent_prefixes |
| Route | Any path under /claude_code_gateway/ |
| Header | x-spanway-code-context: true |
| Tag | code-context in the key, team or project tags |
| Content | Only when a scope also sets scan_content_for_code. A fenced code block of at least three lines, or a unified diff (diff --git, @@ - or +++ b/ lines), in the user, assistant or tool messages. System and developer instructions are not scanned, and the scan stops after the first 262,144 characters |
Add other coding tools by their User-Agent prefix, compared without regard to case.
general_settings:
code_traffic_user_agent_prefixes: ["opencode/", "my-internal-agent/"]
The client signals are self-reported, so any caller can leave them out. The rule never loosens routing, and a request that is not identified as code traffic simply follows the rest of the policy. When code must never leave your boundary, give coding tools their own key or team and set require_zdr on it. Only a proxy admin can change a data_policy, so the key holder cannot remove it. scan_content_for_code catches code pasted into other clients, at the cost of reading each prompt.
Spanway has no built-in signal for Cursor. Give Cursor its own key with the code-context tag, or with require_zdr when its traffic must stay within your boundary, or send x-spanway-code-context: true from tools that let you set headers.
The code-context tag is an ordinary tag. The owner of a key can edit the tags on their own key, so treat the tag as a convenience for marking a coding tool's key, not as a control the key holder cannot undo. It also counts for tag budgets and spend. When enable_tag_filtering is on, a tagged request is first limited to deployments whose tags allow it, and the code traffic rule then filters what is left, so add code-context to the tags of the deployments that should serve it.
What the rule covers
The rule is enforced wherever the policy is. That includes every router call type, fallback model groups, pinned deployments, the Claude Code gateway, and the /vllm, /azure, /nvidia_nim, /bedrock and /gigachat pass-throughs when the request names a router model.
Other provider pass-through endpoints send the request straight to the provider, so the gateway cannot check a deployment's terms there. A code traffic request to one of them is refused with a 400. That covers /anthropic, /vertex_ai (including Claude Code's :rawPredict and :streamRawPredict calls, even when the URL names a router model), /bedrock (including the agent runtime routes), /openai, /gemini, /cohere, /mistral, /assemblyai and the other provider routes, as well as requests with client-supplied credentials. The same refusal applies to any request on those endpoints from a caller whose policy sets require_zdr or forbid_training. Point coding tools at /v1/messages or /v1/chat/completions with a model group whose deployments declare their terms instead.
The websocket pass-throughs (/openai/v1/realtime and /openai/v1/responses over a websocket, /deepgram/v1/listen and /vertex_ai/live) are refused the same way when the session is identified as code traffic, and for any caller whose policy sets require_zdr, forbid_training or allowed_regions. The refusal is an error frame naming the policy, followed by a close with code 1008. The gateway cannot read websocket frames before they are relayed, so when a scope sets scan_content_for_code, every websocket session of that caller is treated as code traffic.
No deployment of model 'coder' satisfies the data policy: zero data retention or self-hosted for code traffic (detected via client: claude-code (User-Agent), required by organization policy). Rejected deployments: anthropic (id 3f2a...): not ZDR or self-hosted (data_retention=limited, self_hosted=undeclared)
The files, batches and fine-tuning endpoints do not detect code traffic yet, so only require_zdr and forbid_training apply to them.
A client cannot send its own data_policy_code_traffic field or metadata.code_traffic. Both are removed before the gateway runs detection.
Logs and metrics
A request identified as code traffic carries metadata.code_traffic in the standard logging payload and in its spend log, with the signal kind, a detail such as claude-code (User-Agent) and the scopes in enforced_by. The log details drawer in the Admin UI shows it as Code traffic.
With Prometheus enabled, spanway_code_traffic_requests_total counts these requests by signal_kind and outcome. routed means a qualifying deployment served the request and rejected means the router's data policy check refused it. Provider errors and other failures are not counted as rejected, and neither are refusals on a provider pass-through endpoint, which happen before the request is logged.
Rolling back
A gateway version from before this rule rejects any data_policy that contains restrict_code_traffic or scan_content_for_code as invalid, and requests on that key, team or organization fail with a 400. Clear those two fields before you roll back to such a version.
What the gateway stores
Zero data retention also governs what Spanway itself keeps. When a key, team or organization requires it, when its policy cannot be read, or when a request asks for it with provider.zdr: true, the gateway keeps only metadata for the request. Spend logs, the Lens copy of request logs, custom agent runs, workflow runs and online scoring keep no prompts, responses or tool inputs and outputs, every logging integration receives the redacted payload, and the response is not cached. When a team or its organization requires it, Lens also keeps no span content from that team's trace credentials. What Spanway stores lists every store and what it keeps.
Compliance evidence
GET /compliance/residency includes a data_policy section. It counts the keys, teams and organizations that require ZDR, forbid training or restrict code traffic, and lists every deployment with its declared terms, its region and whether it qualifies for ZDR, for no training and for code traffic. Those verdicts come from the same functions the router uses to filter deployments, with the same Vertex AI location fallback and, when use_curated_data_terms is on, the same curated terms. In the Admin UI the same section appears under Data policy on the Data Residency tab of the compliance page.
The compliance report scores the provider_data_policy_enforced control under GDPR (Art. 28(3)), UK GDPR, CCPA/CPRA and HIPAA. It fails while no active key (not blocked or expired), team or organization has a policy that requires ZDR, forbids training or restricts code traffic. A policy that sets only allowed_regions counts toward data residency instead, not this control. Once one does, the evidence states how many deployments qualify and how many undeclared deployments can never receive those requests. See Compliance for the full report.
Errors
| Status | Message | Meaning and fix |
|---|---|---|
| 400 | No deployment of model '<model>' satisfies the data policy: ... | Every deployment was rejected. The message names each requirement and why each deployment failed. Declare the terms on a deployment that meets them, or route to another model. |
| 400 | No deployment of model '<model>' satisfies the data policy: the allowed regions never overlap: ... | Two policies, for example the team's and the organization's, allow regions that share no deployment region. Widen one of them. |
| 400 | This <surface> request goes to the provider directly without a configured deployment, so the data policy (...) cannot be verified. Use a model group whose deployments declare their data terms. | A call with a client api_key or api_base, or on a provider pass-through route, while a policy applies. Use a configured model. |
| 400 | This request goes to <destination> without a configured deployment, so the data policy ... cannot be verified. ... | A files, batches or fine-tuning call that names only a provider. Name a model so its deployment terms can be checked. |
| 400 | <destination> uses model '<model>', which fails the data policy: ... | A files, batches or fine-tuning call names a model whose deployment does not meet the policy. Use a model that does. |
| 400 | Invalid key metadata.data_policy: ... (or team, organization) | The stored policy can no longer be read, for example after a rollback. Every request on that scope is refused until a proxy admin sends a valid policy or null. |
| 400 | Invalid data_policy: ... | The policy sent on a key, team or organization write is not valid, for example scan_content_for_code without restrict_code_traffic or an empty allowed_regions. Fix the field the message names. |
| 400 | required_model_region cannot be empty while it is enforced, so send a region or turn enforcement off in the same change | /config/update, /config/field/update, /config/field/delete or PATCH /compliance/residency would clear the required region while enforcement is on. Send a region, or turn enforcement off in the same change. |
| 403 | Only proxy admins can set data_policy on this <key, team or organization>. It decides which providers may receive the holder's request data. | A team admin or organization admin sent a different policy. Ask a proxy admin. |
| 403 | Only a proxy admin can declare a deployment's data terms (...). They decide which data policies the deployment satisfies. ... | A team admin changed data_retention, trains_on_data or another term on a team model. Ask a proxy admin. |
| 500 | general_settings.required_model_region is enforced but unset or ... but invalid: ... | Enforcement is on and the stored region is missing or unreadable, so every request is refused rather than sent anywhere. Set a valid region or turn enforcement off. |
| websocket close 1008 | an error frame naming the policy | A websocket pass-through session was refused because of the policy. Use a configured model group instead. |
Logs
| Level | Line | Meaning and action |
|---|---|---|
| WARNING | Deployment <model> declares malformed data terms <fields>, so they count as undeclared | A config.yaml deployment has a term outside the allowed values. Fix the value, the deployment meanwhile never qualifies for that term. |
| WARNING | ignoring invalid required_model_region='<value>' | The compliance report could not read the required region and reports none. Set a valid region. |
The code traffic metadata and the spanway_code_traffic_requests_total metric are described under code traffic logs and metrics.
Audit
Every change to a data policy or to a deployment's data terms is in the audit log with the values before and after. A key's policy is under Spanway_VerificationToken, a team's under Spanway_TeamTable and an organization's under Spanway_OrganizationTable, each in the row for the entity's update. A deployment's terms are in the Spanway_ProxyModelTable row of the model update. required_model_region and enforce_required_model_region are under Spanway_Config with object id general_settings.
Related
- Compliance page for the data policy table.
- Provider preferences.
- What Spanway stores.