Caché de prompts
NordRouter admite caché de prompts en los proveedores compatibles. Un prefijo repetido puede almacenarse automáticamente o marcarse con cache_control; los campos usage muestran tokens leídos y escritos en caché.
- Mantén iguales el prompt del sistema y el contexto largo, y cambia el último mensaje del usuario.
- El panel permite controlar el caché automático; usa marcas manuales cuando necesites límites precisos.
- El caché abarata solo la entrada reutilizada: no oculta solicitudes ni cambia el coste de los tokens de salida.
Ejemplos completos
A continuación se conservan todos los ejemplos ejecutables de la guía original. Ejecuta únicamente los bloques que correspondan a tu herramienta y sistema operativo.
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 nextDocumentación oficial y enlaces
| 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 |
Guías relacionadas
Comprueba primero la conexión con una solicitud de texto mínima. Después añade streaming, herramientas, imágenes u otras funciones avanzadas. Nunca incluyas la clave API en código público ni en un frontend del navegador.