The OpenRouter API supports cache_control on tool definitions for Anthropic prompt caching (announced in Tool Caching), but the Python SDK's ToolDefinitionJSON model only has function and type fields.
When a dict containing cache_control is passed through the SDK's serialization layer, the field is silently stripped.
import openrouter
client = openrouter.OpenRouter(api_key="...")
client.chat.send(
model="anthropic/claude-sonnet-4-5",
messages=[...],
tools=[
{
"type": "function",
"function": {"name": "search", "description": "Search the web", "parameters": {...}},
"cache_control": {"type": "ephemeral"}, # <-- stripped by SDK before reaching API
}
],
)
The SDK correctly models cache_control on ChatMessageContentItemText (message-level caching works), but the same field is missing from ToolDefinitionJSON.
Expected behavior
cache_control should be preserved on tool definitions and sent to the API, matching the behavior already implemented for message content items.
Suggested fix
Add an optional cache_control field to ToolDefinitionJSON (or its OpenAPI source schema), consistent with ChatMessageContentItemText.cache_control:
class ToolDefinitionJSON(BaseModel):
function: ToolDefinitionJSONFunction
TYPE: Literal["function"] = "function"
cache_control: Optional[ChatMessageContentItemCacheControl] = None # <-- add this
SDK version
openrouter==0.6.0
Additional context
- The OpenRouter API spec at
/docs/api/api-reference/chat/send-chat-completion-request does not currently include cache_control on ToolDefinitionJson either, so this likely needs an OpenAPI spec update before SDK regeneration.
ChatMessageContentItemCacheControl (with type: "ephemeral" and optional ttl) already exists in the SDK and can be reused.
The OpenRouter API supports
cache_controlon tool definitions for Anthropic prompt caching (announced in Tool Caching), but the Python SDK'sToolDefinitionJSONmodel only hasfunctionandtypefields.When a dict containing
cache_controlis passed through the SDK's serialization layer, the field is silently stripped.The SDK correctly models
cache_controlonChatMessageContentItemText(message-level caching works), but the same field is missing fromToolDefinitionJSON.Expected behavior
cache_controlshould be preserved on tool definitions and sent to the API, matching the behavior already implemented for message content items.Suggested fix
Add an optional
cache_controlfield toToolDefinitionJSON(or its OpenAPI source schema), consistent withChatMessageContentItemText.cache_control:SDK version
openrouter==0.6.0Additional context
/docs/api/api-reference/chat/send-chat-completion-requestdoes not currently includecache_controlonToolDefinitionJsoneither, so this likely needs an OpenAPI spec update before SDK regeneration.ChatMessageContentItemCacheControl(withtype: "ephemeral"and optionalttl) already exists in the SDK and can be reused.