สถานะ: 🟢 Complete | อัพเดท: 2026-06-27
Prompt Caching — ลด Cost และ Latency
คืออะไร
Prompt caching ให้ Claude cache ส่วนของ prompt ที่ไม่เปลี่ยน — request ต่อไปใช้ cache แทนประมวลผลใหม่
ประหยัดเท่าไหร่
- Cost: Cache hit ถูกกว่า input tokens ปกติ ~90%
- Latency: Cache hit เร็วกว่าอย่างเห็นได้ชัด โดยเฉพาะ prompt ยาว
วิธีใช้ (API)
messages = client.messages.create(
model="claude-sonnet-4-6",
system=[{
"type": "text",
"text": "...long system prompt...",
"cache_control": {"type": "ephemeral"} # mark for caching
}],
messages=[{"role": "user", "content": "คำถาม"}]
)Cache TTL
Cache อยู่นาน 5 นาที (ephemeral) — ถ้า request ถี่กว่านั้น cache hit rate สูง
เหมาะกับอะไร
Long system prompts, เอกสารอ้างอิงขนาดใหญ่, few-shot examples จำนวนมาก