Skip to content

Google/Vertex Request Builder#3266

Draft
codeshaunted wants to merge 2 commits intocanaryfrom
avery/google
Draft

Google/Vertex Request Builder#3266
codeshaunted wants to merge 2 commits intocanaryfrom
avery/google

Conversation

@codeshaunted
Copy link
Collaborator

@codeshaunted codeshaunted commented Mar 23, 2026

Summary by CodeRabbit

  • New Features
    • Added support for Google Vertex AI (Gemini) and Google AI (Gemini) model providers
    • Enabled streaming requests for Google-powered LLM services
    • Added media content support (images and videos) for these providers
    • Implemented support for Anthropic models running on Vertex AI infrastructure

@vercel
Copy link

vercel bot commented Mar 23, 2026

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

Project Deployment Actions Updated (UTC)
beps Ready Ready Preview, Comment Mar 23, 2026 11:36pm
promptfiddle Ready Ready Preview, Comment Mar 23, 2026 11:36pm

Request Review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 23, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 6cea2dc1-a1dd-41a9-951c-e5bd4407a770

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Added support for Google Cloud AI Platform (Vertex AI) and Google AI with Gemini models through a new GoogleBuilder that constructs HTTP requests using the google-cloud-aiplatform-v1 SDK. Updated request routing to distinguish between Anthropic-on-Vertex and native Vertex/Google AI implementations, with Anthropic-on-Vertex using Anthropic builder with URL rewriting.

Changes

Cohort / File(s) Summary
Dependencies
baml_language/Cargo.toml, baml_language/crates/sys_llm/Cargo.toml
Added google-cloud-aiplatform-v1 (v1.8) dependency with prediction-service feature to workspace and sys_llm crate.
Google Builder Implementation
baml_language/crates/sys_llm/src/build_request/google.rs
New file implementing GoogleBuilder with HTTP request construction for Gemini models, supporting Vertex AI and Google AI URLs, request body building, prompt-to-GCP type conversion, and media handling (text, image, video). Includes comprehensive unit tests for URL generation, body construction, option forwarding, and media support.
Request Routing & Authorization
baml_language/crates/sys_llm/src/build_request/mod.rs
Added google module and is_anthropic_on_vertex() helper. Updated routing to dispatch VertexAi + Anthropic to AnthropicBuilder with URL rewriting, VertexAi + non-Anthropic to GoogleBuilder, and GoogleAi to GoogleBuilder. Authorization updated to handle Anthropic-on-Vertex separately and leave non-Anthropic Vertex/Google requests unauthenticated. Added Vertex AI and Google AI test coverage.
Provider Enum Updates
baml_language/crates/sys_llm/src/provider.rs
Reorganized LlmProvider enum: moved GoogleAi variant and updated doc comments to clarify both VertexAi and GoogleAi use GenerateContentRequest serialization.

Sequence Diagram

sequenceDiagram
    participant Client
    participant Router as Request Router
    participant AnthropicBuilder
    participant GoogleBuilder
    participant VertexAPI as Vertex API
    participant GoogleAPI as Google AI API

    Client->>Router: build_request(provider, model, prompt)
    
    alt VertexAi + Anthropic (claude-*)
        Router->>AnthropicBuilder: build_request()
        AnthropicBuilder->>AnthropicBuilder: construct Anthropic request
        AnthropicBuilder-->>Router: return Anthropic HTTP request
        Router->>Router: rewrite URL to<br/>Vertex rawPredict/streamRawPredict
        Router-->>Client: return Vertex-addressed request
    else VertexAi + Gemini
        Router->>GoogleBuilder: build_request()
        GoogleBuilder->>GoogleBuilder: build Vertex URL<br/>convert prompt to GCP types<br/>serialize GenerateContentRequest
        GoogleBuilder-->>Router: return HTTP request
        Router-->>Client: return request (no auth)
    else GoogleAi
        Router->>GoogleBuilder: build_request()
        GoogleBuilder->>GoogleBuilder: build Google AI URL<br/>convert prompt to GCP types<br/>serialize GenerateContentRequest
        GoogleBuilder-->>Router: return HTTP request
        Router-->>Client: return request (no auth)
    end

    Client->>VertexAPI: POST request
    Client->>GoogleAPI: POST request
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • anthropic provider #3235: Adds and refactors Anthropic build_request implementation, which is directly integrated by this PR's Anthropic-on-Vertex routing that forwards to the Anthropic builder and rewrites URLs to Vertex endpoints.
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Google/Vertex Request Builder' directly and specifically describes the main change - adding a new request builder for Google Cloud and Vertex AI platforms.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch avery/google

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codeshaunted
Copy link
Collaborator Author

@coderabbitai review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 23, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@codspeed-hq
Copy link

codspeed-hq bot commented Mar 23, 2026

Merging this PR will not alter performance

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

✅ 15 untouched benchmarks
⏩ 91 skipped benchmarks1


Comparing avery/google (dd853c1) with canary (dddd673)

Open in CodSpeed

Footnotes

  1. 91 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: e62a614d-9242-4350-b7d0-37b6cd05eb59

📥 Commits

Reviewing files that changed from the base of the PR and between dddd673 and 8218aa8.

⛔ Files ignored due to path filters (1)
  • baml_language/Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (5)
  • baml_language/Cargo.toml
  • baml_language/crates/sys_llm/Cargo.toml
  • baml_language/crates/sys_llm/src/build_request/google.rs
  • baml_language/crates/sys_llm/src/build_request/mod.rs
  • baml_language/crates/sys_llm/src/provider.rs

Comment on lines +120 to +122
Ok(format!(
"https://{domain}/v1/projects/{project_id}/locations/{location}/publishers/google/models/{model}:{rpc}"
))
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Incorrect publisher path for Anthropic models.

The URL template uses publishers/google for Anthropic/Claude models:

"https://{domain}/v1/projects/{project_id}/locations/{location}/publishers/google/models/{model}:{rpc}"

Anthropic models on Vertex AI require publishers/anthropic in the path, not publishers/google. This will cause 404 errors when making requests to Claude models.

🐛 Proposed fix
     Ok(format!(
-        "https://{domain}/v1/projects/{project_id}/locations/{location}/publishers/google/models/{model}:{rpc}"
+        "https://{domain}/v1/projects/{project_id}/locations/{location}/publishers/anthropic/models/{model}:{rpc}"
     ))

Comment on lines +206 to +216
LlmProvider::VertexAi if is_anthropic_on_vertex(client) => {
// Anthropic-on-Vertex needs the anthropic-version header.
// Vertex OAuth2 auth is not yet implemented here.
crate::auth_request::AnthropicAuth
.authorize(raw, client, &callbacks)
.await?
}
LlmProvider::VertexAi | LlmProvider::GoogleAi => {
// Auth not yet implemented -- return the raw request as-is.
raw
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Missing authentication implementation for Vertex AI and Google AI.

The authorization section returns the raw request unchanged for non-Anthropic Vertex AI and Google AI providers. Per the context snippet from auth_request/mod.rs, only AnthropicAuth and OpenAiAuth implementations exist — there's no GoogleAuth or VertexAuth.

This means:

  • Vertex AI requests will lack the required OAuth2 bearer token
  • Google AI requests will lack the API key (typically passed as ?key=... query param)

Both providers will fail at runtime without proper authentication.

Would you like me to help implement the GoogleAuth handler that:

  1. For Google AI: appends the api_key as a query parameter (?key=...)
  2. For Vertex AI: adds OAuth2 bearer token from credentials/ADC

Comment on lines +1131 to +1135
assert!(result.url.contains("claude-3-5-sonnet@20241022:rawPredict"),);
assert_eq!(
result.url,
"https://us-east5-aiplatform.googleapis.com/v1/projects/my-project/locations/us-east5/publishers/google/models/claude-3-5-sonnet@20241022:rawPredict"
);
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🌐 Web query:

Vertex AI Anthropic Claude rawPredict endpoint URL format

💡 Result:

The rawPredict endpoint URL format for Vertex AI Anthropic Claude models is: https://{LOCATION}-aiplatform.googleapis.com/v1/projects/{PROJECT_ID}/locations/{LOCATION}/publishers/anthropic/models/{MODEL}:rawPredict Where: - {LOCATION}: The region (e.g., 'us-central1', 'global' for global endpoint). - {PROJECT_ID}: Your Google Cloud project ID. - {MODEL}: The Claude model ID (e.g., 'claude-3-5-sonnet@20240620', 'claude-opus-4-6'). Use POST method with Authorization Bearer token and JSON body including "anthropic_version": "vertex-2023-10-16", messages, max_tokens, etc. For streaming, use :streamRawPredict instead.

Citations:


🏁 Script executed:

# Read the test file to verify the exact code at lines 1131-1135
sed -n '1100,1160p' baml_language/crates/sys_llm/src/build_request/mod.rs

Repository: BoundaryML/baml

Length of output: 2226


🏁 Script executed:

# Also check the broader context of this test function to understand what it's testing
sed -n '1097,1155p' baml_language/crates/sys_llm/src/build_request/mod.rs

Repository: BoundaryML/baml

Length of output: 2186


🏁 Script executed:

# Search for the implementation that constructs these URLs to understand the logic
rg "publishers" baml_language/crates/sys_llm/src/build_request/ -A 2 -B 2

Repository: BoundaryML/baml

Length of output: 2996


🏁 Script executed:

# Check if there's conditional logic for Anthropic vs Google models
rg "anthropic" baml_language/crates/sys_llm/src/build_request/ -B 3 -A 3

Repository: BoundaryML/baml

Length of output: 43215


🏁 Script executed:

# Look at the full google.rs implementation to see the build_url function context
cat -n baml_language/crates/sys_llm/src/build_request/google.rs | head -150

Repository: BoundaryML/baml

Length of output: 6661


🏁 Script executed:

# Check the complete vertex_anthropic_url function
sed -n '89,123p' baml_language/crates/sys_llm/src/build_request/google.rs

Repository: BoundaryML/baml

Length of output: 1329


Fix Vertex AI URL publisher for Anthropic models: use publishers/anthropic instead of publishers/google.

The Vertex AI URL for Anthropic models must use publishers/anthropic, not publishers/google. This issue exists in both the implementation and the test:

  1. Implementation (google.rs line 121): The vertex_anthropic_url() function hardcodes publishers/google in the URL template.
  2. Test (lines 1131-1135): The assertion expects the incorrect URL with publishers/google.

According to official Google Cloud and Anthropic documentation, the correct format is:

https://{location}-aiplatform.googleapis.com/v1/projects/{project_id}/locations/{location}/publishers/anthropic/models/{model}:rawPredict

Using publishers/google will cause API requests to fail in production.

@github-actions
Copy link

github-actions bot commented Mar 23, 2026

Binary size checks passed

7 passed

Artifact Platform Gzip Baseline Delta Status
bridge_cffi Linux 5.7 MB 5.7 MB +9.5 KB (+0.2%) OK
bridge_cffi-stripped Linux 4.3 MB 4.3 MB +7.6 KB (+0.2%) OK
bridge_cffi macOS 4.6 MB 4.6 MB +7.4 KB (+0.2%) OK
bridge_cffi-stripped macOS 3.5 MB 3.5 MB +4.6 KB (+0.1%) OK
bridge_cffi Windows 4.6 MB 4.6 MB +4.8 KB (+0.1%) OK
bridge_cffi-stripped Windows 3.6 MB 3.5 MB +5.2 KB (+0.1%) OK
bridge_wasm WASM 3.0 MB 3.0 MB +3.6 KB (+0.1%) OK

Generated by cargo size-gate · workflow run

@codeshaunted
Copy link
Collaborator Author

@coderabbitai review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 23, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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