Summary
Anthropic prompt caching is gated on a base_url string match ("openrouter" in base_url), so a Claude model served through a custom Anthropic-compatible endpoint silently loses caching.
Where
run_agent.py computes the gate in two places:
AIAgent.__init__ (~L386-389): self._use_prompt_caching = (is_openrouter and is_claude) or is_native_anthropic
- the provider-fallback recompute path (~L2650-2655): same
("openrouter" in fb_base_url.lower() and "claude" in fb_model.lower()) condition
self._use_prompt_caching is the sole gate on the cache_control marker (~L4335-4336).
Why it's wrong
gauss_cli/runtime_provider.py resolves Claude over chat_completions to custom endpoints (Z.ai / LiteLLM / self-hosted proxies, see _resolve_named_custom_runtime ~L122-128 and _resolve_openrouter_runtime ~L176-190). Those endpoints pass cache_control straight through to Anthropic, but because the base URL isn't OpenRouter the gate evaluates to False and caching is dropped — a ~75% input-cost regression on multi-turn runs for those users.
Repro
Run a Claude model (e.g. anthropic/claude-sonnet-4-...) against a custom chat_completions base URL such as http://localhost:8080/v1. agent._use_prompt_caching is False; no cache_control breakpoints are sent.
Suggested fix
Gate caching by provider capability (api_mode + Claude model) instead of a base_url substring, and apply it to both sites.
Summary
Anthropic prompt caching is gated on a base_url string match (
"openrouter" in base_url), so a Claude model served through a custom Anthropic-compatible endpoint silently loses caching.Where
run_agent.pycomputes the gate in two places:AIAgent.__init__(~L386-389):self._use_prompt_caching = (is_openrouter and is_claude) or is_native_anthropic("openrouter" in fb_base_url.lower() and "claude" in fb_model.lower())conditionself._use_prompt_cachingis the sole gate on thecache_controlmarker (~L4335-4336).Why it's wrong
gauss_cli/runtime_provider.pyresolves Claude overchat_completionsto custom endpoints (Z.ai / LiteLLM / self-hosted proxies, see_resolve_named_custom_runtime~L122-128 and_resolve_openrouter_runtime~L176-190). Those endpoints passcache_controlstraight through to Anthropic, but because the base URL isn't OpenRouter the gate evaluates toFalseand caching is dropped — a ~75% input-cost regression on multi-turn runs for those users.Repro
Run a Claude model (e.g.
anthropic/claude-sonnet-4-...) against a customchat_completionsbase URL such ashttp://localhost:8080/v1.agent._use_prompt_cachingisFalse; nocache_controlbreakpoints are sent.Suggested fix
Gate caching by provider capability (api_mode + Claude model) instead of a base_url substring, and apply it to both sites.