프롬프트 캐싱
NordRouter는 지원 공급자에서 프롬프트 캐시를 사용합니다. 반복되는 앞부분은 자동 또는 cache_control로 캐시되며 usage에 cache read/write 토큰이 표시됩니다.
- 시스템 프롬프트와 긴 문맥은 유지하고 마지막 사용자 메시지만 바꾸세요.
- 자동 캐시는 대시보드에서 관리하고 정밀 제어에는 수동 표시를 사용하세요.
- 캐시는 재사용 입력 비용만 줄이며 출력 토큰 비용은 바꾸지 않습니다.
전체 예제
원본 가이드의 실행 가능한 예제를 모두 아래에 보존했습니다. 사용 중인 도구와 운영체제에 해당하는 블록만 실행하세요.
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 |
관련 가이드
먼저 최소 텍스트 요청으로 연결을 확인한 다음 스트리밍, 도구 호출, 이미지와 같은 고급 기능을 추가하세요. API 키를 공개 코드나 브라우저 프런트엔드에 넣지 마세요.