Repository navigation
fix(vertex_ai): fix gemini-4-argon explicit context caching 400 crash (#46470) - #49860
scriptsmay wants to merge 5 commits into
Conversation
|
Thanks for working on this! Two notes from reproducing it with Claude Code →
Suggestion: keep |
2095cf4 to
11edcf9
Compare
|
Thanks for the review! Adopted your suggestion — added a separate |
|
Hit this in production on Read through the diff against current
|
Merging this PR will not alter performance1 warning
Comparing |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
…hing is unsupported (BerriAI#46470)
… models and sync transform
…ompt_caching gemini-4 (argon/carbon) support implicit prompt caching only; explicit cache_control markers return HTTP 400 "does not support explicit context caching". Add a supports_explicit_prompt_caching model field and gate the three explicit-caching code paths on it, keeping supports_prompt_caching true for implicit caching and cost tracking.
…e_model Address review feedback on BerriAI#49860 after rebasing onto latest main: - add supports_explicit_prompt_caching: false to gemini-4-hydrogen rows - register the flag in _PATTERN_WIDE_CACHE_FLAGS so wildcard deployments (vertex_ai/*, gemini/*) defer to per-model catalog rows - check model_info.base_model via is_explicitly_disabled_factory so custom deployments with base_model: vertex_ai/gemini-4-* skip cachedContents
11edcf9 to
350e856
Compare
|
Thanks @tbartik — this is a real production reproduction, appreciate the detailed write-up. I've rebased the branch onto current
On #3 (memoizing the 400 fallback): fully agree with the reasoning — the repeated Tests: the dedicated unit test file passes (6/6), ruff clean. |
Handwritten 1-3 sentence description
<make-me-human-readable>Prevent HTTP 400 crashes when clients send Anthropic prompt caching headers to Vertex AI models that do not support explicit context caching (e.g. Gemini-4-Argon). The proxy now drops unsupported caching instructions beforehand and safely falls back without dropping messages or tool parameters if Vertex AI rejects explicit cache creation.
</make-me-human-readable>Details
TLDR
Problem this solves:
cache_controlto Gemini-4 models (Argon/Carbon) trigger HTTP 400.supports_prompt_caching: trueis also used to gate explicitcache_controlhandling.cachedContents.create) is rejected with HTTP 400 and was not handled gracefully.How it solves it:
supports_explicit_prompt_cachingfield; set it tofalseon thegemini-4-*(Argon/Carbon) rows while keepingsupports_prompt_caching: truefor implicit caching and cost tracking.target_consumes_cache_control()andContextCachingEndpoints/ Vertex request body transformation onsupports_explicit_prompt_caching.check_and_create_cachepreserving original messages and tools.Relevant issues
Fixes #46470
User Flow
Before: a client requests Gemini-4-Argon with prompt caching headers and gets an HTTP 400 crash
gemini-4-argonand Anthropiccache_controlheaders.cachedContents.create).After: the same request succeeds transparently without error
gemini-4-argonand Anthropiccache_controlheaders.cachedContents.create.Pre-Submission checklist
uv run pytest tests/unit/<your_test_file>.py -v.Screenshots / Proof of Fix
Unit test execution:
Linting:
Type
🐛 Bug Fix
Final Attestation