Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

fix: preserve prefix only for native OpenRouter models (single-segment)

Imgyu Kim302e33ba9226
diff --git a/litellm/litellm_core_utils/get_llm_provider_logic.py b/litellm/litellm_core_utils/get_llm_provider_logic.py
index 2870a92aabc..f96c2e47e6a 100644
--- a/litellm/litellm_core_utils/get_llm_provider_logic.py
+++ b/litellm/litellm_core_utils/get_llm_provider_logic.py
@@ -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)