Logging every request feels like the responsible thing to do. It is also how teams build their second-largest copy of user data, in a store with weaker access control than the database they spent a year securing.
Both problems are real. You cannot debug a model integration without records of what happened, and you cannot defend a log that contains the customer’s document. This page draws the line: the fields worth keeping, the fields that turn a debugging aid into a liability, and the checks that catch a cost or privacy problem before a customer does.
Quick answer. Log token counts, latency, model name, status codes, and correlation IDs. Never log the raw prompt, the raw response, uploaded file content, authentication headers, or full provider error bodies. If you must keep a sample of text for debugging, sample rarely, truncate hard, and delete on a schedule you can prove.
Why logging is a privacy decision
A log line that contains a prompt is a copy of the prompt. That sentence sounds trivial and it decides most of the compliance questions that follow. If the request contained a customer’s contract, the log now contains the contract — under a different retention policy, in a different jurisdiction, visible to a different set of engineers, and usually indexed by a search tool nobody reviewed.
DeepSeek’s own terms say that input and output data may be used, after encryption and de-identification, to operate or improve the services, and the consumer services are described as not being designed for sensitive personal data. Our privacy and safety guide walks through those documents. None of that changes what happens on your side: the provider’s policy governs what DeepSeek does with a request, and your logging policy governs how many extra copies you make of it.
The 12 fields worth logging
These are the fields that let you debug, price, and alert on an integration without storing anything a customer would object to.
| Field | What it answers | Notes |
|---|---|---|
timestamp_utc | When did it happen | ISO 8601, always UTC. Mixed timezones make incidents unreadable. |
request_id | Which call was this | Generated by you, propagated through every service and queue. |
provider_request_id | What the provider saw | The ID from the API response. Required for any support ticket. |
model | Which model answered | Cost and behaviour differ per model; “the API” is not a model name. |
status_code | Did it succeed | Store the raw HTTP status, not just a boolean. |
error_code | What kind of failure | Normalise it. Rate limits and billing failures need different responses. |
latency_ms | How slow, end to end | Include retries and queue time, or the number flatters you. |
ttft_ms | How slow it felt | Time to first token. The metric users actually experience on streaming. |
input_tokens_cache_miss | What the expensive input cost | The line that dominates most bills. |
input_tokens_cache_hit | Is caching working | Cache-hit input is billed at a fraction of cache-miss input. |
output_tokens | What the answer cost | Usually the largest line on the invoice, and the one that grows silently. |
feature_tag | Who is spending | One tag per product feature or customer tier. Without it, cost attribution is guesswork. |
Add attempt if your client retries automatically. A retry is a second bill for the same task, and the only way to see it is to record which attempt produced the result.
Fields that create liability
- The raw prompt or messages array. It is the customer’s content with a new retention policy attached.
- The raw completion. The same problem on the way out — and model output can reproduce fragments of the input.
- Uploaded files and extracted text. Whole documents, stored in a store that was designed for strings.
- Authentication headers. Many HTTP clients log full request headers at debug level, which writes
Bearer sk-…to disk. Strip the header before the client sees it. - Full provider error bodies. Validation errors frequently echo the offending value back. Logging the whole body can email a prompt fragment to your alerting channel.
- Tool-call arguments. An agent that queries a database puts the filter — and sometimes the record — into the arguments.
- User identifiers you do not need. Email addresses and IPs in a log line turn a performance dataset into personal data.
None of this means “log less”. It means log the shape of the request rather than its contents.
A minimal log schema you can copy
One JSON object per request, emitted after the response is fully read. Field names are yours; populate the usage numbers from the provider’s response so you are never estimating.
{
"ts": "2026-11-27T09:14:02.113Z",
"request_id": "req_01J8QZ4T7K",
"provider_request_id": "chatcmpl-9f2c...",
"model": "deepseek-flash",
"status": 200,
"error_code": null,
"latency_ms": 1840,
"ttft_ms": 420,
"attempt": 1,
"usage": {
"input_miss": 1180,
"input_hit": 3200,
"output": 512
},
"feature": "invoice-extract"
}
That object is about 250 bytes. At 100,000 requests a month it is 25 MB — small enough to keep for a year, and it answers almost every question you will ask during an incident. Our API setup guide covers where these values come from in the response.
Redact by allowlist, not by blocklist
Every team that has tried to scrub prompts with a regex has eventually shipped a prompt that got past it. Names, addresses, and account numbers do not have a shape you can match reliably. The durable pattern is the opposite: build the log object from an allowlist of fields, so anything you did not deliberately include never reaches the writer.
When you genuinely need text for debugging, treat it as a separate, temporary artefact rather than a log field:
- Sample rarely — one request in a thousand, not every failed one.
- Truncate hard — 200 characters is enough to recognise a format problem.
- Record why it was kept and when it will be deleted, in the same record.
- Restrict access to a named group, and log who reads it.
What to alert on
Once the fields exist, five alerts cover most of the failures that cost money or trust.
| Alert | Suggested trigger | What it usually means |
|---|---|---|
| Rate-limit responses | Above 2% of requests in 5 minutes | A runaway client, or concurrency above your plan |
| Billing failures | Any occurrence | The account is out of balance and serving will stop |
| p95 latency | Above 2× your 7-day baseline | Provider slowdown, or your prompts got heavier |
| Cache-hit ratio | More than 20% drop week over week | A prompt change quietly doubled input cost |
| Retry rate | Above 5% | Hidden cost multiplier and a sign of a bad error taxonomy |
The cache-hit alert is the one most teams miss, and it is the one that protects the bill. A cache-hit ratio that falls from 70% to 40% after an innocent prompt edit can double your input cost without any error, any latency change, or any complaint. DeepSeek’s usage block reports cache-hit and cache-miss input tokens separately for exactly this reason; our context caching guide covers how to keep the ratio high.
How long to keep each layer
| Layer | Useful for | Reasonable retention |
|---|---|---|
| Per-request fields (the schema above) | Debugging a specific incident | 7–30 days hot, then aggregate |
| Aggregates (daily counts, p95, cache ratio) | Cost trends and capacity planning | 13 months |
| Sampled text, if you keep any | Reproducing a format or parsing failure | Days, with an expiry per record |
| Raw prompts and responses | Nothing you cannot get another way | Do not store by default |
Write the retention period into the log record itself, as a field, so a scheduled job can delete by data rather than by hope.
DeepSeek-specific details worth knowing
- Cache tokens are reported separately. If you log one input number, your cost per request will be wrong for every cached workload — and wrong in the direction that hides savings.
- Billing failure is a status, not an exception. An exhausted balance returns an error rather than degrading service; alert on it explicitly. Our error code guide maps the codes worth monitoring.
- Rate limits are per key. A second key does not raise a shared concurrency ceiling, so log the key identifier (not the key) alongside failures if you run more than one. See rate limits.
- Peak hours change the price of the same tokens. Timestamps let you explain a bill that moved without a traffic change; the rates are on our pricing page.
Quick answers
Can I log prompts if I strip personal data first?
You can, but stripping is the part that fails in practice. A prompt is unstructured text; your regex will miss a name eventually. Log the request’s shape — token counts, status, latency — and keep text out of the default path entirely.
Do I need to log every request?
Every request needs the 12 fields; not every request needs text. The fields are cheap enough to keep at full volume, which is what makes sampling text safe: you still know that 100% of calls succeeded and what they cost.
Is the provider’s dashboard not enough?
It tells you what you spent, not which feature spent it. Provider dashboards cannot tag a request with your customer tier or tie a latency spike to a deploy, and they will not survive a migration to a second provider.
How do I debug a bad answer without the prompt?
Record a prompt template version and a content hash, then reproduce from the template in a controlled environment. You rarely need the customer’s exact text to see that a schema instruction stopped working.
What about logging in the browser or a mobile app?
Treat client-side logs as public. Anything written there can be read by the user and by anything that inspects the device. Keep the keys and the request bodies on the server, and log client events as identifiers only.
Does DeepSeek retain what I send?
Its terms describe using inputs and outputs, after encryption and de-identification, to operate or improve the services, with an opt-out called “Improve the model for everyone” in the consumer product. The commercial API is covered by a separate open-platform policy. Read the primary documents before you decide, and remember they govern the provider’s copy, not yours.
Sources
- DeepSeek API documentation — response fields, usage block, error codes
- DeepSeek Terms of Use — use of inputs and outputs, the model-improvement opt-out
- DeepSeek Privacy Policy, February 10, 2026 — data categories and processing location
- Open platform privacy policy (Chinese) — API data handling
