The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
fix(caching): stamp provider on embedding cache-hit logs so spend logs record provider
milan15c7d850e5d6
diff --git a/litellm/caching/caching_handler.py b/litellm/caching/caching_handler.pyindex b17e055c7ea..d8a2d2d76b7 100644--- a/litellm/caching/caching_handler.py+++ b/litellm/caching/caching_handler.py@@ -517,6 +517,7 @@ class LLMCachingHandler:cached_result=final_embedding_cached_response,is_async=True,is_embedding=True,+ custom_llm_provider=custom_llm_provider,)self._async_log_cache_hit_on_callbacks(logging_obj=logging_obj,diff --git a/tests/test_litellm/caching/test_caching_handler.py b/tests/test_litellm/caching/test_caching_handler.pyindex 1136a0b7e7b..38019fc0fee 100644--- a/tests/test_litellm/caching/test_caching_handler.py+++ b/tests/test_litellm/caching/test_caching_handler.py@@ -558,6 +558,44 @@ async def test_embedding_cache_falls_back_to_token_counter_for_legacy_entries():assert response.usage.prompt_tokens > 0+async def test_embedding_cache_hit_sets_custom_llm_provider_on_logging_obj():+ """A full embedding cache hit must stamp the resolved provider onto the logging+ obj so spend logs record the provider instead of None/unknown."""+ from litellm.types.utils import CallTypes++ llm_caching_handler = LLMCachingHandler(+ original_function=MagicMock(),+ request_kwargs={},+ start_time=datetime.now(),+ )++ cached_result = [+ {+ "embedding": [-0.025, -0.019],+ "index": 0,+ "object": "embedding",+ "model": "text-embedding-3-small",+ "prompt_tokens": 5,+ }+ ]++ logging_obj = _build_logging_obj(CallTypes.aembedding.value, stream=False)+ logging_obj.async_success_handler = AsyncMock()++ response, cache_hit = llm_caching_handler._process_async_embedding_cached_response(+ final_embedding_cached_response=None,+ cached_result=cached_result,+ kwargs={"model": "text-embedding-3-small", "input": "hello world"},+ logging_obj=logging_obj,+ start_time=datetime.now(),+ model="text-embedding-3-small",+ )++ assert cache_hit+ assert logging_obj.model_call_details["custom_llm_provider"] == "openai"++def test_request_kwargs_does_not_retain_logging_obj():"""The caching handler lives on logging_obj._llm_caching_handler, so keeping