Skip to content
Model API cross-border transfer: two gates of contract and gateway

Model API cross-border transfer: contracts handle accountability, gateways handle incidents

Previously, I switched an internal small tool from an overseas model API to a domestic node. The trigger wasn’t performance—it was a payload I saw while going through the request logs: a chat record a user had pasted in contained an ID number, a phone number, and the full text of an unsigned contract. I hadn’t done any field filtering; the whole thing was stuffed into messages.

In other words, since this tool went live, anything users casually pasted in had been sent out verbatim. My first instinct was to dig through the business code to see how many places were still calling the model API directly. After looking, I found I couldn’t even count them—each feature module built its own client and assembled its own messages, and nobody could say how much was being sent out per day.

After that, I put all model calls behind a self-built gateway. Whether data leaves the country is decided by the gateway, not by the individual client.chat.completions.create lines scattered across business files.

Let me be clear upfront: I’m not a lawyer, and everything below is from an engineering perspective. For the actual legal text, refer to the original.

What leaves the country isn’t just the prompt

Most people think “what leaves is the prompt.” In reality, a single call sends out far more than that.

The system prompt itself is in there. It often contains business rules, field meanings, and even internal table names and enum values. Plenty of teams, to save effort, copy schema comments straight into the prompt.

Beyond user input, there’s text parsed from attachments. A parsed PDF is the whole document, not a summary.

Tool call return values also leave. In RAG scenarios, that’s retrieved library content—possibly a complete document, not the snippet you assume.

Multi-turn context is the most underestimated part: the second request resends everything from the first turn, so the volume leaving is cumulative, not just the increment per turn. In a twenty-turn conversation, the same sensitive text may have gone out twenty times.

Three more are often missed. First, embedding requests: the chat endpoint gets desensitized, but the embedding step sends the original text in full—and these two pipelines often belong to two different teams and two different codebases. Second, batch processing and fine-tuning upload files: one-time, large volume, and often nobody treats them as “requests.” Third, retries: the same payload gets resent three or four times due to timeouts, so it leaves three or four times.

Server-side retention is another matter. Mainstream vendors’ APIs don’t train on your data by default, but they usually still retain it for a period for abuse monitoring—on the order of about a month; enterprise editions or specific configurations can negotiate shorter or even zero retention. These are written in the terms. I hadn’t read them before, and from what I’ve observed, most people haven’t either.

One judgment I only understood after getting burned: it’s not about whether the provider is domestic, but about who can access the data. Some vendors have domestic nodes and entities, but operations and the model side remain overseas—this is usually still treated as cross-border. Don’t take “the domain is .cn” as a conclusion.

What you can and can’t get in a contract

If you’re the customer, a decent data processing agreement (DPA) can roughly cover: processor identity—whether they’re a processor or an independent controller, which determines who’s liable when something goes wrong; the sub-processor list and the notice period before changes (many DPAs say “announced after changes,” which amounts to no notice); retention period, deletion mechanism, and deletion proof after termination.

A few harder ones: an explicit denial of using your data for training, rather than a vague “may be used to improve services”; the security incident notification deadline, usually on the order of tens of hours; the obligation to notify you of government access requests—hard to get, as most vendors write “notify to the extent permitted by law”; liability caps—the most realistic one, where compensation for data incidents is often capped at a few times the annual fee; and data storage region and cross-border transfer clauses.

What you can’t get is bargaining power. As a small customer, a DPA is usually take-it-or-leave-it; changing a single word goes through their legal team, and in the end you either sign or don’t. So my later approach was crude: save every version of the DPA, noting the version number and effective date. That way, at least when I someday need to trace “which version of the terms a given request was sent under,” I have something to show. This has a side effect: before signing, you’ll actually read it from start to finish, because you know you’ll be archiving it.

On the compliance path, the Personal Information Protection Law offers three: security assessment, certification, and standard contract filing. Later facilitation rules exempt scenarios involving non-sensitive personal information and a small annual cumulative headcount—as I understand it, on the order of 100,000 people; check the original text for the exact number, and different free trade zones have their own negative lists. Going through these processes requires a personal information protection impact assessment, with a list of cross-border fields written into it. The value of this is that you’ll discover many fields simply can’t be justified for sending out; the filing itself may not be the most important gain.

Four things on the gateway

I don’t think about these two together: a DPA determines whether I can hold someone accountable after the fact; the gateway determines whether the thing happens at all. The only one I can change is the latter.

First, a field whitelist, not a blacklist. Blacklists always miss things, because fields get added. My approach is to allow only the agreed-upon keys in the request body; everything else is dropped and logged. Dropping is annoying at first, but after two weeks it’s clean. The truly hard part is sitting down and writing clearly “which fields does this feature actually need”—nobody wants to do that.

Second, pseudonymization, with the mapping table kept locally.

PYTHON28 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import re, hashlib

PATTERNS = {
"id_card": re.compile(r"\b\d{17}[\dXx]\b"),
"phone": re.compile(r"\b1[3-9]\d{9}\b"),
"bank_card": re.compile(r"\b\d{16,19}\b"),
}

class Vault:
"""映射表只在本地内存里,不随请求出境"""
def __init__(self):
self._m = {}

def token(self, kind, value):
h = hashlib.sha256(f"{kind}:{value}".encode()).hexdigest()[:8]
tok = f"<{kind}_{h}>"
self._m[tok] = value
return tok

def restore(self, text):
for tok, val in self._m.items():
text = text.replace(tok, val)
return text

def redact(text, vault):
for kind, pat in PATTERNS.items():
text = pat.sub(lambda m: vault.token(kind, m.group(0)), text)
return text

Here’s a real pitfall: regexes interfere with each other—an 18-digit pure-number bank card gets eaten by the ID number rule first. I put id_card first, relying on dict insertion order to guarantee it’s replaced first; after replacement it becomes <id_card_xxxx>. This order dependency is fragile, but better than nothing. Another pitfall is the mapping table itself: the snippet above only holds in single-process memory; with multiple replicas you need shared storage, and that storage’s security level can’t be lower than the original data—otherwise you’ve just moved the risk elsewhere.

Third, logs store only hashes and token counts. The gateway’s own access log shouldn’t contain the raw prompt; a sha256(payload) and character count is enough, and when troubleshooting you correlate upstream by time. I store the raw payload separately as an encrypted copy, retained for 7 days, decrypted only during postmortems. There’s an explicit tradeoff here: if a problem surfaces after 7 days, I can’t investigate it. This window is the result of trading storage risk for investigative capability—not a standard answer.

Fourth, triage locally first. Regex only covers structured fields; it’s useless for names, addresses, or medical history buried in free text. So requests first pass through a small local classifier—a set of keyword rules plus a small model, with a conservative threshold—to judge whether the text contains suspected personal information. If so, the whole request is routed to a local model; better a slightly worse result than letting it leave. This triage saved more volume than I expected—roughly 30% of requests ended up not going out.

There’s also a layer of provider abstraction. Providers are configuration; switching takes under an hour. This isn’t to save money—it’s so that if the terms or the policy change someday, I don’t have to touch business code.

A fifteen-minute weekly spot check

Each week I sample 20 gateway logs, decrypt the raw payloads, compare them against the desensitized text, and look for anything that slipped through. Fifteen minutes each time.

Is this more useful than reading ten pages of a DPA? Not necessarily—they solve different problems. Sampling has another layer of value: it keeps producing dirty samples—which fields are constantly missed, which types of attachments take longest to parse—things you can’t come up with by sitting around brainstorming.

The next thing to change is embedding. Right now vectorization still sends the entire original text out. I haven’t figured out how to switch to local without sacrificing recall. I plan to first run a recall comparison with a small local model, and if the drop is no more than five points, switch everything over. Whether five points is too loose a threshold, I don’t have a conclusion yet; but given the current cross-border exposure surface, I lean toward switching first and tuning later.

About this Post

This post is written by Lu's Blog, licensed under CC BY-NC 4.0.

#Data Compliance #Gateways #Model APIs

Comments