litellm - 💡(How to fix) Fix [Feature]: Support for mREP endpoint for vertex AI [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
BerriAI/litellm#23766Fetched 2026-04-08 00:49:14
View on GitHub
Comments
1
Participants
2
Timeline
5
Reactions
1
Author
Participants
Timeline (top)
labeled ×3commented ×1subscribed ×1

Root Cause

The use_psc_endpoint_format=True path is also not correct for mREPs because it uses /endpoints/ instead of /publishers/google/models/:

Fix Action

Fix / Workaround

Current workaround

  • Putting the whole URL as api_base https://aiplatform.us.rep.googleapis.com/v1/projects/my-project/locations/us/publishers/google/models/gemini-3.1-pro-preview so that the api:endpoint forms the correct endpoint.

Code Example

https://aiplatform.us.rep.googleapis.com/v1/projects/{PROJECT}/locations/us/publishers/google/models/{MODEL}:generateContent

---

https://aiplatform.us.rep.googleapis.com:generateContent

---

url = "{}:{}".format(api_base, endpoint)

---

url = "{}/{}/projects/{}/locations/{}/endpoints/{}:{}".format(
    api_base.rstrip("/"),
    version,
    vertex_project,
    vertex_location,
    model_for_url,
    endpoint,
)

---

{api_base}/v1/projects/{vertex_project}/locations/{vertex_location}/publishers/google/models/{model}:{endpoint}

---

# litellm_config.yaml
model_list:
  - model_name: gemini-3-pro-preview
    litellm_params:
      model: vertex_ai/gemini-3.1-pro-preview
      vertex_project: my-project
      vertex_location: us
      api_base: https://aiplatform.us.rep.googleapis.com
      vertex_credentials: /path/to/creds.json

---

import litellm

response = litellm.completion(
    model="gemini-3.1-pro-preview",
    messages=[{"role": "user", "content": "hello"}],
)
RAW_BUFFERClick to expand / collapse

Check for existing issues

  • I have searched the existing issues and checked that my issue is not a duplicate.

The Feature

Vertex AI Multi-Region Endpoints (mREPs) generate an incorrect URL when using api_base with vertex_ai/ models.

Google recently introduced for Vertex AI, which guarantee data residency within a jurisdiction. The mREP base URL format is https://aiplatform.us.rep.googleapis.com (note: no region prefix like us-central1-).

Expected URL format (per Google's docs):

https://aiplatform.us.rep.googleapis.com/v1/projects/{PROJECT}/locations/us/publishers/google/models/{MODEL}:generateContent

Actual URL generated by LiteLLM:

https://aiplatform.us.rep.googleapis.com:generateContent

Relevant code

In litellm/llms/vertex_ai/vertex_llm_base.py, the _check_custom_proxy method handles custom api_base for Vertex AI. When api_base is set and use_psc_endpoint_format is False (the default), it falls through to:

url = "{}:{}".format(api_base, endpoint)

This strips the entire /v1/projects/.../locations/.../publishers/google/models/... path and just appends :{endpoint} to the base URL.

The use_psc_endpoint_format=True path is also not correct for mREPs because it uses /endpoints/ instead of /publishers/google/models/:

url = "{}/{}/projects/{}/locations/{}/endpoints/{}:{}".format(
    api_base.rstrip("/"),
    version,
    vertex_project,
    vertex_location,
    model_for_url,
    endpoint,
)

Expected behavior

When api_base is set to an mREP endpoint like https://aiplatform.us.rep.googleapis.com, the generated URL should preserve the standard Vertex AI path structure:

{api_base}/v1/projects/{vertex_project}/locations/{vertex_location}/publishers/google/models/{model}:{endpoint}

How to reproduce

# litellm_config.yaml
model_list:
  - model_name: gemini-3-pro-preview
    litellm_params:
      model: vertex_ai/gemini-3.1-pro-preview
      vertex_project: my-project
      vertex_location: us
      api_base: https://aiplatform.us.rep.googleapis.com
      vertex_credentials: /path/to/creds.json
import litellm

response = litellm.completion(
    model="gemini-3.1-pro-preview",
    messages=[{"role": "user", "content": "hello"}],
)

The request will be sent to https://aiplatform.us.rep.googleapis.com:generateContent instead of https://aiplatform.us.rep.googleapis.com/v1/projects/my-project/locations/us/publishers/google/models/gemini-3.1-pro-preview:generateContent.

Current workaround

  • Putting the whole URL as api_base https://aiplatform.us.rep.googleapis.com/v1/projects/my-project/locations/us/publishers/google/models/gemini-3.1-pro-preview so that the api:endpoint forms the correct endpoint.

LiteLLM version

1.80.8

Motivation, pitch

Google recently introduced for Vertex AI, which guarantee data residency within a jurisdiction. Given it is a key feature for a lot of org it would be nice to have it as feature out of the box.

What part of LiteLLM is this about?

Proxy

LiteLLM is hiring a founding backend engineer, are you interested in joining us and shipping to all our users?

No

Twitter / LinkedIn details

https://www.linkedin.com/in/bharatsinha23/

extent analysis

Fix Plan

To fix the issue with generating incorrect URLs when using api_base with vertex_ai/ models, we need to modify the _check_custom_proxy method in litellm/llms/vertex_ai/vertex_llm_base.py.

Here are the steps:

  • Modify the url construction when use_psc_endpoint_format is False to preserve the standard Vertex AI path structure.
  • Update the url construction when use_psc_endpoint_format is True to use the correct path for mREPs.

Code Changes

# In litellm/llms/vertex_ai/vertex_llm_base.py

def _check_custom_proxy(self, api_base, endpoint):
    # ...
    if use_psc_endpoint_format:
        # Update the path to use /publishers/google/models/ instead of /endpoints/
        url = "{}/{}/projects/{}/locations/{}/publishers/google/models/{}:{}".format(
            api_base.rstrip("/"),
            version,
            vertex_project,
            vertex_location,
            model_for_url,
            endpoint,
        )
    else:
        # Preserve the standard Vertex AI path structure
        url = "{}/v1/projects/{}/locations/{}/publishers/google/models/{}:{}".format(
            api_base,
            vertex_project,
            vertex_location,
            model_for_url,
            endpoint,
        )
    # ...

Verification

To verify the fix, you can use the provided litellm_config.yaml and test the completion function with the gemini-3.1-pro-preview model. The generated URL should now be in the correct format:

https://aiplatform.us.rep.googleapis.com/v1/projects/my-project/locations/us/publishers/google/models/gemini-3.1-pro-preview:generateContent

You can check the URL by printing the url variable in the _check_custom_proxy method or by using a debugger to inspect the value.

Extra Tips

  • Make sure to test the fix with different api_base values and models to ensure the correct URL is generated in all cases.
  • Consider adding additional logging or error handling to handle cases where the api_base or model is invalid.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

When api_base is set to an mREP endpoint like https://aiplatform.us.rep.googleapis.com, the generated URL should preserve the standard Vertex AI path structure:

{api_base}/v1/projects/{vertex_project}/locations/{vertex_location}/publishers/google/models/{model}:{endpoint}

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

litellm - 💡(How to fix) Fix [Feature]: Support for mREP endpoint for vertex AI [1 comments, 2 participants]