openclaw - 💡(How to fix) Fix Feature: expose OpenRouter provider preference/pinning in model config [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#62992Fetched 2026-04-09 07:59:45
View on GitHub
Comments
0
Participants
1
Timeline
0
Reactions
0
Author
Participants

OpenRouter supports a provider field in the request body to control which backend handles the request (e.g. force Anthropic direct, or prefer Bedrock). OpenClaw does not expose this as a configurable model param, making it impossible to pin OR requests to a stable backend for prompt cache reuse.

Root Cause

Without this, cacheRetention on OR is effectively useless for large contexts (100K+) because OR load-balances across backends that don't share cache. Every turn costs full input price instead of cache-read price.

Code Example

{
  "provider": {
    "order": ["Anthropic"],
    "allow_fallbacks": false
  }
}

---

agents:
  defaults:
    models:
      "openrouter/anthropic/claude-opus-4-6":
        params:
          cacheRetention: "short"
          providerPreference:
            order: ["Anthropic"]
            allowFallbacks: false
RAW_BUFFERClick to expand / collapse

Summary

OpenRouter supports a provider field in the request body to control which backend handles the request (e.g. force Anthropic direct, or prefer Bedrock). OpenClaw does not expose this as a configurable model param, making it impossible to pin OR requests to a stable backend for prompt cache reuse.

Problem

When OR routes consecutive requests to different backends (e.g. Bedrock node A → Bedrock node B, or Bedrock → Anthropic direct), each request gets a cold cache. Prompt cache hit rate drops to near zero even with cacheRetention: "short" set.

Observed: OR Sonnet and Opus sessions cycling between Amazon Bedrock instances — cache stays at 23,535 tokens (system prompt only) instead of 100K+. When OR happens to stick to one backend for 2-3 consecutive requests, cache builds to 100%.

OpenRouter API

OR supports provider preferences natively:

{
  "provider": {
    "order": ["Anthropic"],
    "allow_fallbacks": false
  }
}

This pins the request to Anthropic direct (not Bedrock/Google), enabling proper prompt cache reuse.

Requested config

agents:
  defaults:
    models:
      "openrouter/anthropic/claude-opus-4-6":
        params:
          cacheRetention: "short"
          providerPreference:
            order: ["Anthropic"]
            allowFallbacks: false

Or alternatively, a simpler preferDirect: true shorthand that maps to {"order": ["Anthropic"], "allow_fallbacks": false} for Anthropic model refs.

Impact

Without this, cacheRetention on OR is effectively useless for large contexts (100K+) because OR load-balances across backends that don't share cache. Every turn costs full input price instead of cache-read price.

With Anthropic direct pinning: cache builds in 1-3 turns and stays warm, reducing per-turn cost by ~10× at 170K context.

Environment

  • OpenClaw 4.5 (3e72c03)
  • Model: openrouter/anthropic/claude-opus-4-6 and openrouter/anthropic/claude-sonnet-4-6
  • Context size: 107K–173K tokens
  • cacheRetention: "short" configured but ineffective due to backend switching

Related

Follows from #62974 (cache-aware sticky fallback). Even with sticky fallback, if OR itself load-balances across backends, cache will still bounce.

extent analysis

TL;DR

To fix the issue, add a providerPreference parameter to the model configuration to pin requests to a specific backend, such as Anthropic direct, allowing for proper prompt cache reuse.

Guidance

  • Add a providerPreference section to the model configuration with order set to ["Anthropic"] and allowFallbacks set to false to pin requests to Anthropic direct.
  • Alternatively, use the proposed preferDirect: true shorthand to achieve the same effect.
  • Verify that the cache hit rate improves and the cache size increases to the expected range (100K+) after implementing the fix.
  • Test the configuration with consecutive requests to ensure that the cache is properly reused.

Example

agents:
  defaults:
    models:
      "openrouter/anthropic/claude-opus-4-6":
        params:
          cacheRetention: "short"
          providerPreference:
            order: ["Anthropic"]
            allowFallbacks: false

Notes

The proposed fix relies on the providerPreference parameter being supported by the OpenRouter API and the OpenClaw configuration. If this parameter is not supported, alternative solutions may need to be explored.

Recommendation

Apply the workaround by adding the providerPreference parameter to the model configuration, as this is the most direct way to address the issue and improve cache reuse.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING