Skip to content

Support Vertex AI publisher URLs for Gemini#425

Open
hijos wants to merge 2 commits into
tbphp:mainfrom
hijos:codex/vertex-ai-publisher-gemini
Open

Support Vertex AI publisher URLs for Gemini#425
hijos wants to merge 2 commits into
tbphp:mainfrom
hijos:codex/vertex-ai-publisher-gemini

Conversation

@hijos

@hijos hijos commented Jun 20, 2026

Copy link
Copy Markdown

Summary

Tests

  • npm run build
  • go test ./...

Summary by CodeRabbit

  • Refactor
    • Improved Gemini upstream request URL handling, including correct Vertex AI Publisher-style path rewriting and consistent forwarding of query parameters during proxying.
  • Bug Fixes
    • Fixed API key validation and model-path redirection to use the correct Vertex AI Publisher .../models/<model>:generateContent endpoint and preserve the request body.
  • Tests
    • Added unit tests covering upstream URL construction, request mutation behavior, and API key validation across multiple configuration scenarios.

@coderabbitai

coderabbitai Bot commented Jun 20, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: cb09b003-d39f-4893-be8b-1ea0df5cb514

📥 Commits

Reviewing files that changed from the base of the PR and between 24d9aea and fdd2919.

📒 Files selected for processing (2)
  • internal/channel/gemini_channel.go
  • internal/channel/gemini_channel_test.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • internal/channel/gemini_channel_test.go
  • internal/channel/gemini_channel.go

Walkthrough

GeminiChannel gains a BuildUpstreamURL method that trims the /proxy/{groupName} prefix from incoming paths, detects Vertex AI publisher-style base URLs, and conditionally rewrites Gemini-native model paths. ValidateKey is updated to delegate URL construction to BuildUpstreamURL and apply API keys via ModifyRequest. A set of internal path/URL helpers and a new test file covering all URL-rewriting scenarios are added.

Changes

Gemini upstream URL construction and ValidateKey refactor

Layer / File(s) Summary
BuildUpstreamURL, path helpers, and ValidateKey updates
internal/channel/gemini_channel.go
Adds BuildUpstreamURL that resolves the upstream base, trims the proxy prefix, and rewrites paths for Vertex publisher base URLs. Introduces internal helpers (trimProxyPrefix, isVertexPublisherBase, rewriteGeminiNativePath, path-join/normalization). Updates ValidateKey to call BuildUpstreamURL and apply the API key via ModifyRequest.
Unit tests for BuildUpstreamURL, ApplyModelRedirect, and ValidateKey
internal/channel/gemini_channel_test.go
New test file with four BuildUpstreamURL cases (developer API preservation, Vertex publisher base conversion, bare aiplatform root conversion, no-duplication), one ApplyModelRedirect path-rewrite case, and one ValidateKey case using an httptest server to assert endpoint path and key query parameter. Includes newTestGeminiChannel and mustParseURL helpers.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 Hop hop, the proxy prefix falls away,
Vertex paths rewritten, hip hooray!
BuildUpstreamURL leads the way,
No duplicate publishers shall stay.
The tests all pass — what a fine day! 🌿

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The pull request description is largely incomplete. It lacks the required sections from the template: no linked issue number, no checkbox selection for change type, and no completion of the self-checklist items. Complete the description template by: (1) adding the related issue number after 'Closes #', (2) selecting the appropriate change type checkbox, (3) checking the testing and documentation checklist items with explanations.
Docstring Coverage ⚠️ Warning Docstring coverage is 5.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely describes the main change: adding support for Vertex AI publisher URLs for Gemini, which is the core objective of the pull request.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/channel/gemini_channel.go`:
- Around line 49-52: The else branch at line 52 unconditionally prepends
base.Path to requestPath using joinURLPath, causing path duplication when
non-Vertex upstreams are configured with a path component. Before calling
joinURLPath for the non-Vertex case, add a guard check to verify that the
requestPath does not already contain the base.Path value, similar to how the
Vertex branch mitigates this. This ensures that paths like /v1beta are not
duplicated in the final URL when a base upstream path is already present in the
request.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ad050093-0bdc-429a-aab2-aa25488ff266

📥 Commits

Reviewing files that changed from the base of the PR and between 5579930 and 24d9aea.

📒 Files selected for processing (2)
  • internal/channel/gemini_channel.go
  • internal/channel/gemini_channel_test.go

Comment thread internal/channel/gemini_channel.go
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