Skip to content

fix(vertex_ai): Set anthropic-beta as HTTP header for Vertex AI rawPredict#22321

Open
castrapel wants to merge 1 commit intoBerriAI:mainfrom
castrapel:fix/vertex-ai-anthropic-beta-http-header
Open

fix(vertex_ai): Set anthropic-beta as HTTP header for Vertex AI rawPredict#22321
castrapel wants to merge 1 commit intoBerriAI:mainfrom
castrapel:fix/vertex-ai-anthropic-beta-http-header

Conversation

@castrapel
Copy link
Contributor

@castrapel castrapel commented Feb 27, 2026

Relevant issues

Related: context_management and compact beta headers fail on Vertex AI via
the legacy VertexAIAnthropicConfig handler.

Possibly related: #20418

Pre-Submission checklist

  • I have Added testing in the tests/litellm/ directory
  • 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

Type

Bug Fix

Changes

VertexAIAnthropicConfig.transform_request() sets beta values in the request
body (data["anthropic_beta"]) but does not set them as HTTP headers. Vertex
AI's rawPredict endpoint requires anthropic-beta as an HTTP header for
certain 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-12 beta header)

Verified with direct curl calls to Vertex AI rawPredict:

  • anthropic_beta body field alone: 400 (context_management rejected)
  • anthropic-beta HTTP header: 200 (context_management accepted)
  • Both body field and HTTP header: 200

The fix adds a single line to also set headers["anthropic-beta"] alongside
the existing body field. The headers dict is mutable and propagates to the
HTTP POST call in the Anthropic chat handler.

The experimental pass-through handler
(VertexAIPartnerModelsAnthropicMessagesConfig) already sets beta values as
HTTP headers in validate_anthropic_messages_environment(). This fix aligns
the legacy handler behavior.

Test plan

  • Updated existing context_management tests to verify HTTP header is set
  • Updated extra_headers propagation test to verify HTTP header
  • Updated no-headers test to verify HTTP header is absent when no betas
  • All 13 tests in test file pass

@vercel
Copy link

vercel bot commented Feb 27, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
litellm Ready Ready Preview, Comment Feb 27, 2026 10:48pm

Request Review

@castrapel
Copy link
Contributor Author

@greptileai

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 27, 2026

Greptile Summary

Fixes Vertex AI rawPredict rejecting context_management and compact beta features by setting the anthropic-beta HTTP header alongside the existing anthropic_beta request body field. The Vertex AI rawPredict endpoint requires these beta flags as HTTP headers — the body field alone is insufficient and results in invalid_request_error: context_management: Extra inputs are not permitted.

  • Adds one line in VertexAIAnthropicConfig.transform_request() to set headers["anthropic-beta"] as a comma-separated string when beta values are present
  • Aligns the legacy handler with the experimental pass-through handler (VertexAIPartnerModelsAnthropicMessagesConfig), which already sets beta values as HTTP headers
  • Tests updated to verify both the body field and HTTP header are set correctly, including positive and negative cases
  • All provider-specific code remains within llms/ directory; tests are mock-only with no real network calls

Confidence Score: 5/5

  • This PR is safe to merge — it's a minimal, well-tested one-line bug fix that aligns behavior with an existing handler.
  • The change is a single line that sets an HTTP header value from data already being computed. It follows the exact same pattern used by the experimental pass-through handler. The headers dict is mutable and correctly propagates to the HTTP POST call. All existing tests are updated and new assertions verify both positive and negative cases. No breaking changes, no new dependencies, no provider-specific code outside llms/.
  • No files require special attention

Important Files Changed

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
Loading

Last reviewed commit: 0b589b2

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant