From ab42a6de5edd3fd622ee7c3185566e7ebdb121aa Mon Sep 17 00:00:00 2001 From: Collin Kendra <118716256+czkendra@users.noreply.github.com> Date: Mon, 12 Oct 2026 15:56:19 -0400 Subject: [PATCH] feat: add UplinkSwitch as an OpenAI-compatible provider --- litellm/constants.py | 2 + litellm/llms/openai_like/providers.json | 5 + .../provider_endpoints_support_backup.json | 18 ++ .../provider_create_fields.json | 28 +++ litellm/types/utils.py | 1 + provider_endpoints_support.json | 18 ++ .../openai_like/test_uplinkswitch_provider.py | 203 ++++++++++++++++++ 7 files changed, 275 insertions(+) create mode 100644 tests/unit/llms/openai_like/test_uplinkswitch_provider.py diff --git a/litellm/constants.py b/litellm/constants.py index 38d16d61d7b..3ce5a410d69 100644 --- a/litellm/constants.py +++ b/litellm/constants.py @@ -1011,6 +1011,7 @@ openai_compatible_endpoints: Final[list] = [ "https://api.scx.ai/v1", "https://api.prisminference.com/v1", "https://api.reka.ai/v1", + "https://api.uplinkswitch.com/v1", "https://gigachat.devices.sberbank.ru/api/v1", ] @@ -1088,6 +1089,7 @@ openai_compatible_providers: Final[list] = [ "prism", "sail", "reka", + "uplinkswitch", ] OPENAI_AUDIO_TRANSCRIPTION_PROVIDERS: Final = frozenset({"openai"} | frozenset(openai_compatible_providers)) diff --git a/litellm/llms/openai_like/providers.json b/litellm/llms/openai_like/providers.json index f3aa7768928..1937c8e1111 100644 --- a/litellm/llms/openai_like/providers.json +++ b/litellm/llms/openai_like/providers.json @@ -223,5 +223,10 @@ "base_url": "https://api.reka.ai/v1", "api_key_env": "REKA_API_KEY", "api_base_env": "REKA_API_BASE" + }, + "uplinkswitch": { + "base_url": "https://api.uplinkswitch.com/v1", + "api_key_env": "UPLINKSWITCH_API_KEY", + "api_base_env": "UPLINKSWITCH_API_BASE" } } diff --git a/litellm/provider_endpoints_support_backup.json b/litellm/provider_endpoints_support_backup.json index a0e75b1f02d..4bb98c0047d 100644 --- a/litellm/provider_endpoints_support_backup.json +++ b/litellm/provider_endpoints_support_backup.json @@ -2298,6 +2298,24 @@ "interactions": true } }, + "uplinkswitch": { + "display_name": "UplinkSwitch (`uplinkswitch`)", + "url": "https://docs.litellm.ai/docs/providers/uplinkswitch", + "endpoints": { + "chat_completions": true, + "messages": true, + "responses": true, + "embeddings": false, + "image_generations": false, + "audio_transcriptions": false, + "audio_speech": false, + "moderations": false, + "batches": false, + "rerank": false, + "a2a": false, + "interactions": false + } + }, "v0": { "display_name": "V0 (`v0`)", "url": "https://docs.litellm.ai/docs/providers/v0", diff --git a/litellm/proxy/public_endpoints/provider_create_fields.json b/litellm/proxy/public_endpoints/provider_create_fields.json index 633e9edf71c..c393ff729bb 100644 --- a/litellm/proxy/public_endpoints/provider_create_fields.json +++ b/litellm/proxy/public_endpoints/provider_create_fields.json @@ -3471,6 +3471,34 @@ ], "default_model_placeholder": "typesafe/jev-latest" }, + { + "provider": "UPLINKSWITCH", + "provider_display_name": "UplinkSwitch", + "litellm_provider": "uplinkswitch", + "credential_fields": [ + { + "key": "api_base", + "label": "API Base", + "placeholder": "https://api.uplinkswitch.com/v1", + "tooltip": null, + "required": false, + "field_type": "text", + "options": null, + "default_value": null + }, + { + "key": "api_key", + "label": "API Key", + "placeholder": null, + "tooltip": null, + "required": true, + "field_type": "password", + "options": null, + "default_value": null + } + ], + "default_model_placeholder": "uplinkswitch/gpt-6.1-sol" + }, { "provider": "V0", "provider_display_name": "V0", diff --git a/litellm/types/utils.py b/litellm/types/utils.py index f7385a6d92d..55db27e22f7 100644 --- a/litellm/types/utils.py +++ b/litellm/types/utils.py @@ -4315,6 +4315,7 @@ class LlmProviders(str, Enum): META = "meta" SAIL = "sail" REKA = "reka" + UPLINKSWITCH = "uplinkswitch" LITELLM_AGENT = "litellm_agent" CURSOR = "cursor" BEDROCK_MANTLE = "bedrock_mantle" diff --git a/provider_endpoints_support.json b/provider_endpoints_support.json index 5b179b2e8d8..fd1e05be445 100644 --- a/provider_endpoints_support.json +++ b/provider_endpoints_support.json @@ -2657,6 +2657,24 @@ "interactions": true } }, + "uplinkswitch": { + "display_name": "UplinkSwitch (`uplinkswitch`)", + "url": "https://docs.litellm.ai/docs/providers/uplinkswitch", + "endpoints": { + "chat_completions": true, + "messages": true, + "responses": true, + "embeddings": false, + "image_generations": false, + "audio_transcriptions": false, + "audio_speech": false, + "moderations": false, + "batches": false, + "rerank": false, + "a2a": false, + "interactions": false + } + }, "v0": { "display_name": "V0 (`v0`)", "url": "https://docs.litellm.ai/docs/providers/v0", diff --git a/tests/unit/llms/openai_like/test_uplinkswitch_provider.py b/tests/unit/llms/openai_like/test_uplinkswitch_provider.py new file mode 100644 index 00000000000..b0b641106b1 --- /dev/null +++ b/tests/unit/llms/openai_like/test_uplinkswitch_provider.py @@ -0,0 +1,203 @@ +import json +from pathlib import Path +from typing import Final + +import pytest +import respx + +import litellm +from litellm.caching.llm_caching_handler import LLMClientCache + +_CHAT_COMPLETION: Final = { + "id": "chatcmpl_uplinkswitch", + "object": "chat.completion", + "created": 1_790_000_000, + "model": "gpt-6.1-sol", + "choices": [ + { + "index": 0, + "message": {"role": "assistant", "content": "Hello from UplinkSwitch"}, + "finish_reason": "stop", + } + ], + "usage": {"prompt_tokens": 4, "completion_tokens": 3, "total_tokens": 7}, +} + + +def test_uplinkswitch_is_a_registered_provider(): + assert litellm.LlmProviders.UPLINKSWITCH.value == "uplinkswitch" + assert "uplinkswitch" in litellm.provider_list + assert "uplinkswitch" in litellm.constants.openai_compatible_providers + + +def test_uplinkswitch_provider_resolution(monkeypatch: pytest.MonkeyPatch): + from litellm.litellm_core_utils.get_llm_provider_logic import get_llm_provider + + monkeypatch.setenv("UPLINKSWITCH_API_KEY", "uplinkswitch-test-key") + + model, provider, api_key, api_base = get_llm_provider( + model="uplinkswitch/gpt-6.1-sol", + custom_llm_provider=None, + api_base=None, + api_key=None, + ) + + assert model == "gpt-6.1-sol" + assert provider == "uplinkswitch" + assert api_key == "uplinkswitch-test-key" + assert api_base == "https://api.uplinkswitch.com/v1" + + +def test_uplinkswitch_provider_keeps_explicit_credentials(monkeypatch: pytest.MonkeyPatch): + from litellm.litellm_core_utils.get_llm_provider_logic import get_llm_provider + + monkeypatch.setenv("UPLINKSWITCH_API_KEY", "uplinkswitch-env-key") + monkeypatch.setenv("UPLINKSWITCH_API_BASE", "https://uplinkswitch.env.example/v1") + + _, provider, api_key, api_base = get_llm_provider( + model="uplinkswitch/gpt-6.1-sol", + custom_llm_provider=None, + api_base="https://uplinkswitch.internal.example/v1", + api_key="uplinkswitch-explicit-key", + ) + + assert provider == "uplinkswitch" + assert api_key == "uplinkswitch-explicit-key" + assert api_base == "https://uplinkswitch.internal.example/v1" + + +def test_uplinkswitch_api_base_env_overrides_default(monkeypatch: pytest.MonkeyPatch): + from litellm.litellm_core_utils.get_llm_provider_logic import get_llm_provider + + monkeypatch.setenv("UPLINKSWITCH_API_KEY", "uplinkswitch-env-key") + monkeypatch.setenv("UPLINKSWITCH_API_BASE", "https://uplinkswitch.env.example/v1") + + _, provider, _, api_base = get_llm_provider( + model="uplinkswitch/gpt-6.1-sol", + custom_llm_provider=None, + api_base=None, + api_key=None, + ) + + assert provider == "uplinkswitch" + assert api_base == "https://uplinkswitch.env.example/v1" + + +def test_uplinkswitch_api_base_autodetects_provider(monkeypatch: pytest.MonkeyPatch): + from litellm.litellm_core_utils.get_llm_provider_logic import get_llm_provider + + monkeypatch.setenv("UPLINKSWITCH_API_KEY", "uplinkswitch-env-key") + + model, provider, api_key, api_base = get_llm_provider( + model="gpt-6.1-sol", + custom_llm_provider=None, + api_base="https://api.uplinkswitch.com/v1", + api_key=None, + ) + + assert model == "gpt-6.1-sol" + assert provider == "uplinkswitch" + assert api_key == "uplinkswitch-env-key" + assert api_base == "https://api.uplinkswitch.com/v1" + + +def test_uplinkswitch_is_available_in_add_model_form(): + fields_path = Path(litellm.__file__).parent / "proxy" / "public_endpoints" / "provider_create_fields.json" + providers = json.loads(fields_path.read_text()) + uplinkswitch = next(provider for provider in providers if provider["litellm_provider"] == "uplinkswitch") + + assert uplinkswitch["provider"] == "UPLINKSWITCH" + assert uplinkswitch["provider_display_name"] == "UplinkSwitch" + assert uplinkswitch["default_model_placeholder"] == "uplinkswitch/gpt-6.1-sol" + assert {field["key"]: field["required"] for field in uplinkswitch["credential_fields"]} == { + "api_base": False, + "api_key": True, + } + + +def test_uplinkswitch_supported_endpoints(): + expected: Final = { + "chat_completions": True, + "messages": True, + "responses": True, + "embeddings": False, + "image_generations": False, + "audio_transcriptions": False, + "audio_speech": False, + "moderations": False, + "batches": False, + "rerank": False, + "a2a": False, + "interactions": False, + } + backup_path = Path(litellm.__file__).parent / "provider_endpoints_support_backup.json" + root_path = Path(litellm.__file__).parent.parent / "provider_endpoints_support.json" + + assert json.loads(backup_path.read_text())["providers"]["uplinkswitch"]["endpoints"] == expected + assert json.loads(root_path.read_text())["providers"]["uplinkswitch"]["endpoints"] == expected + + +def test_uplinkswitch_chat_completion_request(): + with respx.mock() as upstream: + route: Final = upstream.post("https://api.uplinkswitch.com/v1/chat/completions").respond( + 200, json=_CHAT_COMPLETION + ) + response: Final = litellm.completion( + model="uplinkswitch/gpt-6.1-sol", + messages=[{"role": "user", "content": "Say hello"}], + api_key="uplinkswitch-test-key", + ) + + request: Final = route.calls.last.request + body: Final = json.loads(request.content) + assert route.call_count == 1 + assert str(request.url) == "https://api.uplinkswitch.com/v1/chat/completions" + assert request.headers["authorization"] == "Bearer uplinkswitch-test-key" + assert body["model"] == "gpt-6.1-sol" + assert body["messages"] == [{"role": "user", "content": "Say hello"}] + assert response.choices[0].message.content == "Hello from UplinkSwitch" + + +def test_uplinkswitch_responses_request_is_bridged_to_chat_completions(): + with respx.mock() as upstream: + route: Final = upstream.post("https://api.uplinkswitch.com/v1/chat/completions").respond( + 200, json=_CHAT_COMPLETION + ) + response: Final = litellm.responses( + model="uplinkswitch/gpt-6.1-sol", + input="Say hello", + api_key="uplinkswitch-test-key", + ) + + request: Final = route.calls.last.request + body: Final = json.loads(request.content) + assert route.call_count == 1 + assert request.headers["authorization"] == "Bearer uplinkswitch-test-key" + assert body["model"] == "gpt-6.1-sol" + assert body["messages"] == [{"role": "user", "content": "Say hello"}] + assert response.output[0].content[0].text == "Hello from UplinkSwitch" + + +@pytest.mark.asyncio +async def test_uplinkswitch_anthropic_messages_request_is_bridged_to_chat_completions(monkeypatch: pytest.MonkeyPatch): + monkeypatch.setattr(litellm, "disable_aiohttp_transport", True) + monkeypatch.setattr(litellm, "in_memory_llm_clients_cache", LLMClientCache()) + with respx.mock() as upstream: + route: Final = upstream.post("https://api.uplinkswitch.com/v1/chat/completions").respond( + 200, json=_CHAT_COMPLETION + ) + response: Final = await litellm.anthropic.messages.acreate( + model="uplinkswitch/gpt-6.1-sol", + messages=[{"role": "user", "content": "Say hello"}], + max_tokens=32, + api_key="uplinkswitch-test-key", + ) + + request: Final = route.calls.last.request + body: Final = json.loads(request.content) + assert route.call_count == 1 + assert request.headers["authorization"] == "Bearer uplinkswitch-test-key" + assert body["model"] == "gpt-6.1-sol" + assert body["messages"] == [{"role": "user", "content": "Say hello"}] + assert body["max_tokens"] == 32 + assert response["content"][0]["text"] == "Hello from UplinkSwitch"