OpenAICloudflare Developer PlatformMar 17, 2026, 12:00 AM

AI Gateway - Log AI Gateway request metadata without storing payloads

A condensed section focused on the key takeaways first.

Original Post

Quick Digest

Summary

A condensed section focused on the key takeaways first.

openaienmodel: gpt-5-mini-2025-08-07

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 false to 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":"..."}]}'.

Full Translation

Translations

A translation section that keeps the flow of the original article.

openaijamodel: gpt-5-mini-2025-08-07

AI Gateway — ペイロードを保存せずにAI Gatewayリクエストのメタデータを記録する

AI Gateway: ペイロードを保存せずにリクエストメタデータを記録する

AI Gateway は cf-aig-collect-log-payload ヘッダーをサポートするようになりました。このヘッダーはリクエストおよびレスポンスのボディをログに保存するかどうかを制御します。デフォルトでは true に設定され、ペイロードはメタデータとともに保存されます。false に設定すると、ペイロードの保存をスキップしつつ、トークン数、モデル、プロバイダ、ステータスコード、コスト、所要時間(duration)などのメタデータは引き続きログに記録されます。これは使用状況メトリクスが必要だが、プロンプトやレスポンスなどの機密データを永続化したくない場合に便利です。

使い方(例)

ターミナルからのリクエスト例:

curl https://gateway.ai.cloudflare.com/v1/$ACCOUNT_ID/$GATEWAY_ID/openai/chat/completions \
  --header "Authorization: Bearer $TOKEN" \
  --header 'Content-Type: application/json' \
  --header 'cf-aig-collect-log-payload: false' \
  --data '{ "model": "gpt-4o-mini", "messages": [ { "role": "user", "content": "What is the email address and phone number of user123?" } ] }'

ログに記録される主なメタデータ

  • トークン数(token counts)
  • モデル(model)
  • プロバイダ(provider)
  • ステータスコード(status code)
  • コスト(cost)
  • 所要時間(duration)

参考

  • 詳細は Logging を参照してください。