fix(caching): skip caching FakeAnthropicMessagesStreamIterator (not JSON serializable)

This commit is contained in:
Alexandre Baudoin 2026-10-06 09:40:25 +02:00
parent 2e1a98f521
commit 07e048bd70
No known key found for this signature in database
GPG key ID: 19F6E60969F1135D

View file

@ -1101,6 +1101,18 @@ class LLMCachingHandler:
)
)
else:
from litellm.llms.anthropic.pass_through.messages.fake_stream_iterator import (
FakeAnthropicMessagesStreamIterator,
)
if isinstance(result, FakeAnthropicMessagesStreamIterator):
# Synthetic streaming wrapper (e.g. websearch interception
# short-circuit) around an already-served response. It is
# not JSON-serializable and was never meant to be cached
# as-is - caching it crashes the Redis/async cache backend
# with "Object of type FakeAnthropicMessagesStreamIterator
# is not JSON serializable" on every streaming request.
return
create_cache_write_task(lambda: cache.async_add_cache(result, **new_kwargs))
def sync_set_cache(