apiVersion: configuration.konghq.com/v1 kind: KongPlugin metadata: name: ${NAME}-llm-ai-proxy-advanced 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: header_name: Authorization header_value: ${OPENROUTER_BEARER} # dev only, like the rest of this gateway's audit trail: log_payloads # puts the prompt and the completion in the log stream, and -- because # OpenTelemetry instrumentation is on here -- in the spans as well. # # This is what the pre-function/post-function capture in # observability.yaml stood in for on this route. Kong's own # implementation reassembles a streamed SSE answer; accumulating raw # chunks does not. logging: log_payloads: true # Model usage and token counts in the log records. With this off Kong # counted nothing of its own, which is half of why usage was missing. log_statistics: true model: provider: openai # name deliberately unset: the client's own `model` field is passed # through to OpenRouter. options: upstream_url: ${OPENROUTER_UPSTREAM_URL} # Cost per 1M tokens, in the provider's currency. Kong multiplies # these by the token counts to produce kong_ai_llm_cost_total, so a # stale figure yields confidently wrong money rather than an error. # Re-check them whenever the model or the contract changes. input_cost: ${LLM_INPUT_COST} output_cost: ${LLM_OUTPUT_COST}