Stéphane Tailland 05cf2bcce1 Turn on Kong's own AI telemetry instead of improvising it
Four settings, all of them off, which is why the AI gateway produced
HTTP-level telemetry and nothing about the model.

  logging.log_payloads     the prompt and the completion, in the log
                           records and — since OTel instrumentation is on
                           here — in the spans too
  logging.log_statistics   model usage and token counts
  prometheus.ai_metrics    kong_ai_llm_* : requests, tokens by type, cost,
                           provider latency, per model and per consumer
  input_cost / output_cost cost per 1M tokens, which is what makes
                           kong_ai_llm_cost_total mean anything

Also removes this morning's pre-function/post-function body capture from
this gateway. It was the wrong tool for the LLM route: Kong's own
implementation reassembles a streamed SSE answer, while accumulating raw
chunks in kong.ctx.shared does not. The five business domains keep theirs
— their MCP traffic is not streamed the same way.

The costs are a snapshot, checked against OpenRouter's price list for
google/gemini-3.7-flash on 2026-08-27: $0.375 in, $1.875 out per 1M
tokens. They are substitution variables rather than literals precisely
because a stale figure produces confidently wrong money rather than an
error.

Note what this does NOT fix: usage is missing on streamed responses
because the OpenAI-compatible API only reports it when the caller asks
for stream_options.include_usage, and that is LibreChat's request to
make, not Kong's. Expect token counts to stay partial until then.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-27 14:12:32 +02:00
2026-08-20 17:28:05 +02:00

platform-llm

Platform-owned llm bounded context — Gateway infrastructure and the shared LLM proxy in one repo. Never split per functional domain, and never split between infra/routing here either: both are owned by the same (platform) team, unlike catalog's dataplane-catalog/catalog-api split (feature team vs. platform team, a real access boundary that doesn't exist for this domain).

What it does

Fronts OpenRouter (https://openrouter.ai) via one proxy route (/llm/v1/chat/completions) — the client's own model field selects among any OpenRouter-hosted model, not just a fixed set Kong picks.

Active policies:

  • ai-rate-limiting-advanced, token-based, both global (across all callers) and per-client (per authenticated consumer).
  • ai-prompt-guard (regex) and ai-semantic-prompt-guard (embedding-based, backed by Redis Stack) for prompt-injection/jailbreak safeguarding.
  • Two-tier auth: key-auth (static, shared key) for chatbot UIs that can't do OIDC on their outbound LLM connection (LibreChat and similar tools — structural limitation of that whole category, not fixable client-side), openid-connect for agents built in-house. Either succeeds; a request passing neither is rejected (request-termination on the fallback anonymous consumer).

Not yet active: PII redaction (ai-sanitizer) — needs a private Kong Cloudsmith registry image and an AI Gateway Enterprise entitlement, blocked pending that access. Everything else in this repo is unaffected.

Structure

  • dev/ai-gateway-kustomization.yaml + dev/ai-gateway-externalsecret.yaml — Gateway/DataPlane/Control Plane infra (same shared k8s-platform template every domain uses).
  • dev/proxy-kustomization.yaml + dev/proxy-externalsecret.yaml — the LLM proxy itself (./kong).
  • dev/gitrepository.yaml — this repo, self-referential.
S
Description
No description provided
Readme 78 KiB