Skip to content

Prompt caching disabled for Claude on custom (non-OpenRouter) endpoints #454

Description

@sumleo

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions