openrouter-caching-strategy
Installation
SKILL.md
OpenRouter Caching Strategy
Overview
OpenRouter charges per token, so caching identical or similar requests can dramatically cut costs. Deterministic requests (temperature=0) with the same model and messages produce identical outputs -- these are safe to cache. This skill covers in-memory caching, persistent caching with TTL, and Anthropic prompt caching via OpenRouter.
Prerequisites
- An OpenRouter API key (
sk-or-v1-...) exported asOPENROUTER_API_KEY— see theopenrouter-install-authskill for setup - Python 3.8+ with the OpenAI SDK, plus the
redisclient package for the persistent cache; Node.js 18+ with the OpenAI SDK for the TypeScript variant in the references - A Redis server reachable at
localhost:6379for Persistent Cache with Redis (the in-memoryLLMCacheneeds no infrastructure) - Deterministic request settings — caching is only safe at
temperature=0