Skip to content

Feature Request: Add Anthropic Prompt Caching Support for OpenRouter #14230

Description

@clawd-noca

Problem

Currently, OpenClaw uses OpenRouter to route to Anthropic models (Claude), but doesn't leverage Anthropic's prompt caching feature. This results in significantly higher costs - potentially 90% more than necessary.

Solution

Add support for Anthropic's cache_control breakpoints in messages sent through OpenRouter. This would allow OpenClaw to cache large static context blocks like:

  • System prompts
  • Workspace bootstrap files (SOUL.md, USER.md, AGENTS.md, etc.)
  • Memory search results
  • Large skill documentation

Implementation Details

Per OpenRouter's prompt caching docs, Anthropic caching is supported but requires explicit cache_control breakpoints in message content.

Example:

{
  "messages": [
    {
      "role": "system",
      "content": [
        {
          "type": "text",
          "text": "You are an assistant..."
        },
        {
          "type": "text",
          "text": "<large workspace context>",
          "cache_control": {
            "type": "ephemeral",
            "ttl": "1h"
          }
        }
      ]
    }
  ]
}

Cost Impact

  • Cache writes: 1.25x-2x base input price (depending on TTL)
  • Cache reads: 0.1x base input price (90% savings)

For typical OpenClaw usage with large system prompts and workspace context that stays constant across turns, this could reduce costs by 60-80% in practice.

Suggested Config

Add config options like:

{
  "agents": {
    "defaults": {
      "models": {
        "openrouter/anthropic/claude-sonnet-4.5": {
          "params": {
            "cacheRetention": "long", // "none" | "short" (5min) | "long" (1h)
            "cacheBreakpoints": ["system", "workspace", "memory"]
          }
        }
      }
    }
  }
}

References

User Impact

This feature would provide immediate cost savings for all users running Anthropic models through OpenRouter, especially those with:

  • Large workspace context files
  • Long-running sessions with stable system prompts
  • Frequent memory/KB searches

/cc @vincentnoca who originally requested this feature

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions