Once pb-46's dashboards show where tokens go, the levers to pull live in the serving and gateway layers: prefix caching (free KV-cache reuse in vLLM), exact and semantic response caching at the gateway, and traffic shaping — priority tiers, token-bucket rate limits, and hedging policy — that protects interactive latency while batch work soaks spare capacity.
Tier: Advanced · Workflow area: Platform-for-AI: observability & cost
This playbook applies each lever where it pays, with the measurement discipline to prove it, and the false-hit guardrails semantic caching demands.
Skip semantic caching for low-volume, high-uniqueness traffic (agent transcripts, unique documents) — hit rates will be single-digit and the false-hit risk isn't worth it. Prefix caching and rate shaping still apply.
Take the free win: vLLM prefix caching. vLLM's automatic prefix caching reuses KV-cache blocks for shared prompt prefixes (system prompts, few-shot preambles, RAG boilerplate) — it cuts prefill compute and TTFT without changing response content, so it is always safe. Confirm it's enabled for your vLLM version (recent versions default on; older need --enable-prefix-caching), then structure prompts for it: stable prefix first, volatile content last — the same discipline as provider-side prompt caching for hosted APIs.
Add exact-match response caching at the gateway. In LiteLLM:
litellm_settings:
cache: true
cache_params:
type: redis
host: os.environ/REDIS_HOST
ttl: 600
Exact-match caching is low-risk (identical request → identical stored response) and already absorbs retries and duplicate clicks. Scope it per-route/key rather than globally, and keep TTLs short where the underlying knowledge moves.
Add semantic caching only where meaning-equivalent answers are acceptable. Semantic cache embeds the prompt and serves a stored response when similarity exceeds a threshold:
litellm_settings:
cache: true
cache_params:
type: redis-semantic
similarity_threshold: 0.92 # start strict; loosen with evidence
redis_semantic_cache_embedding_model: text-embedding-3-small
Safety rules: never on personalized or per-user-context routes (cross-user answer leakage), never on time-sensitive answers, always with the cache keyed within a tenant/team boundary, and always with a cache_hit flag emitted into pb-46 traces so hits are auditable. Verify config keys against your pinned LiteLLM version; GPTCache-class sidecars are the alternative if you need custom eviction or scoring.
Shape traffic into tiers. Define two or three service tiers and enforce them with the mechanisms you already own: per-key rpm_limit/tpm_limit as token buckets (interactive keys get burst headroom; batch keys get throughput caps), the pb-44 inference gateway's priority/criticality policy so batch never queues ahead of chat, and scheduling batch/eval jobs off-peak. Token-bucket intuition: cap burn rate per tier so no single consumer can starve the pool even inside its monthly budget.
Decide your hedging policy deliberately. Request hedging (duplicate a slow request, take the first response) tames tail latency on cheap idempotent calls — but every hedge doubles token cost and load, and hedging into a saturated pool makes the tail worse. If you enable client/gateway retries with tight timeouts as a hedge, cap hedge rate, exempt expensive long-generation routes, and watch the pb-46 cost dashboards for the hedge tax.
Measure before/after like an SRE. For each lever: one-week baseline, enable for a segment, compare — cache hit rate, cost-per-request, P95 TTFT, and (for semantic cache) a sampled false-hit audit where a human judges whether served-from-cache answers were actually correct for the new prompt. Keep or kill each lever on evidence.
A semantic-cache false hit is a silent wrong answer served fast — set the threshold strict, audit samples weekly, and never let the hit-rate KPI outrank the false-hit audit.
similarity_threshold always raises hit rate and always raises false hits; only the human audit tells you the real trade.The cheapest token is the one never generated — before tuning caches, delete dead instructions from your longest system prompts; pb-46's token dashboards tell you which prompts to attack first.