Skip to content

Put an AI gateway in front of llm-d

Use this guide when clients need one OpenAI-compatible entry point for both your self-hosted llm-d models on TPU and external provider APIs, with keys, authentication, rate limits and budgets enforced in one place. llm-d documents two such gateways, LiteLLM and Kong AI Gateway; both forward self-hosted traffic to the llm-d router (the Gateway's address in Gateway Mode, or the EPP Service in Standalone Mode), so nothing about them is TPU specific. The stateful Responses API is its own path: Responses API. Chapter 21 covers the router these gateways sit in front of.

On the left a gray Client box; an arrow labelled API key runs to an amber box, AI gateway, keys, limits, budgets. From the top of the gateway an arrow labelled provider models runs up and right to a gray box, External provider APIs. From the right of the gateway an arrow labelled self-hosted models above and + tenant, priority headers below runs into a gray dashed container titled llm-d on TPU, to an amber Router box, via Gateway or EPP Service. An arrow labelled prefix and load runs down from Router to a blue box, TPU model servers. A note at the bottom left reads Tenant and priority come from the gateway, not the client.

The gateway, LiteLLM or Kong AI Gateway, is the one place where clients authenticate and are metered; behind it, the llm-d router (the Gateway's address in Gateway Mode, the EPP Service in Standalone Mode) still chooses the TPU pod by prefix and load.

Prerequisites

  • A deployed optimized baseline on TPU, reachable at http://<gateway-ip>/v1 (Gateway Mode) or http://optimized-baseline-epp.llm-d-optimized-baseline.svc.cluster.local:80/v1 (Standalone Mode).
  • kubectl, helm, openssl and curl.
  • LiteLLM: PostgreSQL and Redis in its namespace (the guide deploys both; it was validated with chart 1.94.1, proxy v1.90.2, PostgreSQL 16, Redis 7.4).
  • Kong: the Gateway API CRDs (kubectl get crd gateways.gateway.networking.k8s.io httproutes.gateway.networking.k8s.io).
  • Provider API keys only in Kubernetes Secrets, never in values files or client code.

Steps

1. LiteLLM: register the llm-d model

In the LiteLLM Helm values.yaml, add the llm-d model under model_list with the hosted_vllm/ prefix. For Standalone Mode with Qwen3-32B on v6e:

    - model_name: qwen/qwen3-32b-standalone
      litellm_params:
        model: hosted_vllm/Qwen/Qwen3-32B
        api_base: http://optimized-baseline-epp.llm-d-optimized-baseline.svc.cluster.local:80/v1
        api_key: "none"
      model_info:
        input_cost_per_token: 0.0000008   # $0.80 per 1M input tokens
        output_cost_per_token: 0.0000024  # $2.40 per 1M output tokens

llm-d requires no API key. Self-hosted models have no public price, so set model_info to your own chargeback rate or LiteLLM records zero spend and budgets count only external models. The guide's formula: tokens_per_hour = 3600 x sustained_output_tok/s x utilization and output_cost_per_token = (accelerator $/hr x accelerators) / tokens_per_hour; on TPU use the slice's hourly price and your measured throughput. Then install:

export NAMESPACE=litellm
kubectl create namespace "$NAMESPACE" --dry-run=client -o yaml | kubectl apply -f -
# create the core and provider Secrets, PostgreSQL and Redis as the guide shows, then:
helm install litellm oci://ghcr.io/berriai/litellm-helm \
  -n "$NAMESPACE" -f values.yaml
kubectl -n "$NAMESPACE" rollout status deploy/litellm

Check: kubectl -n "$NAMESPACE" get svc lists litellm on port 4000; through a port-forward, /v1/models lists qwen/qwen3-32b-standalone, and a chat request with a virtual key returns a completion from the TPU pool.

2. Kong: route a path to the llm-d model

Install the kong/ingress chart (helm repo add kong https://charts.konghq.com), create the kong Gateway and a placeholder Service, then pair an ai-proxy plugin with an HTTPRoute. For Standalone Mode:

apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
  name: ai-proxy-qwen3-32b-standalone
plugin: ai-proxy
config:
  route_type: llm/v1/chat
  model:
    provider: openai
    name: Qwen/Qwen3-32B
    options:
      upstream_url: http://optimized-baseline-epp.llm-d-optimized-baseline.svc.cluster.local:80/v1/chat/completions
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: qwen3-32b-standalone
  annotations:
    konghq.com/plugins: ai-proxy-qwen3-32b-standalone, key-auth, rate-limiting
spec:
  parentRefs:
    - name: kong
  rules:
    - matches:
        - path:
            type: PathPrefix
            value: /qwen3-32b-standalone
      backendRefs:
        - name: ai-placeholder
          port: 80

The key-auth and rate-limiting plugins and the KongConsumer with its credential Secret come from the guide's step 4. On TPU7x, set name to Qwen/Qwen3.5-397B-A17B-FP8 and point upstream_url at your release's EPP Service.

Check: a request without a key is rejected, and with one it returns a completion:

curl -s -m 45 http://$PROXY_IP/qwen3-32b-standalone \
  -H "Content-Type: application/json" \
  -H "apikey: $CLIENT_KEY" \
  -d '{
    "messages": [{"role": "user", "content": "hi"}],
    "max_tokens": 16
  }' | jq .

3. Keep the router's view intact

The gateway sends each request to the router, which still picks the TPU pod by prefix and load. Tenant and priority headers for flow control must be set by the gateway after it authenticates the client, not passed through from clients.

Check: per-pod counters (Optimized baseline, step 5) still show prefix affinity for requests sent through the gateway.

Troubleshooting

Symptom Cause Fix
LiteLLM spend stays 0 for llm-d models No model_info prices on hosted_vllm/* Add your chargeback rates
A LiteLLM key limited to 60 RPM briefly allows about 3x with 3 replicas Virtual-key limits are per pod, synced late One replica, or divide rpm_limit by the replica count
Kong rejects the request key-auth on the route and no apikey header Send the consumer's key
Model not found through the gateway Model name differs from what /v1/models on the router returns Use the exact served ID
Gateway Mode upstream unreachable Wrong Gateway address kubectl get gateway llm-d-inference-gateway -n <ns>

References