litellm - 💡(How to fix) Fix [Feature]: Public way to detect URL-templated providers (vertex_ai/bedrock) so wrappers can decide whether to forward api_base [1 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#26724Fetched 2026-04-29 06:12:31
View on GitHub
Comments
0
Participants
1
Timeline
3
Reactions
0
Participants
Timeline (top)
labeled ×3

Error Message

from dotenv import load_dotenv; load_dotenv() import litellm

Works — SDK templates the URL from vertex_project + vertex_location.

ok = litellm.completion( model="vertex_ai/gemini-2.5-flash", messages=[{"role": "user", "content": "pong"}], vertex_project="my-project", vertex_location="global", ) print(ok.choices[0].message.content) # -> "pong"

Fails — same args plus a valid-looking api_base. 404 with empty body.

litellm.completion( model="vertex_ai/gemini-2.5-flash", messages=[{"role": "user", "content": "pong"}], vertex_project="my-project", vertex_location="global", api_base="https://aiplatform.googleapis.com/", )

litellm.NotFoundError: Vertex_aiException -

(status_code=404, body is empty)

Root Cause

  1. litellm.get_llm_provider(model, api_base=sentinel)[3] — echoes the sentinel back unchanged for every provider; can't distinguish templated from override-friendly.
  2. litellm.openai_compatible_providers — third-party OpenAI-compat list only; doesn't cover vertex_ai/bedrock/ollama/openai/anthropic.
  3. ProviderConfigManager.get_provider_chat_config(model, provider).get_complete_url(...) — for vertex_ai this just echoes the input api_base back, because the real URL builder lives in litellm.llms.vertex_ai.vertex_llm_base._get_token_and_url, which is private.
  4. Method-presence heuristics (get_api_base etc.) — ollama's config class lacks get_api_base but Ollama does honor api_base, so the signal is unreliable.

Code Example

litellm.provider_honors_api_base("vertex_ai")  # -> False
litellm.provider_honors_api_base("bedrock")    # -> False
litellm.provider_honors_api_base("ollama")     # -> True
litellm.provider_honors_api_base("openai")     # -> True

---

from dotenv import load_dotenv; load_dotenv()
import litellm

# WorksSDK templates the URL from vertex_project + vertex_location.
ok = litellm.completion(
    model="vertex_ai/gemini-2.5-flash",
    messages=[{"role": "user", "content": "pong"}],
    vertex_project="my-project",
    vertex_location="global",
)
print(ok.choices[0].message.content)  # -> "pong"

# Fails — same args plus a valid-looking api_base. 404 with empty body.
litellm.completion(
    model="vertex_ai/gemini-2.5-flash",
    messages=[{"role": "user", "content": "pong"}],
    vertex_project="my-project",
    vertex_location="global",
    api_base="https://aiplatform.googleapis.com/",
)
# litellm.NotFoundError: Vertex_aiException -
# (status_code=404, body is empty)
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

Add a public introspection surface that tells callers whether a given custom_llm_provider honors the api_base kwarg, or templates its URL internally from vertex_project + vertex_location / aws_region / etc.

Smallest viable shape:

litellm.provider_honors_api_base("vertex_ai")  # -> False
litellm.provider_honors_api_base("bedrock")    # -> False
litellm.provider_honors_api_base("ollama")     # -> True
litellm.provider_honors_api_base("openai")     # -> True

Or as an attribute on the LlmProviders enum.

Bigger but more useful alternatives:

  1. Make vertex_ai's URL builder honor api_base as the host portion only, and still template the path ({api_base}/v1/projects/.../locations/.../models/...:generateContent). Then api_base passthrough would be safe across all providers.
  2. At minimum, raise a typed error when api_base is passed to a provider that ignores it, instead of silently 404ing — e.g. LiteLLMUnsupportedKwarg("api_base", provider="vertex_ai").

Happy to send a PR for option 1 (the introspection function) if maintainers think it's the right shape.

Motivation, pitch

I'm building a wrapper around litellm.completion(...) that exposes a single "endpoint URL" config field to its users. The wrapper has no public way to know whether forwarding that URL as api_base is safe for the configured provider, and the failure mode for the wrong choice is silent and hard to diagnose.

Repro on litellm 1.83.12, Python 3.11:

from dotenv import load_dotenv; load_dotenv()
import litellm

# Works — SDK templates the URL from vertex_project + vertex_location.
ok = litellm.completion(
    model="vertex_ai/gemini-2.5-flash",
    messages=[{"role": "user", "content": "pong"}],
    vertex_project="my-project",
    vertex_location="global",
)
print(ok.choices[0].message.content)  # -> "pong"

# Fails — same args plus a valid-looking api_base. 404 with empty body.
litellm.completion(
    model="vertex_ai/gemini-2.5-flash",
    messages=[{"role": "user", "content": "pong"}],
    vertex_project="my-project",
    vertex_location="global",
    api_base="https://aiplatform.googleapis.com/",
)
# litellm.NotFoundError: Vertex_aiException -
# (status_code=404, body is empty)

The exception class is NotFoundError but the message and body are blank. A successful call's _hidden_params["api_base"] shows the canonical templated URL: global-aiplatform.googleapis.com/v1/projects/.../locations/global/publishers/google/models/gemini-2.5-flash:generateContent, which differs from the bare aiplatform.googleapis.com host the user would naturally declare.

What I tried for runtime detection (all dead ends):

  1. litellm.get_llm_provider(model, api_base=sentinel)[3] — echoes the sentinel back unchanged for every provider; can't distinguish templated from override-friendly.
  2. litellm.openai_compatible_providers — third-party OpenAI-compat list only; doesn't cover vertex_ai/bedrock/ollama/openai/anthropic.
  3. ProviderConfigManager.get_provider_chat_config(model, provider).get_complete_url(...) — for vertex_ai this just echoes the input api_base back, because the real URL builder lives in litellm.llms.vertex_ai.vertex_llm_base._get_token_and_url, which is private.
  4. Method-presence heuristics (get_api_base etc.) — ollama's config class lacks get_api_base but Ollama does honor api_base, so the signal is unreliable.

This is a real gap for anyone building configuration layers on top of litellm; right now we have to either hardcode a per-provider list or expose the routing detail to our own users.

What part of LiteLLM is this about?

SDK (litellm Python package)

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

No

Twitter / LinkedIn details

No response

extent analysis

TL;DR

Implement an introspection function to check if a given custom_llm_provider honors the api_base keyword argument.

Guidance

  • Add a public introspection surface, such as litellm.provider_honors_api_base("vertex_ai"), to determine if a provider honors api_base.
  • Consider raising a typed error when api_base is passed to a provider that ignores it, instead of silently 404ing.
  • Modify the vertex_ai URL builder to honor api_base as the host portion only, while still templating the path.
  • Implement a check to prevent passing api_base to providers that do not support it.

Example

def provider_honors_api_base(provider):
    # Implementation details depend on the specific providers and their behavior
    # For example:
    if provider == "vertex_ai" or provider == "bedrock":
        return False
    elif provider == "ollama" or provider == "openai":
        return True
    else:
        raise ValueError("Unknown provider")

Notes

The exact implementation of the introspection function will depend on the specific behavior of each provider. This example provides a basic starting point.

Recommendation

Apply a workaround by implementing the introspection function to check if a provider honors api_base, as this will provide a clear and safe way to determine the correct behavior for each provider.

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…

Still need to ship something?

×6

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

Back to top recommendations

TRENDING