You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
applyCaching called too freely, causes LiteLLM to fail #6473
litellm.BadRequestError: Vertex_aiException BadRequestError - b'{"type":"error","error":{"type":"invalid_request_error","message":"invalid beta flag"},"request_id":"req_vrtx_011CWdZLV7UDvRZBkvyfXcKJ"}'. Received Model Group=claude-opus-4.1
Available Model Group Fallbacks=None
Even though my model has claude in the name I am explicitly saying it is an openai provider with "npm": "@ai-sdk/openai-compatible". In this case I am using LiteLLM proxy to front all LLM access and it does not support the added "cache_control" key this injects to every message.
Some possible solutions that could be done:
config option to disable the applyCaching functionality, either per model or provider
(... existing ors) && model.api.npm !== "@ai-sdk/openai-compatible" be added to the if statement logic there. Though I am not sure if that is the best approach or if it should apply to other providers as well.
OpenCode version
1.0.212
Steps to reproduce
Setup LiteLLM in front of Anthropic models where model id includes claude or anthropic
Setup a custom provider in opencode using LiteLLM as a @ai-sdk/openai-compatible provider
call on a model and it fails due to injected cache keys in messages array.
For anyone else hitting this, this plugin will work (for now at least) since the model.api.id is used primarily before this event hook is called so if we change it during this stage the applyLogic comes after.
This could break something in the future but it works as a patch for me now.
importtype{Plugin}from"@opencode-ai/plugin";exportconstPatchCachingBug: Plugin=async()=>{return{async"chat.params"(input){constmodel=input.model;// Only touch the specific bad combo: OpenAI-compatible / gateway model// whose api.id contains "claude" but is NOT actually Anthropic.if(model.providerID!=="anthropic"&&model.api.npm!=="@ai-sdk/anthropic"&&typeofmodel.api.id==="string"&&(model.api.id.includes("claude")||model.api.id.includes("anthropic"))){// Strip the "claude" substring so ProviderTransform.message// does not enter the Anthropic caching branch.model.api.id=model.api.id.replace(/claude/gi,"cl4ude");}},};};
I think litellm has a flag to drop unsupported parameters, dmed person that wrote that code originally
I don't have full control over this particular LiteLLM instance myself so I can't easily get this option added yet.
Reacted by Nicolas Iderhoff, Arvind Prasad, fire and Matt Flowers
Well the above plugin no longer works, either the execution order changed or something. Pretty annoying, don't feel like trying to fix it again.
Upstream litellm has not fixed this yet either with drop params. I've resorted to running a full litellm proxy locally just to alias the names of the models that cause issues. Litellm team said they added this to their backlog so just waiting for it to get fixed there.
I'm seeing the same issue: any custom model whose id contains "claude"/"anthropic" triggers applyCaching and injects cache_control into messages, which LiteLLM/OpenAI-compatible proxies reject (400 invalid_request_error / LiteLLM General Error).\n\nThis also makes a plugin workaround impossible now because the caching injection happens inside ProviderTransform.message() before any accessible plugin hooks run (chat.params runs later and experimental.chat.messages.transform can't affect the model id). So a plugin can't prevent applyCaching or strip cache_control early enough.\n\nNet: LiteLLM/OpenAI-compatible usage is broken for these model ids unless you rename/alias the model or patch core.
Yeah I think we need some better approach internally, note that a plugin can still strip them out, it's kinda weird but you can override the fetch implementation for any provider and it could strip out the things, example fetch being overriden:
Hey @rekram1-node, thanks for the fetch-override suggestion — it worked for me.
I had to hook the provider ID that actually owns the OpenAI-compatible/LiteLLM proxy (redacted below), and make sure auth exists for that provider so the loader runs. After that, stripping cache_control before the request goes out fixed the 400s.
Here’s the working plugin (provider name redacted):
I will close this out for now as I agree it is sort of not an opencode issue directly and is more an issue with so many different providers and proxies handling calls and payloads differently
Activity
github-actions commentedon Dec 30, 2025
This issue might be a duplicate of existing issues. Please check:
Feel free to ignore if none of these address your specific case.
rekram1-node commentedon Dec 30, 2025
I think litellm has a flag to drop unsupported parameters, dmed person that wrote that code originally
RingOfStorms commentedon Dec 31, 2025
For anyone else hitting this, this plugin will work (for now at least) since the model.api.id is used primarily before this event hook is called so if we change it during this stage the applyLogic comes after.
This could break something in the future but it works as a patch for me now.
I don't have full control over this particular LiteLLM instance myself so I can't easily get this option added yet.
RingOfStorms commentedon Jan 22, 2026
Well the above plugin no longer works, either the execution order changed or something. Pretty annoying, don't feel like trying to fix it again.
Upstream litellm has not fixed this yet either with drop params. I've resorted to running a full litellm proxy locally just to alias the names of the models that cause issues. Litellm team said they added this to their backlog so just waiting for it to get fixed there.
rekram1-node commentedon Jan 22, 2026
Ah, the plugin still runs it's the code that changed internally that makes it not take affect
hendem commentedon Jan 22, 2026
I'm seeing the same issue: any custom model whose id contains "claude"/"anthropic" triggers applyCaching and injects cache_control into messages, which LiteLLM/OpenAI-compatible proxies reject (400 invalid_request_error / LiteLLM General Error).\n\nThis also makes a plugin workaround impossible now because the caching injection happens inside ProviderTransform.message() before any accessible plugin hooks run (chat.params runs later and experimental.chat.messages.transform can't affect the model id). So a plugin can't prevent applyCaching or strip cache_control early enough.\n\nNet: LiteLLM/OpenAI-compatible usage is broken for these model ids unless you rename/alias the model or patch core.
rekram1-node commentedon Jan 22, 2026
Yeah I think we need some better approach internally, note that a plugin can still strip them out, it's kinda weird but you can override the fetch implementation for any provider and it could strip out the things, example fetch being overriden:
opencode/packages/opencode/src/plugin/codex.ts
Line 376 in c3f393b
Ofc this isnt ideal solution just providing work around
hendem commentedon Jan 22, 2026
Thanks for the suggestion — that makes sense. I'll try the fetch-override approach and report back.
hendem commentedon Jan 22, 2026
Hey @rekram1-node, thanks for the fetch-override suggestion — it worked for me.
I had to hook the provider ID that actually owns the OpenAI-compatible/LiteLLM proxy (redacted below), and make sure auth exists for that provider so the loader runs. After that, stripping cache_control before the request goes out fixed the 400s.
Here’s the working plugin (provider name redacted):
ririnto commentedon Feb 4, 2026
use other model id and re-mapping in config.yaml(litellm).
RingOfStorms commentedon Mar 3, 2026
I will close this out for now as I agree it is sort of not an opencode issue directly and is more an issue with so many different providers and proxies handling calls and payloads differently
fix: empty tool-result content and cache control level for custom @ai…