Skip to content

Fix URL construction bug and add proxy server warnings for Gemini models #13698

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kankute-sameer
Copy link
Contributor

Fix URL construction bug and add proxy server warnings for Gemini models

Relevant issues

Fixes #13693 - Invalid port error when using Gemini models with LiteLLM proxy server

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have Added testing in the tests/litellm/ directory, Adding at least 1 test is a hard requirement - see details
  • I have added a screenshot of my new test passing locally
  • 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

Type

🐛 Bug Fix
🧹 Refactoring

Changes

Bug Fix: URL Construction Error

  • Fixed malformed URL construction in _check_custom_proxy method
  • Changed from "{}:{}".format(api_base, endpoint) to "{}/{}".format(api_base.rstrip('/'), endpoint.lstrip('/'))
  • Resolves Invalid port: '4000:generateContent' error

Enhanced Error Handling

  • Added warning when using Gemini models with proxy server api_base
  • Added targeted 404 error handling with actionable guidance
  • Improved developer experience with clear error messages

⚠️ Important Note: Architectural Limitation

We have NOT fixed the fundamental architectural issue where Gemini models automatically route to /generateContent endpoints when using a LiteLLM proxy server.

What Still Happens

  • Gemini models still hit /generateContent endpoint
  • Proxy servers still return 404 (they only support OpenAI-compatible endpoints)
  • Users still need to use custom_llm_provider="openai" as a workaround

Why This Can't Be Fully Fixed Here

This is a design-level architectural mismatch between:

  1. LiteLLM Gemini integration (designed for direct Google API calls)([Feature]: Support setting custom api_base for vertex_ai_beta models #4317)
  2. LiteLLM Proxy servers (designed for OpenAI-compatible endpoints)

Copy link

vercel bot commented Aug 18, 2025

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

Project Deployment Preview Comments Updated (UTC)
litellm Ready Ready Preview Comment Aug 18, 2025 7:31am

)
raise VertexAIError(
status_code=error_code,
message=f"{err.response.text or 'Not Found'} | {hint}",
Copy link
Contributor

Choose a reason for hiding this comment

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

this will throw an error on python 3.8

can you avoid using |

@@ -301,7 +301,7 @@ def _check_custom_proxy(
"""
if api_base:
if custom_llm_provider == "gemini":
url = "{}:{}".format(api_base, endpoint)
url = "{}/{}".format(api_base.rstrip("/"), endpoint.lstrip("/"))
Copy link
Contributor

Choose a reason for hiding this comment

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

the : is for google ai studio calls because that's how the endpoint is constructed.

curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent" \

see :generateContent

Your changes would cause these requests to fail @kankute-sameer

Copy link
Contributor

@krrishdholakia krrishdholakia left a comment

Choose a reason for hiding this comment

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

current pr would break for google ai studio

@@ -301,7 +301,7 @@ def _check_custom_proxy(
"""
if api_base:
if custom_llm_provider == "gemini":
url = "{}:{}".format(api_base, endpoint)
url = "{}/{}".format(api_base.rstrip("/"), endpoint.lstrip("/"))
Copy link

Choose a reason for hiding this comment

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

api_base + endpoint seems to still be missing the model information

If api_base=https://api.example.com/v1beta, appending the generateContent endpoint results in the URL https://api.example.com/v1beta:generateContent.

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

Successfully merging this pull request may close these issues.

[Bug] Invalid URL construction when using litellm.completion under the Python SDK
3 participants