litellm - ✅(Solved) Fix [Bug]: Gemini Context Caching fails when using custom api_base(ValueError: Model parameter is required for Gemini custom API base URLs) [1 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
BerriAI/litellm#23846Fetched 2026-04-08 00:48:53
View on GitHub
Comments
0
Participants
1
Timeline
6
Reactions
0
Participants
Timeline (top)
labeled ×3closed ×1cross-referenced ×1referenced ×1

Error Message

File ".../litellm/llms/vertex_ai/context_caching/vertex_ai_context_caching.py", line 484, in async_check_and_create_cache token, url = self._get_token_and_url_context_caching( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File ".../litellm/llms/vertex_ai/context_caching/vertex_ai_context_caching.py", line 84, in _get_token_and_url_context_caching return self._check_custom_proxy( ^^^^^^^^^^^^^^^^^^^^^^^^^ File ".../litellm/llms/vertex_ai/vertex_llm_base.py", line 393, in _check_custom_proxy raise ValueError( ValueError: Model parameter is required for Gemini custom API base URLs

Root Cause

This happens because the context caching module fails to pass the model name down to the proxy validation logic, which is strictly required for Gemini URL construction when a custom base URL is provided.

Fix Action

Fixed

PR fix notes

PR #23928: fix(gemini): pass model to context caching URL builder for custom api_base

Description (problem / solution / changelog)

Relevant issues

Fixes #23846

Pre-Submission checklist

  • I have Added testing in the tests/test_litellm/ directory, Adding at least 1 test is a hard requirement - see details
  • My PR passes all unit tests on make test-unit
  • My PR's scope is as isolated as possible, it only solves 1 specific problem
  • I have requested a Greptile review by commenting @greptileai and received a Confidence Score of at least 4/5 before requesting a maintainer review

Type

🐛 Bug Fix

Changes

_get_token_and_url_context_caching() in vertex_ai_context_caching.py was hardcoding model=None when calling _check_custom_proxy(). This works fine without a custom api_base (the default Google URL doesn't need the model in the path), but raises ValueError: Model parameter is required for Gemini custom API base URLs when api_base is set — because proxy URLs are constructed as {api_base}/models/{model}:cachedContents.

Fix

  • Added optional model parameter to _get_token_and_url_context_caching() (default None, backward-compatible)
  • Propagated model from the two callers that have it (check_and_create_cache and async_check_and_create_cache)
  • The two list-only callers (check_cache, async_check_cache) don't need model since listing doesn't require it in the URL

Changed files

  • litellm/llms/vertex_ai/context_caching/vertex_ai_context_caching.py (modified, +10/-1)
  • tests/test_litellm/llms/vertex_ai/context_caching/test_vertex_ai_context_caching.py (modified, +38/-1)

Code Example

File ".../litellm/llms/vertex_ai/context_caching/vertex_ai_context_caching.py", line 484, in async_check_and_create_cache
    token, url = self._get_token_and_url_context_caching(
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../litellm/llms/vertex_ai/context_caching/vertex_ai_context_caching.py", line 84, in _get_token_and_url_context_caching
    return self._check_custom_proxy(
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../litellm/llms/vertex_ai/vertex_llm_base.py", line 393, in _check_custom_proxy
    raise ValueError(
ValueError: Model parameter is required for Gemini custom API base URLs
RAW_BUFFERClick to expand / collapse

Check for existing issues

  • I have searched the existing issues and checked that my issue is not a duplicate.

What happened?

When using Gemini models with Context Caching enabled and a custom api_base, LiteLLM raises a ValueError(Model parameter is required for Gemini custom API base URLs).

This happens because the context caching module fails to pass the model name down to the proxy validation logic, which is strictly required for Gemini URL construction when a custom base URL is provided.

Root Cause Analysis:

  1. In litellm/llms/vertex_ai/context_caching/vertex_ai_context_caching.py, the method _get_token_and_url_context_caching calls self._check_custom_proxy.
  2. It hardcodes model=None in this call (Line 92 in v1.82.3).
  3. However, in litellm/llms/vertex_ai/vertex_llm_base.py, the _check_custom_proxy method raises a ValueError if api_base is present and model is None for the gemini provider (Lines 392-396), as it needs the model name to construct the path: {api_base}/models/{model}:{endpoint}.

Steps to Reproduce

  1. Configure a Gemini model in config.yaml with a custom api_base and cache_control_injection_points.
  2. Trigger a request that involves context caching.
  3. The request will fail during the cache creation/check phase.

Relevant log output

File ".../litellm/llms/vertex_ai/context_caching/vertex_ai_context_caching.py", line 484, in async_check_and_create_cache
    token, url = self._get_token_and_url_context_caching(
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../litellm/llms/vertex_ai/context_caching/vertex_ai_context_caching.py", line 84, in _get_token_and_url_context_caching
    return self._check_custom_proxy(
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../litellm/llms/vertex_ai/vertex_llm_base.py", line 393, in _check_custom_proxy
    raise ValueError(
ValueError: Model parameter is required for Gemini custom API base URLs

What part of LiteLLM is this about?

SDK (litellm Python package)

What LiteLLM version are you on ?

v1.82.3

Twitter / LinkedIn details

No response

extent analysis

Fix Plan

To resolve the ValueError caused by the missing model parameter when using Gemini models with Context Caching enabled and a custom api_base, you need to modify the _get_token_and_url_context_caching method in vertex_ai_context_caching.py to pass the model name to the _check_custom_proxy method.

Here are the steps:

  • Open litellm/llms/vertex_ai/context_caching/vertex_ai_context_caching.py
  • Modify the _get_token_and_url_context_caching method to pass the model name:
def _get_token_and_url_context_caching(self, ...):
    # ...
    model = self.model  # Assuming self.model has the model name
    return self._check_custom_proxy(model, ...)
  • Alternatively, if self.model is not available, you can pass the model name as an argument to the _get_token_and_url_context_caching method.

Verification

To verify that the fix worked:

  • Trigger a request that involves context caching with a Gemini model and a custom api_base.
  • Check the logs for any ValueError exceptions related to the missing model parameter.
  • If the fix is successful, the request should complete without raising a ValueError.

Extra Tips

  • Make sure to update the litellm package to the latest version if available, as this issue might be fixed in a later version.
  • If you are using a custom implementation of the _check_custom_proxy method, ensure that it handles the model parameter correctly.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

litellm - ✅(Solved) Fix [Bug]: Gemini Context Caching fails when using custom api_base(ValueError: Model parameter is required for Gemini custom API base URLs) [1 pull requests, 1 participants]