Cut Cost up to 90% with Prompt Caching
Cache stable system prompts, large few-shot blocks, and long documents to slash input cost.
Şükrü Yusuf KAYA
11 min read
IntermediateCache Anatomisi
Prompt'un hangi bölümünü cache'leyeceğini ile işaretlersin. İlk çağrıda 'cache write' biraz pahalı; sonraki çağrılar bu kısım için %90'a varan tasarruf.
cache_controlpython
resp = client.messages.create( model="claude-sonnet-4-6", max_tokens=1024, system=[ { "type":"text", "text": LONG_STABLE_SYSTEM_PROMPT, "cache_control": {"type":"ephemeral"}, }, ], messages=[{"role":"user","content": user_text}],)# response.usage içinde cache_read_input_tokens / cache_creation_input_tokens alanları olurSystem prompt cache — en yaygın kullanım.
python
# Cache hit oranı simülasyonutotal_in = 0cached_in = 0calls = [ {"input": 1200, "cached": 0}, # ilk çağrı, cache miss {"input": 1200, "cached": 1100}, # cache hit {"input": 1200, "cached": 1100}, {"input": 1200, "cached": 1100},]for c in calls: total_in += c["input"] cached_in += c["cached"] print(f"Cache hit oranı: {cached_in/total_in*100:.1f}%")Cache hit oranı — yüksek tut, maliyetin sahibi sen ol.
Boşluk doldur · text
Cache _____ flag'i ile sistem promptunun bölümleri cache'lenir. Tipik _____ TTL kısa, dakikalar mertebesindedir. Hit oranını izlemek için response _____ alanı kullanılır.Frequently Asked Questions
Structurally separate variable bits from the system prompt. Move customer name and language outside the cache; keep role, rules, glossary inside.
Yorumlar & Soru-Cevap
(0)Yorum yazmak için giriş yap.
Yorumlar yükleniyor...