Description
OpenRouter supports explicit prompt caching via cache_control breakpoints for Anthropic and Gemini models (docs). However, OpenRouterChatModel currently inherits the OpenAI base behavior which silently drops CachePoint items:
# In OpenAIChatModel._map_content_item:
elif isinstance(item, CachePoint):
# OpenAI doesn't support prompt caching via CachePoint, so we filter it out
return None
Since OpenRouterChatModel doesn't override _map_content_item, any CachePoint passed in messages is silently ignored — even when the underlying model (e.g. Anthropic via OpenRouter) supports it.
Expected behavior
OpenRouterChatModel should translate CachePoint into the cache_control format that OpenRouter expects, e.g.:
{"type": "text", "text": "...", "cache_control": {"type": "ephemeral"}}
This would allow users to benefit from cached token pricing (0.25x input cost) when using Anthropic or Gemini models through OpenRouter.
References
I'm willing to submit a PR for this myself if the proposal is accepted.
Description
OpenRouter supports explicit prompt caching via
cache_controlbreakpoints for Anthropic and Gemini models (docs). However,OpenRouterChatModelcurrently inherits the OpenAI base behavior which silently dropsCachePointitems:Since
OpenRouterChatModeldoesn't override_map_content_item, anyCachePointpassed in messages is silently ignored — even when the underlying model (e.g. Anthropic via OpenRouter) supports it.Expected behavior
OpenRouterChatModelshould translateCachePointinto thecache_controlformat that OpenRouter expects, e.g.:{"type": "text", "text": "...", "cache_control": {"type": "ephemeral"}}This would allow users to benefit from cached token pricing (0.25x input cost) when using Anthropic or Gemini models through OpenRouter.
References
pydantic_ai/models/openai.py—_map_content_itemfilters outCachePointI'm willing to submit a PR for this myself if the proposal is accepted.