Skip to content

Instantly share code, notes, and snippets.

@phatpham-katalon
Created March 27, 2026 10:20
Show Gist options
  • Select an option

  • Save phatpham-katalon/a3a5958ac6f11ff62b4a767c769bb9b8 to your computer and use it in GitHub Desktop.

Select an option

Save phatpham-katalon/a3a5958ac6f11ff62b4a767c769bb9b8 to your computer and use it in GitHub Desktop.

Prompt Caching Evidence Report

Date: 2026-03-27
Model: anthropic.claude-haiku-4-5-20251001-v1:0
Proxy: LiteLLM via mitmproxy reverse proxy on localhost:8888
Agent: kai-orchestrator-agent on localhost:8005
Runtime: copilotkit-runtime-server on localhost:3000

Test Setup

  • Fresh agent restart with LITELLM_PROXY_API_BASE=http://localhost:8888
  • stream_options: {"include_usage": true} enabled to capture token usage in SSE stream
  • cache_control breakpoints added to system and last user messages
  • 4-turn conversation on a single thread, capturing all LLM calls via mitmproxy

Baseline (Before Prompt Caching)

Turn Message prompt completion cached cache_created
1 "hello" 37,194 58 0 0
2 "What can you do for me?" 37,263 323 0 0

No caching — cached_tokens and cache_creation_tokens both zero on every call.

With Prompt Caching Enabled

Turn 1 — "hello" (1 LLM call)

prompt completion cached cache_created
Call 1 37,194 59 0 37,191

Fresh session, cache seeded — 37,191 tokens written to cache.

Turn 2 — "What can you do for me?" (1 LLM call)

prompt completion cached cache_created
Call 1 37,263 371 37,191 69

99.8% cache hit — 37,191 tokens read from cache, only 69 new tokens written.

Turn 3 — "Tell me about TestCloud features" (3 LLM calls — tool use)

prompt completion cached cache_created
Call 1 (tool decision) 37,643 118 37,260 380
Call 2 (tool result) 40,397 79 37,640 0
Call 3 (final answer) 40,903 408 37,640 0

Cache held across turns 2→3 — call 1 hit cache (37,260 tokens). All 3 calls within the turn benefited from caching.

Turn 4 — "How do I schedule a test run?" (1 LLM call — no tool use)

prompt completion cached cache_created
Call 1 41,343 316 37,640 3,700

Cache held across turns 3→4. Only 1 LLM call needed (agent answered directly without tool use). 37,640 tokens from cache, 3,700 new tokens written (accumulated conversation history).

Summary

  • System prompt (~37k tokens) is successfully cached on the first LLM call of each session
  • Subsequent calls within the same turn and across turns read from cache
  • Cache hit rate is ~99% of prompt tokens on follow-up calls
  • Only new conversation history tokens (few hundred) are written to cache on each turn
  • Multi-call turns (tool use) benefit from caching — calls 2+ within a turn always hit cache
  • Cache TTL held across all 4 turns — every call after turn 1 hit cache consistently
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment