From a26e57b2c5e21c41d56e77024668e2e376c8149e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Tailland?= Date: Thu, 27 Aug 2026 16:41:34 +0200 Subject: [PATCH] Let the AI gateway read the bodies it is meant to log Two ceilings had to clear 30 KB prompts, and neither alone was enough: nginx's client_body_buffer_size, which decides whether the body stays in memory at all, and ai-proxy's max_request_body_size, which decides whether the plugin will introspect it. With the first at 8k the body went to a temp file and kong.request.get_raw_body() returned nil, so log_payloads and log_statistics were enabled and empty, and no kong_ai_llm_* metric ever appeared. 256k here against the 8k the domain gateways keep. Affordable because this gateway is low-traffic; the buffer is per connection carrying a body, so copying the value to the domain gateways needs that arithmetic redone for their volume. Storage cost measured rather than assumed: 18 LLM requests a day at roughly 60 KB of prompt and completion is 1.1 MiB/day, against 425 MiB/day of Kong audit records already flowing. My earlier warning that the audit trail would grow fast was wrong at this volume. Co-Authored-By: Claude Opus 5 --- dev/ai-gateway-kustomization.yaml | 10 ++++++++++ kong/ai-proxy-advanced.yaml | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/dev/ai-gateway-kustomization.yaml b/dev/ai-gateway-kustomization.yaml index 68ca314..3d13303 100644 --- a/dev/ai-gateway-kustomization.yaml +++ b/dev/ai-gateway-kustomization.yaml @@ -18,6 +18,16 @@ spec: substitute: NAME: llm-dev NAMESPACE: llm + # 256k, against the 8k the other domains keep. Prompts here carry the + # conversation and the MCP tool definitions and already run to 30 KB; + # below this nginx spills the body to a temp file and + # kong.request.get_raw_body() returns nil, which is what left ai-proxy's + # log_payloads and log_statistics producing nothing at all. + # + # Affordable precisely because this gateway is low-traffic — the buffer is + # per connection carrying a body. Do not copy it to the domain gateways + # without doing that arithmetic for their volume. + CLIENT_BODY_BUFFER_SIZE: 256k HOSTNAME: llm-dev.sttlab.local substituteFrom: - kind: ConfigMap diff --git a/kong/ai-proxy-advanced.yaml b/kong/ai-proxy-advanced.yaml index c36a483..0d92067 100644 --- a/kong/ai-proxy-advanced.yaml +++ b/kong/ai-proxy-advanced.yaml @@ -5,6 +5,10 @@ metadata: namespace: ${NAMESPACE} plugin: ai-proxy-advanced config: + # The plugin's own ceiling on what it will introspect, distinct from nginx's + # client_body_buffer_size — both have to clear 30 KB prompts or the payload + # and usage logging stay empty. Raised together; neither alone is enough. + max_request_body_size: 262144 targets: - route_type: llm/v1/chat auth: