litellm - 💡(How to fix) Fix [Bug]: Gemini(Vertex AI) context caching error [1 comments, 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#27093Fetched 2026-05-04 04:59:09
View on GitHub
Comments
1
Participants
1
Timeline
4
Reactions
0
Participants
Timeline (top)
labeled ×3commented ×1

Error Message

When passing both cache_control and tool_choice together in a Gemini request, the following error is returned: error

Root Cause

This happens because tool_choice (toolConfig in Gemini API) was not being included in the cached content creation request. As a result, it remained in the subsequent completion request alongside cachedContent, which Gemini does not allow.

Code Example

error

"Tool config, tools and system instruction should not be set in the request when using cached content."
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?

A bug happened!

When passing both cache_control and tool_choice together in a Gemini request, the following error is returned: "Tool config, tools and system instruction should not be set in the request when using cached content."

Steps to Reproduce

This happens because tool_choice (toolConfig in Gemini API) was not being included in the cached content creation request. As a result, it remained in the subsequent completion request alongside cachedContent, which Gemini does not allow.

Relevant log output

error

"Tool config, tools and system instruction should not be set in the request when using cached content."

What part of LiteLLM is this about?

SDK (litellm Python package)

What LiteLLM version are you on ?

1.82.1

Twitter / LinkedIn details

No response

extent analysis

TL;DR

Remove the tool_choice parameter from the Gemini request when using cached content to resolve the error.

Guidance

  • Verify that the tool_choice parameter is not necessary when using cached content, as Gemini does not allow it.
  • Check the LiteLLM Python package documentation to see if there are any specific guidelines for handling cached content and tool configuration.
  • Consider modifying the request to exclude tool_choice when cached content is being used, to prevent the error from occurring.
  • Review the cached content creation request to ensure that tool_choice (or toolConfig in Gemini API) is included, so it is not passed in the subsequent completion request.

Example

No code snippet is provided as the issue does not contain sufficient information about the code.

Notes

The solution assumes that the tool_choice parameter is not required when using cached content. If this parameter is necessary, further investigation into the Gemini API and LiteLLM Python package may be required.

Recommendation

Apply workaround: Remove the tool_choice parameter from the Gemini request when using cached content, as this is the most straightforward way to resolve the error based on the provided information.

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