Conversation
The LiteLLM and OpenAI-Compatible provider entries carry no prompt-cache routing metadata, so `resolvePromptCacheRoute` never resolves a route for them and `cache_control` is never attached to message content. Anthropic models proxied through either provider report zero cache read/write tokens on every request, no matter how large the context, and there is no setting that turns it on. Give both providers the same Anthropic cache-control routing the other pass-through aggregators already declare. The route matches only Anthropic-lineage model ids, so non-Claude models on these providers are untouched. LiteLLM also gets the Qwen route, which still requires the catalog `prompt-cache` capability that its `/model/info` response supplies. Fixes cline#13667
Contributor
|
PR author is not in the allowed authors list. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related Issue
Issue: #13667
Description
Requests sent to Anthropic models through the LiteLLM and OpenAI-Compatible providers never include
cache_control, so Anthropic prompt caching never engages —cacheReadTokens/cacheWriteTokensare 0 on every request regardless of context size.resolvePromptCacheRouteattaches cache markers only when the provider manifest declaresmetadata.routing.promptCache. Thelitellmandopenai-compatibleentries insdk/packages/llms/src/providers/builtins.tsdeclare no routing metadata at all, so the route never resolves andapplyPromptCacheToLastTextPartis never reached. The other pass-through aggregators —openrouter,vercel-ai-gateway,aihubmix— already declare it, which is why caching works there.This gives both providers the same Anthropic cache-control routing:
litellm→ANTHROPIC_AND_QWEN_CACHE_ROUTING_METADATA. LiteLLM forwardscache_controlto the upstream Anthropic/Bedrock deployment, and its/v1/model/inforesponse already populates the catalogprompt-cachecapability that the Qwen route requires (fetchLiteLlmPrivateModelsmapssupports_prompt_caching).openai-compatible→ANTHROPIC_ROUTING_METADATA. Custom endpoints pointed at Anthropic models get caching; the Qwen route is omitted because this provider has no model catalog to supply theprompt-cachecapability it requires, so it could never resolve.Both routes match only Anthropic-lineage model ids, so non-Claude models on these providers are unaffected. No new user-facing setting: this follows the metadata-driven routing the SDK already uses for the other aggregators rather than reviving a per-provider toggle. The orphaned
liteLlmUsePromptCachefield noted in the issue stays unused; removing it is a separate cleanup.Usage read-back needed no change —
normalizeUsageinai-sdk.tsalready readsprompt_tokens_details.cached_tokensandcache_creation_input_tokens, which is what LiteLLM returns.Test Procedure
Added to
sdk/packages/llms/src/providers/gateway.test.ts, following the existing prompt-cache routing tests:forwards Anthropic prompt cache controls for $providerId— parameterized overlitellmandopenai-compatible, assertscache_control: { type: "ephemeral" }lands on the user content part in the provider'sproviderOptionsbucket forbedrock/converse/eu.anthropic.claude-sonnet-5(the model id from the report). Both cases fail onmainand pass with this change.keeps prompt cache controls off non-Anthropic $providerId models— same providers withgpt-4o, asserts nocache_controlanywhere in the request. Guards the blast radius of enabling routing on the generic provider.keeps Anthropic cache-control routing on the expected provider set, the catalog-level assertion that enumerates which providers carryanthropic-cache-controlrouting.Reasoning routing is unchanged in effect: before this change these providers fell through
resolveUnroutedAnthropicReasoningRoute, which gave Anthropic-lineage models theanthropic-compatiblereasoning route; the explicit metadata now declares the same route for the same set.Ran locally (Bun 1.4.2, Node 22.14):
@cline/llms— 876 passed, 4 skipped@cline/core— 2431 passed; 11 pre-existing failures insrc/hub/server/boundary.test.tsandsrc/session/search/session-history-search.test.ts, verified identical on an unmodified treeapps/vscodebun run test:unit— 1121 passed@cline/cli1202,@cline/shared420,@cline/agents87,@cline/cline-hub111,@cline/vscode4 — all passingbun run lintandbun run types— cleanType of Change
Pre-flight Checklist
bun test) and code is formatted and linted (bun run format && bun run lint)Additional Notes
I have not been able to test against a live LiteLLM proxy — verification is the unit tests plus tracing the
@ai-sdk/openai-compatiblepassthrough (getOpenAIMetadataspreadsproviderOptions.openaiCompatibleonto each content part, which is whatcreatePromptCacheProviderOptionssets).