Skip to content

sbroms2/tanstack-ai-openrouter-cachecontrol-repro

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Repro: @tanstack/ai-openrouter drops tool-definition cacheControl

Minimal, deterministic reproduction — no network call, no API key. It shows that the OpenRouter adapter's function-tool converter discards a tool's metadata.cacheControl, so Anthropic prompt caching of tool definitions can never reach the wire.

Run

npm install
node repro.mjs

Expected output

1) converter output:         {"type":"function","function":{...}}                       <- no cacheControl  (BUG)
2) serialized wire tool:     {"function":{...},"type":"function"}                        <- no cache_control (consequence)
3) wire tool WITH forward:   {"cache_control":{"type":"ephemeral"},"function":{...}}     <- present once forwarded
  • (1) convertToolsToProviderFormat never reads tool.metadata.cacheControl, so the marker is gone before serialization.
  • (2) Running the request through the SDK's ChatRequest$outboundSchema confirms nothing reaches the wire.
  • (3) Manually adding cacheControl (camelCase) to the converter output makes the SDK emit cache_control — proving the @openrouter/sdk already supports it and the converter is the only gap. (Snake_case cache_control is stripped by the SDK's outbound schema, so the camelCase key is required.)

@tanstack/ai-anthropic's convertCustomToolToAdapterFormat already forwards metadata.cacheControl; ai-openrouter should match.

Versions

@tanstack/ai 0.34.0 · @tanstack/ai-openrouter 0.14.2 · @openrouter/sdk 0.12.35 · Node v24

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors