AI Gateway - Log AI Gateway request metadata without storing payloads
Key Points
- cf-aig-collect-log-payload header added
- Set header to false to avoid storing request/response bodies
- Metadata (tokens, model, cost, duration) still logged
Summary
AI Gateway adds the cf-aig-collect-log-payload request header to control whether request and response bodies are stored in logs. By default the header is true (payloads are stored). Set it to false to skip storing request/response bodies while still logging metadata such as token counts, model, provider, status code, cost, and duration. This lets you retain usage and billing metrics without persisting sensitive prompt or response text.
Key Points
- Header:
cf-aig-collect-log-payload(default:true). - Set the header to
falseto prevent storing request/response bodies while retaining metadata: token counts, model, provider, status code, cost, duration. - Use case: collect usage metrics and billing data without persisting sensitive prompts or responses.
- Example: include the header in requests, e.g.
curl -H 'cf-aig-collect-log-payload: false' https://gateway.ai.cloudflare.com/v1/$ACCOUNT_ID/$GATEWAY_ID/openai/chat/completions -H 'Authorization: Bearer $TOKEN' -H 'Content-Type: application/json' -d '{"model":"gpt-4o-mini","messages":[{"role":"user","content":"..."}]}'.