fix(gemini): avoid duplicate model route for full api_base#26983
fix(gemini): avoid duplicate model route for full api_base#26983StatPan wants to merge 3 commits into
Conversation
Greptile SummaryThis PR fixes a URL-construction bug in Confidence Score: 4/5Safe to merge; the fix is minimal and correct for the documented cases, with one unhandled edge case left as a P2 suggestion. Only P2 findings present. The three-branch guard correctly handles all cases described in the PR. One unhandled edge case (full-route api_base with a mismatched endpoint) could silently produce a bad URL but is very unlikely in practice and is no worse than the pre-fix behaviour. No files require special attention.
|
| Filename | Overview |
|---|---|
| litellm/llms/vertex_ai/vertex_llm_base.py | Adds three-way branch in _check_custom_proxy to avoid duplicating /models/{model}:{endpoint} when the Gemini api_base already includes the full route or the model prefix; also adds rstrip("/") to the base-URL case. |
| tests/test_litellm/llms/vertex_ai/test_vertex_llm_base.py | Removes unused imports, converts an incomplete print statement into a proper assertion, and adds a parametrized regression test for the three new api_base shapes. |
Reviews (1): Last reviewed commit: "test(vertex): restore credential project..." | Re-trigger Greptile
| if api_base.endswith(f"/models/{model}:{endpoint}"): | ||
| url = api_base | ||
| elif api_base.endswith(f"/models/{model}"): | ||
| url = f"{api_base}:{endpoint}" | ||
| else: | ||
| url = "{}/models/{}:{}".format( | ||
| api_base.rstrip("/"), model, endpoint | ||
| ) |
There was a problem hiding this comment.
If a user sets
api_base to a full route that already contains a different endpoint than the one being requested (e.g. api_base ends with :generateContent but the call needs :streamGenerateContent), none of the first two branches match and the else branch appends /models/{model}:{endpoint} onto an already-fully-routed base, producing a malformed URL. A guard on the broader /models/{model}: pattern would prevent this from silently constructing a wrong URL.
| if api_base.endswith(f"/models/{model}:{endpoint}"): | |
| url = api_base | |
| elif api_base.endswith(f"/models/{model}"): | |
| url = f"{api_base}:{endpoint}" | |
| else: | |
| url = "{}/models/{}:{}".format( | |
| api_base.rstrip("/"), model, endpoint | |
| ) | |
| if api_base.endswith(f"/models/{model}:{endpoint}"): | |
| url = api_base | |
| elif api_base.endswith(f"/models/{model}"): | |
| url = f"{api_base}:{endpoint}" | |
| elif f"/models/{model}:" in api_base: | |
| # api_base already contains a routed path for this model but | |
| # with a different endpoint – swap the endpoint rather than | |
| # appending a second /models/… segment. | |
| url = api_base[: api_base.rfind(f"/models/{model}:")] + f"/models/{model}:{endpoint}" | |
| else: | |
| url = "{}/models/{}:{}".format( | |
| api_base.rstrip("/"), model, endpoint | |
| ) |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
Quick follow-up: I closed the earlier routing attempts (#26980, #26982) so this PR is now the only active PR for the Gemini custom This is the clean review path:
The bug breaks deployments where |
|
🤖 litellm-agent: This PR is currently BLOCKED from merge. Score: 4/5 ❌ Why blocked:
Details: Score docked for: 1 unresolved reviewer concern (greptile). Fix the issues above and push an update — the bot will re-review automatically.
|
|
Hi maintainers, gentle ping on this bug fix. This PR is now the only active PR for #26979 after closing the earlier routing attempts. It is a small 2-file change against Could someone take a look when possible, or let me know if this should be routed differently? |
Summary
/models/{model}:{endpoint}route when Geminiapi_basealready includes the full routeapi_basevalues that already point at/models/{model}prefixes without duplicating the model pathapi_basehandlingValidation
uv run pytest tests/test_litellm/llms/vertex_ai/test_vertex_llm_base.py -k 'custom_proxy or full_route or api_base or credential_project_validation'uv run ruff check litellm/llms/vertex_ai/vertex_llm_base.py tests/test_litellm/llms/vertex_ai/test_vertex_llm_base.pyContext
This is the clean OSS-staging re-open of the same fix after identifying that the previous PR routing was wrong and the branch ancestry pulled in unrelated diff.
Related: