Skip to content

İstem önbelleği

NordRouter, destekleyen sağlayıcılarda istem önbelleğini kullanır. Yinelenen önekler otomatik önbelleğe alınabilir veya cache_control ile işaretlenebilir; usage alanları okunan ve yazılan önbellek tokenlarını gösterir.

  • Sistem istemini ve uzun bağlamı aynı tutup yalnızca son kullanıcı mesajını değiştirin.
  • Otomatik önbellek panelden yönetilir; kesin kontrol gerekiyorsa elle işaretleme kullanın.
  • Önbellek yalnızca yeniden kullanılan girdiyi ucuzlatır; çıktı tokenlarının ücretini değiştirmez.

Eksiksiz örnekler

Özgün kılavuzdaki çalıştırılabilir örneklerin tamamı aşağıda korunmuştur. Yalnızca kullandığınız araç ve işletim sistemiyle ilgili blokları çalıştırın.

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

Resmi belgeler ve bağlantılar

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

İlgili kılavuzlar

Önce en küçük metin isteğiyle bağlantıyı doğrulayın; ardından akış, araç çağrıları, görseller ve diğer gelişmiş özellikleri ekleyin. API anahtarını herkese açık koda veya tarayıcı ön yüzüne koymayın.

Sorun giderme