From 55ebc4f51e8abe802dcb6dca5e2048c3507c90f8 Mon Sep 17 00:00:00 2001 From: Honam <116502099+binbor111@users.noreply.github.com> Date: Thu, 2 Apr 2026 06:00:14 -0700 Subject: [PATCH] test(provider): add tests for chuizi provider routing + fix prefix handling - Add chuizi provider block in _get_openai_compatible_provider_info for prefix routing (chuizi/model-name -> api_base + api_key) - Add 2 tests: prefix routing and API key env var resolution This fixes codecov patch coverage for the chuizi provider addition. --- .../get_llm_provider_logic.py | 9 ++++++++ tests/local_testing/test_get_llm_provider.py | 22 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/litellm/litellm_core_utils/get_llm_provider_logic.py b/litellm/litellm_core_utils/get_llm_provider_logic.py index 373f813ac8e..d9c5e35286d 100644 --- a/litellm/litellm_core_utils/get_llm_provider_logic.py +++ b/litellm/litellm_core_utils/get_llm_provider_logic.py @@ -683,6 +683,15 @@ def _get_openai_compatible_provider_info( # noqa: PLR0915 ) = litellm.LMStudioChatConfig()._get_openai_compatible_provider_info( api_base, api_key ) + elif custom_llm_provider == "chuizi": + # chuizi is openai compatible, unified AI gateway + api_base = ( + api_base + or get_secret("CHUIZI_API_BASE") + or "https://api.chuizi.ai/v1" + ) # type: ignore + + dynamic_api_key = api_key or get_secret_str("CHUIZI_API_KEY") elif custom_llm_provider == "deepseek": # deepseek is openai compatible, we just need to set this to custom_openai and have the api_base be https://api.deepseek.com/v1 api_base = ( diff --git a/tests/local_testing/test_get_llm_provider.py b/tests/local_testing/test_get_llm_provider.py index af0e92e2f47..1535ce513cb 100644 --- a/tests/local_testing/test_get_llm_provider.py +++ b/tests/local_testing/test_get_llm_provider.py @@ -420,3 +420,25 @@ def test_get_llm_provider_use_proxy_arg_true_with_direct_args(): assert provider == "litellm_proxy" assert key == arg_api_key # Should use the argument key assert base == arg_api_base # Should use the argument base + + +def test_get_llm_provider_chuizi(): + """Test that chuizi/ prefix routes to chuizi provider.""" + model, custom_llm_provider, dynamic_api_key, api_base = litellm.get_llm_provider( + model="chuizi/anthropic/claude-sonnet-4-6", + ) + assert custom_llm_provider == "chuizi" + assert model == "anthropic/claude-sonnet-4-6" + assert api_base == "https://api.chuizi.ai/v1" + + +def test_get_llm_provider_chuizi_with_api_key(): + """Test that chuizi provider resolves CHUIZI_API_KEY from env.""" + os.environ["CHUIZI_API_KEY"] = "test-chuizi-key" + model, custom_llm_provider, dynamic_api_key, api_base = litellm.get_llm_provider( + model="chuizi/openai/gpt-4.1", + ) + assert custom_llm_provider == "chuizi" + assert model == "openai/gpt-4.1" + assert dynamic_api_key == "test-chuizi-key" + os.environ.pop("CHUIZI_API_KEY", None)