19 April 2026
التخزين المؤقت في Claude: وفّر 90% من تكاليف API — Claude Prompt Caching: Cut API Costs by 90%Arabic
Arabic
التخزين المؤقت في Claude: وفّر 90% من تكاليف API
ما هو Prompt Caching؟
ميزة مدفونة في Claude API تخزّن النصوص الطويلة مرة واحدة، وتعيد استخدامها في كل طلب لاحق بدلاً من إرسالها من الصفر. النتيجة: توفير يصل إلى 90% في التكلفة وسرعة أعلى.
لماذا تهمك؟
إذا كنت تبني تطبيقاً يستخدم Claude وعندك system prompt طويل، أو وثائق، أو سياق ثابت — فأنت تدفع ثمنه في كل طلب. هذا مضيعة حقيقية.
الخطوة 1: افهم كيف يعمل
Claude يدعم "cache breakpoints" — نقاط تخبر النموذج: "احفظ كل ما قبل هذه النقطة". في الطلب الأول يُخزَّن السياق. من الطلب الثاني فصاعداً، تدفع فقط 10% من سعر الـ input tokens المخزّنة.
الخطوة 2: أضف cache_control في الكود
في Python SDK:
client.messages.create(
model="claude-opus-4-7",
system=[{
"type": "text",
"text": "أنت مساعد ذكي... [نص طويل]",
"cache_control": {"type": "ephemeral"}
}],
messages=[{"role": "user", "content": "سؤالك هنا"}]
)
السطر الوحيد المضاف: cache_control — هذا كل شيء.
الخطوة 3: اعرف ما يمكن تخزينه
- System prompts الطويلة
- وثائق أو PDFs محوّلة لنص
- أمثلة Few-shot طويلة
- قوائم قواعد أو تعليمات ثابتة
الشرط: المحتوى المخزّن يجب أن يكون 1024 token أو أكثر.
الخطوة 4: راقب النتائج
في الـ response ستجد:
usage.cache_creation_input_tokens — tokens خُزِّنت
usage.cache_read_input_tokens — tokens أُعيد استخدامها (هذه الرخيصة)
متى تتوقع التوفير؟
الطلب الأول: لا توفير (يبني الـ cache)
من الطلب الثاني: توفير فوري
الـ cache يبقى 5 دقائق افتراضياً — مثالي للمحادثات المتتالية.
مثال عملي:
بدون cache: 10,000 token × 100 طلب = مليون token تدفع عنها
مع cache: تدفع مليون token مرة، ثم 10% فقط على الـ 99 طلب الباقية.
التوفير = 90% تقريباً.
من @mabuzant — تابعني للمزيد
--- English ---
Claude Prompt Caching: Cut API Costs by 90%
What Is Prompt Caching?
A buried Claude API feature that stores long context once, then reuses it across subsequent calls instead of resending it every time. Result: up to 90% cost reduction and faster responses.
Why It Matters
If you're building with Claude and have a long system prompt, documents, or fixed context — you're paying full price on every single request. That's wasted money.
Step 1: Understand How It Works
Claude supports cache breakpoints — markers that tell the model: "store everything before this point." First request builds the cache. Every request after pays only 10% of the normal input token price for cached content.
Step 2: Add cache_control to Your Code
In Python SDK:
client.messages.create(
model="claude-opus-4-7",
system=[{
"type": "text",
"text": "You are an assistant... [long text]",
"cache_control": {"type": "ephemeral"}
}],
messages=[{"role": "user", "content": "Your question"}]
)
One added line: cache_control — that's literally it.
Step 3: Know What to Cache
- Long system prompts
- Documents or converted PDFs
- Lengthy few-shot examples
- Fixed rules or instruction lists
Requirement: cached content must be 1024 tokens or more.
Step 4: Monitor Your Savings
In the API response look for:
usage.cache_creation_input_tokens — tokens stored
usage.cache_read_input_tokens — tokens reused (these are cheap)
When to Expect Savings
First request: no savings (builds the cache)
Second request onward: immediate savings
Cache lasts 5 minutes by default — ideal for ongoing conversations.
Real Example:
Without cache: 10,000 tokens × 100 requests = 1M tokens billed
With cache: pay for 1M tokens once, then 10% on the remaining 99 requests.
Savings = roughly 90%.
From @mabuzant — follow for weekly AI content
Liked this guide?
Join Mohammad's community
72 guides like this one, and a new one every week. One subscription opens them all.
$68/ month
Approximate price in your currency. You pay in AED
- A permanent archive. Open any guide, any time
- 20% off private build sessions
- Cancel any time, no commitment
Or without a subscription
Secure, encrypted payment via Stripe
By completing payment, you agree to the refund and cancellation policyMost value
Start building with me now
We sit together, break down your problem, and I build the AI solution with you step by step
60minutes
- A private session with you
- Real building during the session
- Results you take with you when we finish
100% free
A free consultation about your problem