کشکردن پرامپت
NordRouter برای سرویسهای پشتیبانیشده از prompt caching استفاده میکند. پیشوند تکراری خودکار یا با cache_control ذخیره میشود و usage توکنهای خوانده و نوشتهشده را نشان میدهد.
- پرامپت سیستم و متن طولانی را ثابت نگه دارید و پیام آخر را عوض کنید.
- کش خودکار از پنل کنترل میشود؛ برای کنترل دقیق از نشانهگذاری دستی استفاده کنید.
- کش فقط هزینهٔ ورودی تکراری را کم میکند، نه توکن خروجی را.
نمونههای کامل
همهٔ نمونههای قابل اجرای راهنمای اصلی در ادامه حفظ شدهاند. فقط بلوک متناسب با ابزار و سیستمعامل خود را اجرا کنید.
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مستندات رسمی و پیوندها
| Operation | Multiplier | When it's charged |
|---|---|---|
| Write (cache-write) | ×1.25 | the first time the context enters the cache |
| Read (cache-read) | ×0.1 (−90%) | every repeat of the same context |
| No cache | With cache | |
|---|---|---|
| What's billed | 10 × 30k input | 1 write + 9 reads |
| Input cost | ~$0.46 | ~$0.10 |
راهنماهای مرتبط
ابتدا اتصال را با یک درخواست متنی کوچک بررسی کنید؛ سپس streaming، فراخوانی ابزار، تصویر و قابلیتهای پیشرفته را اضافه کنید. کلید API را در کد عمومی یا frontend مرورگر قرار ندهید.