fix(litellm/caching/caching_handler.py): fix kwargs[litellm_params][preset_cache_key] not being propagated up the call stack during a cache hit, resulting in the x-litellm-cache-key header not being returned - #8822
Conversation
…reset_cache_key] not being propogated up the call stack during a cache hit, resulting in the x-litellm-cache-key header not being returned
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
|
@ishaan-jaff can I get a review today? |
|
|
|
Any updates to when this PR be merged? |
|
ack @Eduard-Voiculescu - i'll look at this tomorrow |
… return from a response
|
Is it just me or there's no x-litellm-cache-key header at all in the response? using v1.74.0-stable |
Same for me, tried many things but did not manage to get this x-litellm-cache-key header. I upgraded to v1.76.0 and did not have any luck. |
Title
fix(litellm/caching/caching_handler.py): fix
kwargs["litellm_params"]["preset_cache_key"]not being propagated up the call stack during a cache hit, resulting in thex-litellm-cache-keyheader not being returnedRelevant issues
#8570
Type
🐛 Bug Fix
Changes
The problem is subtle and my fix is currently hacky. I don't know yet enough about the codebase to determine a more "correct" solution to this.
The problem is:
kwargspassed intocaching_handler._retrieve_from_cache()does not contain alitellm_paramsdictionary:litellm/litellm/caching/caching_handler.py
Line 480 in 70923f7
caching._set_preset_cache_key_in_kwargs()expects there to be alitellm_paramsdictionary, so it can use it to pass thepreset_cache_keyup the call stack. But it is missing.litellm/litellm/caching/caching.py
Line 365 in 70923f7
preset_cache_keyis missing when we try to retrieve it incaching_handler._async_get_cache()usingcaching_get_preset_cache_key_from_kwargslitellm/litellm/caching/caching_handler.py
Line 179 in 70923f7
https://github.com/BerriAI/litellm/blob/main/litellm/caching/caching.py#L341
x-litellm-cache-keynot being returned to the caller upon cache hitThe obvious fix for this is to just add an empty
litellm_paramsdictionary tokwargs. However, in the case of a cache miss, this results in a downstream error, wherelitellm_paramsends up being passed to bedrock, and throwing this error:So to get around that, if we do not have a cache hit, we detect that, and remove the
litellm_paramsdictionary fromkwargs. I only remove it ifpreset_cache_keyis the only key in its dictionary, in an attempt to not interfere with other potential flows I might not be consideringI don't like this fix, but I'm not sure how else to fix it without starting to modify existing interfaces, and turning this into a refactoring pull request. If this fix is too hacky, I'd appreciate some general suggestions as to what may be a better fix
Is there any way to gracefully drop the
litellm_paramsdictionary before it gets passed to bedrock?[REQUIRED] Testing - Attach a screenshot of any new tests passing locally
Sorry, I haven't been able to get the tests running yet, would appreciate help there. Below is output with the fix. You can see the
x-litellm-cache-keyheader is returned on cache hit now