mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-10 22:41:41 +00:00
fix: preserve prefix only for native OpenRouter models (single-segment)
Native models like openrouter/auto, openrouter/free have no extra '/' after the prefix. Provider-routed models like openrouter/anthropic/claude have extra segments and need prefix stripping. Condition: only early-return when model after 'openrouter/' has no '/'.
This commit is contained in:
parent
ad07d7faad
commit
302e33ba92
1 changed files with 11 additions and 0 deletions
|
|
@ -158,6 +158,17 @@ def get_llm_provider( # noqa: PLR0915
|
|||
): # handle scenario where model="azure/*" and custom_llm_provider="azure"
|
||||
model = custom_llm_provider + "/" + model
|
||||
|
||||
# Native OpenRouter models have IDs like "openrouter/auto" where the
|
||||
# "openrouter/" prefix is part of the actual model name on the API.
|
||||
# Only preserve prefix for single-segment native models (no extra '/'),
|
||||
# not for provider-routed models like "openrouter/anthropic/claude-3.5-sonnet".
|
||||
if (
|
||||
custom_llm_provider == "openrouter"
|
||||
and model.startswith("openrouter/")
|
||||
and "/" not in model[len("openrouter/"):]
|
||||
):
|
||||
return model, custom_llm_provider, dynamic_api_key, api_base
|
||||
|
||||
if api_key and api_key.startswith("os.environ/"):
|
||||
dynamic_api_key = get_secret_str(api_key)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue