ClaudeCloudflare 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.

claudeenmodel: claude-sonnet-4-20250514

AI Gateway adds selective payload logging control

Key Points

  • New header controls AI Gateway payload logging
  • Metadata logging preserved without sensitive data
  • Enhanced privacy for AI request monitoring

Summary

AI Gateway introduces the cf-aig-collect-log-payload header to control whether request and response payloads are stored in logs. This feature enables logging of essential metadata while optionally excluding sensitive payload data.

Key Points

  • New header control: cf-aig-collect-log-payload header determines payload storage behavior
  • Default behavior: Header defaults to true, maintaining current logging functionality
  • Metadata preservation: Setting header to false still logs metadata including token counts, model, provider, status code, cost, and duration
  • Privacy enhancement: Allows collection of usage metrics without persisting sensitive prompt or response data
  • Simple implementation: Add header with false value to API requests to skip payload storage

Full Translation

Translations

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

claudejamodel: claude-sonnet-4-20250514

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

AI Gateway

AI Gatewayで、リクエストとレスポンスのボディをログに保存するかどうかを制御するcf-aig-collect-log-payloadヘッダーがサポートされました。デフォルトでは、このヘッダーはtrueに設定されており、ペイロードはメタデータと一緒に保存されます。

このヘッダーをfalseに設定すると、ペイロードの保存をスキップしながら、以下のようなメタデータのログ記録は継続されます:

  • トークン数
  • モデル
  • プロバイダー
  • ステータスコード
  • コスト
  • 実行時間

これは、使用状況メトリクスが必要だが、機密性の高いプロンプトやレスポンスデータを永続化したくない場合に便利です。

使用例

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?"
      }
    ]
  }'

詳細については、Loggingを参照してください。