npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

n8n-nodes-openrouter-cache-chat-model

v0.2.0

Published

OpenRouter Chat Model with prompt caching support for n8n AI Agent workflows

Downloads

51

Readme

n8n-nodes-openrouter-cache

OpenRouter Chat Model node for n8n with prompt caching support. Drop-in replacement for the built-in OpenRouter Chat Model that injects cache_control markers to reduce costs up to 90% on Anthropic and Gemini models.

Features

  • Prompt caching for Anthropic and Gemini models via OpenRouter (system message + optional last user message)
  • Configurable TTL: 5-minute default or 1-hour extended cache
  • Cache breakpoints: System message only, or system + last user message
  • Caching enabled by default — the whole point of this node
  • Tool call fix preserved from upstream (fixes empty arguments from Anthropic-via-OpenRouter)
  • Uses existing openRouterApi credential — no extra setup

Install

In your n8n instance:

  1. Go to Settings → Community Nodes
  2. Click Install
  3. Enter n8n-nodes-openrouter-cache-chat-model
  4. Click Install

Usage

  1. Add the OpenRouter Cache Chat Model node to your workflow
  2. Connect it to an AI Agent or AI Chain node
  3. Select your model (e.g., anthropic/claude-sonnet-4-20250514 or google/gemini-2.5-flash)
  4. Caching is enabled by default — configure under Options if needed

Options

| Option | Default | Description | |--------|---------|-------------| | Enable Prompt Caching | true | Toggle caching on/off | | Cache TTL | 5 Minutes | 5 Minutes or 1 Hour (1h has 2x write cost on Anthropic) | | Cache Breakpoints | System Message Only | System Message Only or System + Last User Message |

How it works

The node wraps the standard ChatOpenAI from LangChain with a custom fetch interceptor that:

  1. Intercepts outgoing API requests
  2. Transforms system message content from string to content blocks with cache_control: { type: "ephemeral" }
  3. Optionally marks the last user message for caching too
  4. Sends the modified request to OpenRouter

On the response side, it also fixes empty tool call arguments (a known issue with Anthropic models via OpenRouter).

Which models benefit?

| Provider | Caching | Notes | |----------|---------|-------| | Anthropic (Claude) | Explicit — this node adds it | Min 1024-4096 tokens depending on model | | OpenAI (GPT) | Automatic | No modification needed, but node won't break anything | | DeepSeek | Automatic | Same as OpenAI | | Google (Gemini 2.5) | Explicit — this node adds it | Min 1,028 tokens (Flash) / 2,048 tokens (Pro). Fixed ~3-5min TTL |

Verifying cache hits

Check the OpenRouter Activity dashboard after running your workflow twice:

  • First run: cache_write_tokens > 0 (cache established)
  • Second run: cached_tokens > 0 (cache hit, reduced cost)

Development

npm install
npm run build

For local testing, copy dist/ to your n8n custom nodes directory:

cp -r dist/ ~/.n8n/custom/node_modules/n8n-nodes-openrouter-cache-chat-model/dist/
cp package.json ~/.n8n/custom/node_modules/n8n-nodes-openrouter-cache-chat-model/

License

MIT