eca icon indicating copy to clipboard operation
eca copied to clipboard

Support: swap from and to anthropic models

Open madorian opened this issue 1 year ago • 4 comments

If I use Claude directly and then switch model to Claude through OpenRouter, I get this.

LLM response status: 400 body: {"error":{"message":"Provider returned error","code":400,"metadata":{"raw":"{"type":"error","error":{"type":"invalid_request_error","message":"messages.4.content.0: unexpected tool_use_id found in tool_result blocks: toolu_019fKLkGVcnhrPDYqErj5DiA. Each tool_result block must have a corresponding tool_use block in the previous message."},"request_id":"req_011CV7qdABguoPnbjVcwX83P"}","provider_name":"Anthropic"}},"user_id":"user_33jchzmvU7PXp74VQ7lMri1X9QT"}

madorian avatar Nov 14 '25 13:11 madorian

@madorian that happens because anthropic provider uses anthropic API and openrouter uses openai-chat, and changing a chat from one to other is incompatible currently since anthropic and openai encodes the ids and expect them on next requests, I can't see a way to make them work currently

ericdallo avatar Nov 16 '25 16:11 ericdallo

I think a short term solution would be to surface a user friendly error or warning message . Or even just not allowing the user to make a switch that isn't supported.

FWIW this article discusses the challenges in building an abstraction on top of multiple providers that also supports switching models/providers.

https://mariozechner.at/posts/2025-11-30-pi-coding-agent/

The code is also available

Ramblurr avatar Dec 22 '25 21:12 Ramblurr

Thanks @Ramblurr that makes sense, I will start with the user message

ericdallo avatar Dec 29 '25 14:12 ericdallo

Improved the error handling for this:

Image

ericdallo avatar Dec 29 '25 16:12 ericdallo