Skip to content

प्रॉम्प्ट कैशिंग

NordRouter समर्थित providers में prompt cache उपयोग करता है। दोहराया prefix अपने-आप या cache_control से cache हो सकता है; usage में cache read और write tokens दिखते हैं।

  • System prompt और लंबा context समान रखें, केवल अंतिम user message बदलें।
  • Automatic cache को dashboard से नियंत्रित करें; सटीक नियंत्रण के लिए manual marker उपयोग करें।
  • Cache केवल दोबारा उपयोग हुए input की लागत घटाता है, output tokens की नहीं।

पूरे उदाहरण

मूल गाइड के सभी चलने योग्य उदाहरण नीचे सुरक्षित रखे गए हैं। केवल अपने टूल और ऑपरेटिंग सिस्टम से संबंधित ब्लॉक चलाएँ।

json
"usage": {
  "prompt_tokens": 21364,
  "prompt_tokens_details": {
    "cached_tokens": 21361     // ← read from cache at ×0.1
  },
  "completion_tokens": 40
}
bash
curl https://nordrouter.com/v1/messages \
  -H "x-api-key: sk-nr-YOUR-KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{
    "model": "anthropic/claude-fable-5",
    "max_tokens": 512,
    "system": [
      {
        "type": "text",
        "text": "You are an assistant for our documentation. Here is the reference: <...lots of text...>",
        "cache_control": { "type": "ephemeral" }
      }
    ],
    "messages": [{ "role": "user", "content": "First question about the reference?" }]
  }'
python
from anthropic import Anthropic

client = Anthropic(base_url="https://nordrouter.com", api_key="sk-nr-YOUR-KEY")

resp = client.messages.create(
    model="anthropic/claude-fable-5",
    max_tokens=512,
    system=[{
        "type": "text",
        "text": "You are an assistant for our documentation. Here is the reference: <...>",
        "cache_control": {"type": "ephemeral"},   # cache the reference
    }],
    messages=[{"role": "user", "content": "First question about the reference?"}],
)
print(resp.usage)  # cache_creation_input_tokens on the 1st request, cache_read on the next

आधिकारिक दस्तावेज़ और लिंक

OperationMultiplierWhen it's charged
Write (cache-write)×1.25the first time the context enters the cache
Read (cache-read)×0.1 (−90%)every repeat of the same context
No cacheWith cache
What's billed10 × 30k input1 write + 9 reads
Input cost~$0.46~$0.10

संबंधित गाइड

पहले न्यूनतम text request से कनेक्शन जाँचें, फिर streaming, tool calls, images और दूसरी advanced सुविधाएँ जोड़ें। API key को public code या browser frontend में कभी न रखें।

समस्या निवारण