Skip to content

Commit bc45489

Browse files
authored
document cf-aig-collect-log-payload header redacting request and responses in logs (#28904)
1 parent 2254ea0 commit bc45489

1 file changed

Lines changed: 35 additions & 1 deletion

File tree

  • src/content/docs/ai-gateway/observability/logging

src/content/docs/ai-gateway/observability/logging/index.mdx

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ In the example below, we use `cf-aig-collect-log` to bypass the default setting
3434
curl https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/openai/chat/completions \
3535
--header "Authorization: Bearer $TOKEN" \
3636
--header 'Content-Type: application/json' \
37-
--header 'cf-aig-collect-log: false \
37+
--header 'cf-aig-collect-log: false' \
3838
--data ' {
3939
"model": "gpt-4o-mini",
4040
"messages": [
@@ -47,6 +47,40 @@ curl https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/openai/chat/
4747
'
4848
```
4949

50+
### Collect log payload (`cf-aig-collect-log-payload`)
51+
52+
The `cf-aig-collect-log-payload` header allows you to control whether the raw request and response bodies (payloads) are stored for a given request. Unlike `cf-aig-collect-log`, which controls the entire log entry, this header only affects payload storage — metadata such as token counts, model, provider, status code, cost, and duration will still be logged.
53+
54+
This is useful when you want to maintain visibility into usage metrics and request metadata without persisting sensitive prompt or completion data.
55+
56+
| Header value | Behavior |
57+
| ------------ | -------- |
58+
| `true` | Request and response payloads are stored. |
59+
| `false` | Payload storage is skipped. Metadata-only log entries are still saved. |
60+
61+
In the example below, we use `cf-aig-collect-log-payload` to skip storing the request and response bodies while keeping the metadata log.
62+
63+
```bash
64+
curl https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/openai/chat/completions \
65+
--header "Authorization: Bearer $TOKEN" \
66+
--header 'Content-Type: application/json' \
67+
--header 'cf-aig-collect-log-payload: false' \
68+
--data ' {
69+
"model": "gpt-4o-mini",
70+
"messages": [
71+
{
72+
"role": "user",
73+
"content": "What is the email address and phone number of user123?"
74+
}
75+
]
76+
}
77+
'
78+
```
79+
80+
:::note
81+
If `cf-aig-collect-log` is set to `false`, the entire log entry (including metadata) is skipped regardless of the `cf-aig-collect-log-payload` value. Use `cf-aig-collect-log-payload: false` on its own if you only want to suppress payload storage while retaining metadata logs.
82+
:::
83+
5084
## DLP fields in logs
5185

5286
When [Data Loss Prevention (DLP)](/ai-gateway/features/dlp/) policies are enabled on a gateway, log entries for requests that trigger a DLP policy match include additional fields:

0 commit comments

Comments
 (0)