mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-08 03:08:45 +00:00
feat: add TrustedRouter as a JSON-configured OpenAI-compatible provider
TrustedRouter (https://trustedrouter.com) is an OpenAI-compatible LLM router. Added via the JSON provider registry, following the parasail/libertai pattern: providers.json entry, openai_compatible_providers/endpoints lists, LlmProviders enum, and unit tests covering the registry, constants, env-var config, and prefix routing
This commit is contained in:
parent
493bca667b
commit
b0169bcec7
4 changed files with 68 additions and 0 deletions
|
|
@ -788,6 +788,7 @@ openai_compatible_endpoints: Final[list] = [
|
|||
"https://api.inference.wandb.ai/v1",
|
||||
"https://api.clarifai.com/v2/ext/openai/v1",
|
||||
"https://api.libertai.io/v1",
|
||||
"https://api.trustedrouter.com/v1",
|
||||
"https://pinstripes.io/v1",
|
||||
"https://api.meta.ai/v1",
|
||||
"https://api.cognition.ai/v1",
|
||||
|
|
@ -837,6 +838,7 @@ openai_compatible_providers: Final[list] = [
|
|||
"chutes", # Chutes - JSON-configured provider
|
||||
"parasail", # Parasail - JSON-configured provider
|
||||
"libertai", # LibertAI - JSON-configured provider
|
||||
"trustedrouter", # TrustedRouter - JSON-configured provider
|
||||
"featherless_ai",
|
||||
"nscale",
|
||||
"nebius",
|
||||
|
|
|
|||
|
|
@ -200,5 +200,11 @@
|
|||
"temperature_max": 1.99
|
||||
},
|
||||
"supported_endpoints": ["/v1/chat/completions"]
|
||||
},
|
||||
"trustedrouter": {
|
||||
"base_url": "https://api.trustedrouter.com/v1",
|
||||
"api_key_env": "TRUSTEDROUTER_API_KEY",
|
||||
"api_base_env": "TRUSTEDROUTER_API_BASE",
|
||||
"supported_endpoints": ["/v1/chat/completions", "/v1/responses"]
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3831,6 +3831,7 @@ class LlmProviders(str, Enum):
|
|||
XIAOMI_MIMO = "xiaomi_mimo"
|
||||
TENSORMESH = "tensormesh"
|
||||
LIBERTAI = "libertai"
|
||||
TRUSTEDROUTER = "trustedrouter"
|
||||
PINSTRIPES = "pinstripes"
|
||||
COGNITION = "cognition"
|
||||
SCX_AI = "scx-ai"
|
||||
|
|
|
|||
59
tests/test_litellm/llms/trustedrouter/test_trustedrouter.py
Normal file
59
tests/test_litellm/llms/trustedrouter/test_trustedrouter.py
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
import os
|
||||
from unittest.mock import patch
|
||||
|
||||
TRUSTEDROUTER_API_BASE = "https://api.trustedrouter.com/v1"
|
||||
|
||||
|
||||
def test_trustedrouter_json_registry():
|
||||
import litellm
|
||||
from litellm.llms.openai_like.json_loader import JSONProviderRegistry
|
||||
|
||||
assert litellm.LlmProviders.TRUSTEDROUTER.value == "trustedrouter"
|
||||
assert litellm.LlmProviders("trustedrouter") == litellm.LlmProviders.TRUSTEDROUTER
|
||||
assert JSONProviderRegistry.exists("trustedrouter")
|
||||
config = JSONProviderRegistry.get("trustedrouter")
|
||||
assert config is not None
|
||||
assert config.base_url == TRUSTEDROUTER_API_BASE
|
||||
assert config.api_key_env == "TRUSTEDROUTER_API_KEY"
|
||||
assert config.api_base_env == "TRUSTEDROUTER_API_BASE"
|
||||
assert "/v1/chat/completions" in config.supported_endpoints
|
||||
assert "/v1/responses" in config.supported_endpoints
|
||||
|
||||
|
||||
def test_trustedrouter_listed_in_openai_compatible_providers():
|
||||
from litellm.constants import (
|
||||
openai_compatible_endpoints,
|
||||
openai_compatible_providers,
|
||||
)
|
||||
|
||||
assert "trustedrouter" in openai_compatible_providers
|
||||
assert TRUSTEDROUTER_API_BASE in openai_compatible_endpoints
|
||||
|
||||
|
||||
def test_trustedrouter_dynamic_config_env_vars():
|
||||
from litellm.llms.openai_like.dynamic_config import create_config_class
|
||||
from litellm.llms.openai_like.json_loader import JSONProviderRegistry
|
||||
|
||||
config = create_config_class(JSONProviderRegistry.get("trustedrouter"))()
|
||||
|
||||
with patch.dict(
|
||||
os.environ,
|
||||
{
|
||||
"TRUSTEDROUTER_API_KEY": "test-key",
|
||||
"TRUSTEDROUTER_API_BASE": "https://example.com/v1",
|
||||
},
|
||||
):
|
||||
api_base, api_key = config._get_openai_compatible_provider_info(None, None)
|
||||
|
||||
assert api_base == "https://example.com/v1"
|
||||
assert api_key == "test-key"
|
||||
|
||||
|
||||
def test_trustedrouter_provider_detection_by_prefix():
|
||||
from litellm.litellm_core_utils.get_llm_provider_logic import get_llm_provider
|
||||
|
||||
model, provider, _, api_base = get_llm_provider("trustedrouter/zdr")
|
||||
|
||||
assert model == "zdr"
|
||||
assert provider == "trustedrouter"
|
||||
assert api_base == TRUSTEDROUTER_API_BASE
|
||||
Loading…
Add table
Reference in a new issue