fix(vertex_ai): Set anthropic-beta as HTTP header for Vertex AI rawPredict#22321
Open
castrapel wants to merge 1 commit intoBerriAI:mainfrom
Open
fix(vertex_ai): Set anthropic-beta as HTTP header for Vertex AI rawPredict#22321castrapel wants to merge 1 commit intoBerriAI:mainfrom
castrapel wants to merge 1 commit intoBerriAI:mainfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
Author
Contributor
Greptile SummaryFixes Vertex AI
Confidence Score: 5/5
|
| Filename | Overview |
|---|---|
| litellm/llms/vertex_ai/vertex_ai_partner_models/anthropic/transformation.py | Adds a single line to set anthropic-beta as an HTTP header alongside the existing body field. Aligns legacy handler with experimental pass-through handler behavior. Clean, minimal fix. |
| tests/test_litellm/llms/vertex_ai/vertex_ai_partner_models/anthropic/test_vertex_ai_partner_models_anthropic_transformation.py | Updates existing tests to verify the new HTTP header is set when beta values are present and absent when no betas apply. Tests are mock-only with no real network calls. |
Sequence Diagram
sequenceDiagram
participant Client as LiteLLM Client
participant Config as VertexAIAnthropicConfig
participant Handler as BaseLLMHTTPHandler
participant Vertex as Vertex AI rawPredict
Client->>Handler: completion(model, messages, optional_params)
Handler->>Config: transform_request(model, messages, optional_params, headers)
Note over Config: Collect beta values into beta_set
Config->>Config: data["anthropic_beta"] = list(beta_set)
Config->>Config: headers["anthropic-beta"] = ",".join(beta_set)
Config-->>Handler: return data (body)
Handler->>Handler: sign_request(headers, data)
Handler->>Vertex: POST rawPredict (headers + body)
Note over Vertex: Validates anthropic-beta HTTP header<br/>for context_management, compact, etc.
Vertex-->>Handler: 200 OK
Handler-->>Client: ModelResponse
Last reviewed commit: 0b589b2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Relevant issues
Related: context_management and compact beta headers fail on Vertex AI via
the legacy VertexAIAnthropicConfig handler.
Possibly related: #20418
Pre-Submission checklist
tests/litellm/directorymake test-unit@greptileaiType
Bug Fix
Changes
VertexAIAnthropicConfig.transform_request()sets beta values in the requestbody (
data["anthropic_beta"]) but does not set them as HTTP headers. VertexAI's rawPredict endpoint requires
anthropic-betaas an HTTP header forcertain features to be recognized. Without the header, Vertex rejects request
body fields that depend on it with:
invalid_request_error: context_management: Extra inputs are not permitted
(We were experiencing this with the
compact-2026-01-12beta header)Verified with direct curl calls to Vertex AI rawPredict:
anthropic_betabody field alone: 400 (context_management rejected)anthropic-betaHTTP header: 200 (context_management accepted)The fix adds a single line to also set
headers["anthropic-beta"]alongsidethe existing body field. The
headersdict is mutable and propagates to theHTTP POST call in the Anthropic chat handler.
The experimental pass-through handler
(
VertexAIPartnerModelsAnthropicMessagesConfig) already sets beta values asHTTP headers in
validate_anthropic_messages_environment(). This fix alignsthe legacy handler behavior.
Test plan