Repository navigation
fix(vertex_ai): build full request path when custom api_base has no path - #32367
Conversation
Greptile SummaryFixes a URL construction bug in
Confidence Score: 4/5Safe to merge; the change only affects the previously-broken bare-host api_base code path and leaves all working configurations untouched. Narrowly scoped three-line fix with five new tests and correct handling of streaming, PSC, and path-containing gateway cases. No files require special attention.
|
| Filename | Overview |
|---|---|
| litellm/llms/vertex_ai/vertex_llm_base.py | Core fix: adds a bare-host detection branch that grafts the default Vertex URL path onto the custom host; PSC and Gemini branches are unaffected and take priority. |
| tests/test_litellm/llms/vertex_ai/test_vertex_llm_base.py | Adds 5 new focused unit tests for the bare-host path; updates one existing parametrized case to match the new (correct) URL shape; all tests use mocked inputs with no real network calls. |
| tests/test_litellm/llms/vertex_ai/test_vertex_ai_psc_endpoint_support.py | Updates test_standard_proxy_with_googleapis to use a path-containing api_base, correctly preserving the api_base:endpoint assertion for path-ful proxies. |
Reviews (1): Last reviewed commit: "fix(vertex_ai): build full request path ..." | Re-trigger Greptile
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Merging this PR will improve performance by 11.07%
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing |
|
re: codspeed the "regressed" benchmark is a mocked gpt-4o completion that never touches the vertex-only code changed here, and the symmetric ±30% swings on sibling mock benchmarks are runner noise |
Relevant issues
Linear ticket
Resolves LIT-3167
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
@greptileaito re-request a review after pushing changes)Delays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
Screenshots / Proof of Fix
Reproduced live against the real Vertex API with a proxy config containing one deployment (
gemini-embedding-2->vertex_ai/gemini-embedding-2,vertex_location: global, bare-hostapi_base: https://aiplatform.googleapis.com); the identical curl was run first on the base branch, then on this PR's branchBefore (base branch, 8c0e3c0)
After (this PR, bb589ac)
The
--detailed_debuglog confirms the grafted outbound URL:https://aiplatform.googleapis.com/v1/projects/<project>/locations/global/publishers/google/models/gemini-embedding-2:embedContentType
🐛 Bug Fix
Changes
Vertex AI requests with a custom
api_basethat has no URL path (a bare host such ashttps://aiplatform.googleapis.comor an internal gateway host) produced invalid URLs.VertexBase._check_custom_proxyappended the endpoint verb with a colon, yielding e.g.https://aiplatform.googleapis.com:embedContent, which httpx rejects withhttpx.InvalidURL: Invalid port: 'embedContent'before any network call. A customer hit this as 500s on /embeddings for a vertex_ai Gemini embedding model routed throughGoogleBatchEmbeddings->_get_token_and_url->_check_custom_proxy, and the same flaw affected every vertex mode routed through that append (generateContent, predict, countTokens)The colon append exists for gateway api_bases (e.g. the Cloudflare AI Gateway convention) whose
api_basealready contains the full/v1/projects/.../models/{model}path; for those, appending:{endpoint}is correct and stays unchanged. The fix parses theapi_baseand, when its path is empty, instead grafts the default-built vertex URL's path onto the bare host, so the request goes to{api_base}/v1/projects/.../models/{model}:{endpoint}. The PSC endpoint format branch and the gemini (Google AI Studio) branch are untouched, and chat streaming on a bare host still ends up with exactly one?alt=sse. A bare-hostapi_basecould never produce a valid URL before, so no working setup changes behaviorRegression tests cover the bare host graft for embedContent, a bare host with a trailing slash, a path-ful gateway
api_basekeeping the colon append, chat streaming on a bare host keeping a single?alt=sse, and the PSC endpoint format staying intact