diff --git a/litellm/llms/vertex_ai/context_caching/vertex_ai_context_caching.py b/litellm/llms/vertex_ai/context_caching/vertex_ai_context_caching.py index 75d4ffbed86..0d13dd26f50 100644 --- a/litellm/llms/vertex_ai/context_caching/vertex_ai_context_caching.py +++ b/litellm/llms/vertex_ai/context_caching/vertex_ai_context_caching.py @@ -76,6 +76,9 @@ class ContextCachingEndpoints(VertexBase): base_url = get_vertex_base_url(vertex_location) url = f"{base_url}/v1beta1/projects/{vertex_project}/locations/{vertex_location}/{endpoint}" + if custom_llm_provider == "gemini" and api_base: + return auth_header, f"{api_base.rstrip('/')}/{endpoint}" + return self._check_custom_proxy( api_base=api_base, custom_llm_provider=custom_llm_provider, diff --git a/tests/test_litellm/llms/vertex_ai/context_caching/test_vertex_ai_context_caching.py b/tests/test_litellm/llms/vertex_ai/context_caching/test_vertex_ai_context_caching.py index f666829d2e8..fb0be993fae 100644 --- a/tests/test_litellm/llms/vertex_ai/context_caching/test_vertex_ai_context_caching.py +++ b/tests/test_litellm/llms/vertex_ai/context_caching/test_vertex_ai_context_caching.py @@ -2027,12 +2027,7 @@ class TestVertexAIGlobalLocation: "global-aiplatform" not in url ), "URL should not contain 'global-aiplatform' prefix" - def test_gemini_context_caching_with_custom_api_base_passes_model(self): - """Gemini context caching with custom api_base must pass model to _check_custom_proxy. - - Regression test for https://github.com/BerriAI/litellm/issues/23846 - Previously model was hardcoded to None, causing ValueError when api_base was set. - """ + def test_gemini_custom_cache_uses_collection_endpoint_without_model(self): caching = ContextCachingEndpoints() auth_header, url = caching._get_token_and_url_context_caching( @@ -2042,11 +2037,10 @@ class TestVertexAIGlobalLocation: vertex_project=None, vertex_location=None, vertex_auth_header=None, - model="gemini-1.5-pro", ) - assert "models/gemini-1.5-pro" in url - assert url.startswith("https://my-proxy.example.com/") + assert auth_header == {"x-goog-api-key": "test-key"} + assert url == "https://my-proxy.example.com/cachedContents" def test_gemini_context_caching_without_api_base_ignores_model(self): """Without custom api_base, model param is not needed (default URL is used)."""