तकनीकी mechanism: LLM inference की "prefill" चरण के दौरान, model सभी input tokens को process करता है और उनकी KV cache entries की गणना करता है। Prompt caching इस KV cache को स्टोर करती है ताकि समान prefix वाले बाद के requests cached portion के लिए prefill को skip कर सकें। केवल नए tokens (उपयोगकर्ता का वास्तविक संदेश) को processing की आवश्यकता होती है। Anthropic, OpenAI, और Google सभी prompt caching का कोई न कोई रूप प्रदान करते हैं।
अधिकांश implementations matching prefixes का स्वचालित रूप से पता लगाकर या आपको cache breakpoints चिह्नित करने देकर काम करते हैं। मुख्य constraint: केवल exact prefix matches ही गिने जाते हैं। यदि आपका system prompt एक token से भी बदलता है, तो cache miss होता है। इसका मतलब है कि अपने prompts को stable parts पहले (system prompt, documents) और variable parts बाद में (user message) के साथ संरचित करना cache hit rates के लिए महत्वपूर्ण है।
Prompt caching सबसे बड़ी बचत तब देती है जब: (1) आपके पास एक लंबा, स्थिर prefix हो (बड़े system prompts, RAG context), (2) आप उसी prefix के साथ कई requests भेजते हैं (chatbots, agents), और (3) input tokens आपकी costs का महत्वपूर्ण हिस्सा हैं। छोटे, unique prompts वाले applications के लिए, caching कम लाभ देती है। Context window को documents से भरने वाले applications के लिए, यह transformative है।