Agent skill · marketing growth · jeremylongshore

openrouter-caching-strategy

Implement caching for OpenRouter API responses to reduce cost and latency.

Why this skill is useful

Adds specific caching strategies and implementation details for optimizing OpenRouter API usage that the AI wouldn't reliably generate on its own.

What it needs

Requires python3, redis installed locally. Requires openrouter account access. About 5k tokens when loaded. Last updated 2026-08-07. 2,604 stars on the source repository.

What this skill does

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 as OPENROUTERAPIKEY — see the openrouter-install-auth skill for setup Python 3.8+ with the OpenAI SDK, plus the redis client 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:6379 for Persistent Cache with Redis (the in-memory LLMCache needs no infrastructure) Deterministic request settings — caching is only safe at temperature=0 Instructions 1. Confirm the requests you want to cache are deterministic (temperature=0); non-zero temperatures produce different outputs each call and must never be cached. 2. Start with the In-Memory Cache: LLMCache plus cachedcompletion() gives you TTL expiry and hit/miss counters in a single process. 3. For multi-instance deployments, switch to Persistent Cache with Redis — rediscachedcompletion() stores results under or:<sha256> keys with r.setex TTL expiry and falls through to a direct API call on a miss. 4. Build keys per Cache Key Design: include the model ID (with variants like :floor), messages, temperature, maxtokens, and topp; exclude stream and the HTTP-Referer/X-Title headers. 5. For large static system prompts (RAG context), add cachecontrol: {"type": "ephemeral"} per Anthropic Prompt Caching via OpenRouter — cache reads bill at 0.1x the input rate. 6. Wire the Cache Invalidation table: flush per-model keys on model version updates, flush everything on system prompt changes, and let TTL handle the rest. …

How to use it

Reference it in AdaL, Claude Code, Cursor or any coding agent — nothing to install:

@skills jeremylongshore/openrouter-caching-strategy--067efd

View the source on GitHub

Browse the @skills marketplace