From 8a5919c47f6c4c825605a4338906f97cfa70b5e1 Mon Sep 17 00:00:00 2001 From: Studio Platforms Date: Mon, 19 Oct 2026 17:08:53 +0200 Subject: [PATCH 1/4] feat(providers): add AI Stupid Level as a JSON-configured OpenAI-compatible provider --- litellm/constants.py | 2 + litellm/llms/openai_like/providers.json | 8 + .../provider_endpoints_support_backup.json | 18 ++ .../provider_create_fields.json | 28 +++ litellm/types/utils.py | 1 + provider_endpoints_support.json | 18 ++ .../test_aistupidlevel_provider.py | 214 ++++++++++++++++++ 7 files changed, 289 insertions(+) create mode 100644 tests/unit/llms/openai_like/test_aistupidlevel_provider.py diff --git a/litellm/constants.py b/litellm/constants.py index da95b97036a..2dcde3a25bf 100644 --- a/litellm/constants.py +++ b/litellm/constants.py @@ -1031,6 +1031,7 @@ openai_compatible_endpoints: Final[list[str]] = [ "https://api.reka.ai/v1", "https://gigachat.devices.sberbank.ru/api/v1", "https://api.openinfer.ai/v1", + "https://aistupidlevel.info/v1", ] @@ -1099,6 +1100,7 @@ openai_compatible_providers: Final[list] = [ "docker_model_runner", "ragflow", "pinstripes", # Pinstripes - JSON-configured provider + "aistupidlevel", # AI Stupid Level - JSON-configured provider "openinfer", "darkbloom", "meta", # Meta Model API (Muse Spark) - JSON-configured provider diff --git a/litellm/llms/openai_like/providers.json b/litellm/llms/openai_like/providers.json index 36337fddbdc..d331c97bed8 100644 --- a/litellm/llms/openai_like/providers.json +++ b/litellm/llms/openai_like/providers.json @@ -249,5 +249,13 @@ "/v1/responses", "/v1/messages" ] + }, + "aistupidlevel": { + "base_url": "https://aistupidlevel.info/v1", + "api_key_env": "AISTUPIDLEVEL_API_KEY", + "api_base_env": "AISTUPIDLEVEL_API_BASE", + "provider_info": { + "supports_function_calling": true + } } } diff --git a/litellm/provider_endpoints_support_backup.json b/litellm/provider_endpoints_support_backup.json index f95b553c2b4..ff8003a21de 100644 --- a/litellm/provider_endpoints_support_backup.json +++ b/litellm/provider_endpoints_support_backup.json @@ -120,6 +120,24 @@ "interactions": true } }, + "aistupidlevel": { + "display_name": "AI Stupid Level (`aistupidlevel`)", + "url": "https://docs.litellm.ai/docs/providers/aistupidlevel", + "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 + } + }, "amazon_nova": { "display_name": "Amazon Nova (`amazon_nova`)", "url": "https://docs.litellm.ai/docs/providers/amazon_nova", diff --git a/litellm/proxy/public_endpoints/provider_create_fields.json b/litellm/proxy/public_endpoints/provider_create_fields.json index a794854ce19..4aebe958e53 100644 --- a/litellm/proxy/public_endpoints/provider_create_fields.json +++ b/litellm/proxy/public_endpoints/provider_create_fields.json @@ -35,6 +35,34 @@ ], "default_model_placeholder": "aiml/flux-pro/v1.1" }, + { + "provider": "AISTUPIDLEVEL", + "provider_display_name": "AI Stupid Level", + "litellm_provider": "aistupidlevel", + "credential_fields": [ + { + "key": "api_base", + "label": "API Base", + "placeholder": "https://aistupidlevel.info/v1", + "tooltip": null, + "required": false, + "field_type": "text", + "options": null, + "default_value": null + }, + { + "key": "api_key", + "label": "API Key", + "placeholder": "aism_...", + "tooltip": null, + "required": true, + "field_type": "password", + "options": null, + "default_value": null + } + ], + "default_model_placeholder": "aistupidlevel/auto-coding" + }, { "provider": "AI21", "provider_display_name": "Ai21", diff --git a/litellm/types/utils.py b/litellm/types/utils.py index 419c2624111..019eb8fd5c0 100644 --- a/litellm/types/utils.py +++ b/litellm/types/utils.py @@ -4402,6 +4402,7 @@ class LlmProviders(str, Enum): META = "meta" SAIL = "sail" REKA = "reka" + AISTUPIDLEVEL = "aistupidlevel" LITELLM_AGENT = "litellm_agent" CURSOR = "cursor" BEDROCK_MANTLE = "bedrock_mantle" diff --git a/provider_endpoints_support.json b/provider_endpoints_support.json index c2cec2c5490..688d09bb207 100644 --- a/provider_endpoints_support.json +++ b/provider_endpoints_support.json @@ -121,6 +121,24 @@ "interactions": true } }, + "aistupidlevel": { + "display_name": "AI Stupid Level (`aistupidlevel`)", + "url": "https://docs.litellm.ai/docs/providers/aistupidlevel", + "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 + } + }, "amazon_nova": { "display_name": "Amazon Nova (`amazon_nova`)", "url": "https://docs.litellm.ai/docs/providers/amazon_nova", diff --git a/tests/unit/llms/openai_like/test_aistupidlevel_provider.py b/tests/unit/llms/openai_like/test_aistupidlevel_provider.py new file mode 100644 index 00000000000..ee3272cb713 --- /dev/null +++ b/tests/unit/llms/openai_like/test_aistupidlevel_provider.py @@ -0,0 +1,214 @@ +""" +Tests for the AI Stupid Level provider (JSON-configured, OpenAI-compatible). + +AI Stupid Level is a router: the model id is a routing mode such as ``auto-coding``, +or a real model id to pin one model. +""" + +import json +from pathlib import Path +from typing import Final + +import pytest +import respx + +import litellm +from litellm.caching.llm_caching_handler import LLMClientCache +from litellm.litellm_core_utils.get_llm_provider_logic import get_llm_provider + +_BASE: Final = "https://aistupidlevel.info/v1" +_CHAT_COMPLETION: Final = { + "id": "chatcmpl_asl", + "object": "chat.completion", + "created": 1_790_000_000, + "model": "claude-opus-5-5", + "system_fingerprint": "aism_v1_anthropic", + "choices": [ + { + "index": 0, + "message": {"role": "assistant", "content": "Hello from the router"}, + "finish_reason": "stop", + } + ], + "usage": {"prompt_tokens": 4, "completion_tokens": 4, "total_tokens": 8}, +} + + +def test_aistupidlevel_is_a_registered_provider(): + assert litellm.LlmProviders.AISTUPIDLEVEL.value == "aistupidlevel" + assert "aistupidlevel" in litellm.provider_list + assert "aistupidlevel" in litellm.constants.openai_compatible_providers + assert _BASE in litellm.constants.openai_compatible_endpoints + + +def test_aistupidlevel_json_config(): + from litellm.llms.openai_like.json_loader import JSONProviderRegistry + + config = JSONProviderRegistry.get("aistupidlevel") + assert config is not None + assert config.base_url == _BASE + assert config.api_key_env == "AISTUPIDLEVEL_API_KEY" + assert config.api_base_env == "AISTUPIDLEVEL_API_BASE" + # The router accepts max_completion_tokens as sent, so nothing is remapped. + assert config.param_mappings == {} + + +def test_aistupidlevel_provider_resolution(monkeypatch: pytest.MonkeyPatch): + monkeypatch.setenv("AISTUPIDLEVEL_API_KEY", "aism-env-key") + monkeypatch.delenv("AISTUPIDLEVEL_API_BASE", raising=False) + + model, provider, api_key, api_base = get_llm_provider(model="aistupidlevel/auto-coding") + + assert model == "auto-coding" + assert provider == "aistupidlevel" + assert api_key == "aism-env-key" + assert api_base == _BASE + + +def test_aistupidlevel_api_base_env_overrides_default(monkeypatch: pytest.MonkeyPatch): + monkeypatch.setenv("AISTUPIDLEVEL_API_KEY", "aism-env-key") + monkeypatch.setenv("AISTUPIDLEVEL_API_BASE", "https://router.example/v1") + + _, provider, _, api_base = get_llm_provider(model="aistupidlevel/auto-reasoning") + + assert provider == "aistupidlevel" + assert api_base == "https://router.example/v1" + + +def test_aistupidlevel_api_base_autodetects_provider(): + _, provider, _, api_base = get_llm_provider(model="auto-coding", api_base=_BASE) + + assert provider == "aistupidlevel" + assert api_base == _BASE + + +def test_aistupidlevel_routed_models_support_tools(): + """Every routed or pinned model can call tools, so tool params must not be dropped.""" + from litellm.llms.openai_like.dynamic_config import create_config_class + from litellm.llms.openai_like.json_loader import JSONProviderRegistry + + assert litellm.supports_function_calling(model="aistupidlevel/auto-tooling") is True + + config = create_config_class(JSONProviderRegistry.get("aistupidlevel"))() + supported: Final = config.get_supported_openai_params("auto-tooling") + assert "tools" in supported + assert "tool_choice" in supported + + +def test_aistupidlevel_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()) + entry = next(p for p in providers if p["litellm_provider"] == "aistupidlevel") + + assert entry["provider_display_name"] == "AI Stupid Level" + assert entry["default_model_placeholder"] == "aistupidlevel/auto-coding" + assert {field["key"]: field["required"] for field in entry["credential_fields"]} == { + "api_base": False, + "api_key": True, + } + + +def test_aistupidlevel_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"]["aistupidlevel"]["endpoints"] == expected + assert json.loads(root_path.read_text())["providers"]["aistupidlevel"]["endpoints"] == expected + + +def test_aistupidlevel_chat_completion_request(): + with respx.mock() as upstream: + route: Final = upstream.post(f"{_BASE}/chat/completions").respond(200, json=_CHAT_COMPLETION) + response: Final = litellm.completion( + model="aistupidlevel/auto-coding", + messages=[{"role": "user", "content": "Say hello"}], + max_completion_tokens=64, + api_key="aism-test-key", + ) + + request: Final = route.calls.last.request + body: Final = json.loads(request.content) + assert route.call_count == 1 + assert str(request.url) == f"{_BASE}/chat/completions" + assert request.headers["authorization"] == "Bearer aism-test-key" + assert body["model"] == "auto-coding" + assert body["max_completion_tokens"] == 64 + assert response.choices[0].message.content == "Hello from the router" + + +def test_aistupidlevel_tools_are_forwarded(): + tools: Final = [ + { + "type": "function", + "function": { + "name": "get_weather", + "parameters": {"type": "object", "properties": {"city": {"type": "string"}}}, + }, + } + ] + with respx.mock() as upstream: + route: Final = upstream.post(f"{_BASE}/chat/completions").respond(200, json=_CHAT_COMPLETION) + litellm.completion( + model="aistupidlevel/auto-tooling", + messages=[{"role": "user", "content": "Weather in Oslo?"}], + tools=tools, + tool_choice="required", + api_key="aism-test-key", + ) + + body: Final = json.loads(route.calls.last.request.content) + assert body["tools"] == tools + assert body["tool_choice"] == "required" + + +def test_aistupidlevel_responses_request_is_bridged_to_chat_completions(): + with respx.mock() as upstream: + route: Final = upstream.post(f"{_BASE}/chat/completions").respond(200, json=_CHAT_COMPLETION) + response: Final = litellm.responses( + model="aistupidlevel/auto-best", + input="Say hello", + api_key="aism-test-key", + ) + + body: Final = json.loads(route.calls.last.request.content) + assert route.call_count == 1 + assert body["model"] == "auto-best" + assert body["messages"] == [{"role": "user", "content": "Say hello"}] + assert response.output[0].content[0].text == "Hello from the router" + + +@pytest.mark.asyncio +async def test_aistupidlevel_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(f"{_BASE}/chat/completions").respond(200, json=_CHAT_COMPLETION) + response: Final = await litellm.anthropic.messages.acreate( + model="aistupidlevel/auto-coding", + messages=[{"role": "user", "content": "Say hello"}], + max_tokens=32, + api_key="aism-test-key", + ) + + body: Final = json.loads(route.calls.last.request.content) + assert route.call_count == 1 + assert route.calls.last.request.headers["authorization"] == "Bearer aism-test-key" + assert body["model"] == "auto-coding" + assert body["max_tokens"] == 32 + assert response["content"][0]["text"] == "Hello from the router" From 5d35033d2217b7286a951f50caa4ca10b894247f Mon Sep 17 00:00:00 2001 From: Studio Platforms Date: Fri, 23 Oct 2026 12:22:04 +0200 Subject: [PATCH 2/4] feat(aistupidlevel): list the routing modes in the model cost map Adds the 10 routing modes (aistupidlevel/auto, auto-coding, auto-tooling, ...) to the cost map and its backup, in the same shape as the Fireworks router entries: provider, chat mode, the router's limits and capability flags, with no prices. The limits (262,144 in, 64,000 out) are the smallest across the models it routes to. There are no prices because each request is billed by the routed model's provider to the caller's own key. Tools that read model lists from the cost map can now show these modes, and get_model_info resolves them. Co-Authored-By: Claude Opus 5.5 --- ...odel_prices_and_context_window_backup.json | 120 ++++++++++++++++++ model_prices_and_context_window.json | 120 ++++++++++++++++++ .../test_aistupidlevel_provider.py | 21 +++ 3 files changed, 261 insertions(+) diff --git a/litellm/model_prices_and_context_window_backup.json b/litellm/model_prices_and_context_window_backup.json index bb0cdd51d9c..a71c6690b0f 100644 --- a/litellm/model_prices_and_context_window_backup.json +++ b/litellm/model_prices_and_context_window_backup.json @@ -71337,6 +71337,126 @@ "supports_reasoning": true, "supports_vision": true }, + "aistupidlevel/auto": { + "litellm_provider": "aistupidlevel", + "max_input_tokens": 262144, + "max_output_tokens": 64000, + "max_tokens": 64000, + "mode": "chat", + "source": "https://aistupidlevel.info/router/docs#strategies", + "supports_function_calling": true, + "supports_response_schema": true, + "supports_tool_choice": true, + "supports_vision": false + }, + "aistupidlevel/auto-best": { + "litellm_provider": "aistupidlevel", + "max_input_tokens": 262144, + "max_output_tokens": 64000, + "max_tokens": 64000, + "mode": "chat", + "source": "https://aistupidlevel.info/router/docs#strategies", + "supports_function_calling": true, + "supports_response_schema": true, + "supports_tool_choice": true, + "supports_vision": false + }, + "aistupidlevel/auto-coding": { + "litellm_provider": "aistupidlevel", + "max_input_tokens": 262144, + "max_output_tokens": 64000, + "max_tokens": 64000, + "mode": "chat", + "source": "https://aistupidlevel.info/router/docs#strategies", + "supports_function_calling": true, + "supports_response_schema": true, + "supports_tool_choice": true, + "supports_vision": false + }, + "aistupidlevel/auto-fastest-quality": { + "litellm_provider": "aistupidlevel", + "max_input_tokens": 262144, + "max_output_tokens": 64000, + "max_tokens": 64000, + "mode": "chat", + "source": "https://aistupidlevel.info/router/docs#strategies", + "supports_function_calling": true, + "supports_response_schema": true, + "supports_tool_choice": true, + "supports_vision": false + }, + "aistupidlevel/auto-reasoning": { + "litellm_provider": "aistupidlevel", + "max_input_tokens": 262144, + "max_output_tokens": 64000, + "max_tokens": 64000, + "mode": "chat", + "source": "https://aistupidlevel.info/router/docs#strategies", + "supports_function_calling": true, + "supports_response_schema": true, + "supports_tool_choice": true, + "supports_vision": false + }, + "aistupidlevel/auto-tooling": { + "litellm_provider": "aistupidlevel", + "max_input_tokens": 262144, + "max_output_tokens": 64000, + "max_tokens": 64000, + "mode": "chat", + "source": "https://aistupidlevel.info/router/docs#strategies", + "supports_function_calling": true, + "supports_response_schema": true, + "supports_tool_choice": true, + "supports_vision": false + }, + "aistupidlevel/auto-value": { + "litellm_provider": "aistupidlevel", + "max_input_tokens": 262144, + "max_output_tokens": 64000, + "max_tokens": 64000, + "mode": "chat", + "source": "https://aistupidlevel.info/router/docs#strategies", + "supports_function_calling": true, + "supports_response_schema": true, + "supports_tool_choice": true, + "supports_vision": false + }, + "aistupidlevel/auto-value-coding": { + "litellm_provider": "aistupidlevel", + "max_input_tokens": 262144, + "max_output_tokens": 64000, + "max_tokens": 64000, + "mode": "chat", + "source": "https://aistupidlevel.info/router/docs#strategies", + "supports_function_calling": true, + "supports_response_schema": true, + "supports_tool_choice": true, + "supports_vision": false + }, + "aistupidlevel/auto-value-reasoning": { + "litellm_provider": "aistupidlevel", + "max_input_tokens": 262144, + "max_output_tokens": 64000, + "max_tokens": 64000, + "mode": "chat", + "source": "https://aistupidlevel.info/router/docs#strategies", + "supports_function_calling": true, + "supports_response_schema": true, + "supports_tool_choice": true, + "supports_vision": false + }, + "aistupidlevel/auto-value-tooling": { + "litellm_provider": "aistupidlevel", + "max_input_tokens": 262144, + "max_output_tokens": 64000, + "max_tokens": 64000, + "mode": "chat", + "source": "https://aistupidlevel.info/router/docs#strategies", + "supports_function_calling": true, + "supports_response_schema": true, + "supports_tool_choice": true, + "supports_vision": false + }, "bespoke/nimble-latest": { "input_cost_per_token": 0.0, "litellm_provider": "bespoke", diff --git a/model_prices_and_context_window.json b/model_prices_and_context_window.json index bb0cdd51d9c..a71c6690b0f 100644 --- a/model_prices_and_context_window.json +++ b/model_prices_and_context_window.json @@ -71337,6 +71337,126 @@ "supports_reasoning": true, "supports_vision": true }, + "aistupidlevel/auto": { + "litellm_provider": "aistupidlevel", + "max_input_tokens": 262144, + "max_output_tokens": 64000, + "max_tokens": 64000, + "mode": "chat", + "source": "https://aistupidlevel.info/router/docs#strategies", + "supports_function_calling": true, + "supports_response_schema": true, + "supports_tool_choice": true, + "supports_vision": false + }, + "aistupidlevel/auto-best": { + "litellm_provider": "aistupidlevel", + "max_input_tokens": 262144, + "max_output_tokens": 64000, + "max_tokens": 64000, + "mode": "chat", + "source": "https://aistupidlevel.info/router/docs#strategies", + "supports_function_calling": true, + "supports_response_schema": true, + "supports_tool_choice": true, + "supports_vision": false + }, + "aistupidlevel/auto-coding": { + "litellm_provider": "aistupidlevel", + "max_input_tokens": 262144, + "max_output_tokens": 64000, + "max_tokens": 64000, + "mode": "chat", + "source": "https://aistupidlevel.info/router/docs#strategies", + "supports_function_calling": true, + "supports_response_schema": true, + "supports_tool_choice": true, + "supports_vision": false + }, + "aistupidlevel/auto-fastest-quality": { + "litellm_provider": "aistupidlevel", + "max_input_tokens": 262144, + "max_output_tokens": 64000, + "max_tokens": 64000, + "mode": "chat", + "source": "https://aistupidlevel.info/router/docs#strategies", + "supports_function_calling": true, + "supports_response_schema": true, + "supports_tool_choice": true, + "supports_vision": false + }, + "aistupidlevel/auto-reasoning": { + "litellm_provider": "aistupidlevel", + "max_input_tokens": 262144, + "max_output_tokens": 64000, + "max_tokens": 64000, + "mode": "chat", + "source": "https://aistupidlevel.info/router/docs#strategies", + "supports_function_calling": true, + "supports_response_schema": true, + "supports_tool_choice": true, + "supports_vision": false + }, + "aistupidlevel/auto-tooling": { + "litellm_provider": "aistupidlevel", + "max_input_tokens": 262144, + "max_output_tokens": 64000, + "max_tokens": 64000, + "mode": "chat", + "source": "https://aistupidlevel.info/router/docs#strategies", + "supports_function_calling": true, + "supports_response_schema": true, + "supports_tool_choice": true, + "supports_vision": false + }, + "aistupidlevel/auto-value": { + "litellm_provider": "aistupidlevel", + "max_input_tokens": 262144, + "max_output_tokens": 64000, + "max_tokens": 64000, + "mode": "chat", + "source": "https://aistupidlevel.info/router/docs#strategies", + "supports_function_calling": true, + "supports_response_schema": true, + "supports_tool_choice": true, + "supports_vision": false + }, + "aistupidlevel/auto-value-coding": { + "litellm_provider": "aistupidlevel", + "max_input_tokens": 262144, + "max_output_tokens": 64000, + "max_tokens": 64000, + "mode": "chat", + "source": "https://aistupidlevel.info/router/docs#strategies", + "supports_function_calling": true, + "supports_response_schema": true, + "supports_tool_choice": true, + "supports_vision": false + }, + "aistupidlevel/auto-value-reasoning": { + "litellm_provider": "aistupidlevel", + "max_input_tokens": 262144, + "max_output_tokens": 64000, + "max_tokens": 64000, + "mode": "chat", + "source": "https://aistupidlevel.info/router/docs#strategies", + "supports_function_calling": true, + "supports_response_schema": true, + "supports_tool_choice": true, + "supports_vision": false + }, + "aistupidlevel/auto-value-tooling": { + "litellm_provider": "aistupidlevel", + "max_input_tokens": 262144, + "max_output_tokens": 64000, + "max_tokens": 64000, + "mode": "chat", + "source": "https://aistupidlevel.info/router/docs#strategies", + "supports_function_calling": true, + "supports_response_schema": true, + "supports_tool_choice": true, + "supports_vision": false + }, "bespoke/nimble-latest": { "input_cost_per_token": 0.0, "litellm_provider": "bespoke", diff --git a/tests/unit/llms/openai_like/test_aistupidlevel_provider.py b/tests/unit/llms/openai_like/test_aistupidlevel_provider.py index ee3272cb713..87fd0594766 100644 --- a/tests/unit/llms/openai_like/test_aistupidlevel_provider.py +++ b/tests/unit/llms/openai_like/test_aistupidlevel_provider.py @@ -95,6 +95,27 @@ def test_aistupidlevel_routed_models_support_tools(): assert "tool_choice" in supported +def test_aistupidlevel_routing_modes_are_in_the_model_cost_map(monkeypatch: pytest.MonkeyPatch): + """Routing modes carry the router's limits and no fixed price: each request is billed + by the routed model's provider to the caller's own key.""" + cost_map_path = Path(litellm.__file__).parent / "model_prices_and_context_window_backup.json" + modes = {k: v for k, v in json.loads(cost_map_path.read_text()).items() if k.startswith("aistupidlevel/")} + + assert "aistupidlevel/auto-coding" in modes + for name, info in modes.items(): + assert info["litellm_provider"] == "aistupidlevel", name + assert info["mode"] == "chat", name + assert (info["max_input_tokens"], info["max_output_tokens"]) == (262144, 64000), name + assert info["supports_function_calling"] is True, name + assert info["supports_vision"] is False, name + assert not any("cost" in field for field in info), name + + monkeypatch.setattr(litellm, "model_cost", {**litellm.model_cost, **modes}) + info = litellm.get_model_info(model="aistupidlevel/auto-coding") + assert info["max_input_tokens"] == 262144 + assert info["supports_function_calling"] is True + + def test_aistupidlevel_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()) From 9bc7da2adb0137defefd656fca3a667119acfd68 Mon Sep 17 00:00:00 2001 From: Studio Platforms Date: Tue, 27 Oct 2026 09:03:59 +0100 Subject: [PATCH 3/4] fix(aistupidlevel): drop the retired max_tokens field from the cost-map rows Upstream #48471 retired max_tokens in favor of max_input_tokens and max_output_tokens; our routing-mode rows already carry both. --- litellm/model_prices_and_context_window_backup.json | 10 ---------- model_prices_and_context_window.json | 10 ---------- 2 files changed, 20 deletions(-) diff --git a/litellm/model_prices_and_context_window_backup.json b/litellm/model_prices_and_context_window_backup.json index 599c92e4bd1..cebe2107c3f 100644 --- a/litellm/model_prices_and_context_window_backup.json +++ b/litellm/model_prices_and_context_window_backup.json @@ -69698,7 +69698,6 @@ "litellm_provider": "aistupidlevel", "max_input_tokens": 262144, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "source": "https://aistupidlevel.info/router/docs#strategies", "supports_function_calling": true, @@ -69710,7 +69709,6 @@ "litellm_provider": "aistupidlevel", "max_input_tokens": 262144, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "source": "https://aistupidlevel.info/router/docs#strategies", "supports_function_calling": true, @@ -69722,7 +69720,6 @@ "litellm_provider": "aistupidlevel", "max_input_tokens": 262144, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "source": "https://aistupidlevel.info/router/docs#strategies", "supports_function_calling": true, @@ -69734,7 +69731,6 @@ "litellm_provider": "aistupidlevel", "max_input_tokens": 262144, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "source": "https://aistupidlevel.info/router/docs#strategies", "supports_function_calling": true, @@ -69746,7 +69742,6 @@ "litellm_provider": "aistupidlevel", "max_input_tokens": 262144, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "source": "https://aistupidlevel.info/router/docs#strategies", "supports_function_calling": true, @@ -69758,7 +69753,6 @@ "litellm_provider": "aistupidlevel", "max_input_tokens": 262144, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "source": "https://aistupidlevel.info/router/docs#strategies", "supports_function_calling": true, @@ -69770,7 +69764,6 @@ "litellm_provider": "aistupidlevel", "max_input_tokens": 262144, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "source": "https://aistupidlevel.info/router/docs#strategies", "supports_function_calling": true, @@ -69782,7 +69775,6 @@ "litellm_provider": "aistupidlevel", "max_input_tokens": 262144, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "source": "https://aistupidlevel.info/router/docs#strategies", "supports_function_calling": true, @@ -69794,7 +69786,6 @@ "litellm_provider": "aistupidlevel", "max_input_tokens": 262144, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "source": "https://aistupidlevel.info/router/docs#strategies", "supports_function_calling": true, @@ -69806,7 +69797,6 @@ "litellm_provider": "aistupidlevel", "max_input_tokens": 262144, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "source": "https://aistupidlevel.info/router/docs#strategies", "supports_function_calling": true, diff --git a/model_prices_and_context_window.json b/model_prices_and_context_window.json index 599c92e4bd1..cebe2107c3f 100644 --- a/model_prices_and_context_window.json +++ b/model_prices_and_context_window.json @@ -69698,7 +69698,6 @@ "litellm_provider": "aistupidlevel", "max_input_tokens": 262144, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "source": "https://aistupidlevel.info/router/docs#strategies", "supports_function_calling": true, @@ -69710,7 +69709,6 @@ "litellm_provider": "aistupidlevel", "max_input_tokens": 262144, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "source": "https://aistupidlevel.info/router/docs#strategies", "supports_function_calling": true, @@ -69722,7 +69720,6 @@ "litellm_provider": "aistupidlevel", "max_input_tokens": 262144, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "source": "https://aistupidlevel.info/router/docs#strategies", "supports_function_calling": true, @@ -69734,7 +69731,6 @@ "litellm_provider": "aistupidlevel", "max_input_tokens": 262144, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "source": "https://aistupidlevel.info/router/docs#strategies", "supports_function_calling": true, @@ -69746,7 +69742,6 @@ "litellm_provider": "aistupidlevel", "max_input_tokens": 262144, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "source": "https://aistupidlevel.info/router/docs#strategies", "supports_function_calling": true, @@ -69758,7 +69753,6 @@ "litellm_provider": "aistupidlevel", "max_input_tokens": 262144, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "source": "https://aistupidlevel.info/router/docs#strategies", "supports_function_calling": true, @@ -69770,7 +69764,6 @@ "litellm_provider": "aistupidlevel", "max_input_tokens": 262144, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "source": "https://aistupidlevel.info/router/docs#strategies", "supports_function_calling": true, @@ -69782,7 +69775,6 @@ "litellm_provider": "aistupidlevel", "max_input_tokens": 262144, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "source": "https://aistupidlevel.info/router/docs#strategies", "supports_function_calling": true, @@ -69794,7 +69786,6 @@ "litellm_provider": "aistupidlevel", "max_input_tokens": 262144, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "source": "https://aistupidlevel.info/router/docs#strategies", "supports_function_calling": true, @@ -69806,7 +69797,6 @@ "litellm_provider": "aistupidlevel", "max_input_tokens": 262144, "max_output_tokens": 64000, - "max_tokens": 64000, "mode": "chat", "source": "https://aistupidlevel.info/router/docs#strategies", "supports_function_calling": true, From 2df02d226a71dfc35de4f125f48880e52b9ebab3 Mon Sep 17 00:00:00 2001 From: Studio Platforms Date: Thu, 5 Nov 2026 09:37:06 +0100 Subject: [PATCH 4/4] fix(aistupidlevel): never send OpenAI credentials when the provider key is missing With AISTUPIDLEVEL_API_KEY unset and no api_key passed, the shared chat path fell back to litellm.openai_key / OPENAI_API_KEY and sent that key to aistupidlevel.info. JSON providers can now opt in to `special_handling.require_api_key`: the request is refused with an AuthenticationError naming the provider's env var before any client is built (the OpenAI client would otherwise read OPENAI_API_KEY itself). aistupidlevel sets it. Other providers are unchanged. Tests cover sync and async, and that the provider's own key is sent when both are present. --- litellm/llms/openai_like/README.md | 5 ++- litellm/llms/openai_like/providers.json | 3 ++ litellm/main.py | 9 +++++ .../test_aistupidlevel_provider.py | 36 +++++++++++++++++++ 4 files changed, 52 insertions(+), 1 deletion(-) diff --git a/litellm/llms/openai_like/README.md b/litellm/llms/openai_like/README.md index fb00b07c986..4878380a7f3 100644 --- a/litellm/llms/openai_like/README.md +++ b/litellm/llms/openai_like/README.md @@ -62,7 +62,10 @@ That's it! The provider will be automatically loaded and available. // Optional: Special handling flags "special_handling": { - "convert_content_list_to_string": true + "convert_content_list_to_string": true, + // Refuse the request when neither api_key nor api_key_env is set, + // instead of falling back to OpenAI credentials + "require_api_key": true }, // Optional: Capabilities every model of this provider has, used when a diff --git a/litellm/llms/openai_like/providers.json b/litellm/llms/openai_like/providers.json index 99998e25324..c5256bb7bd4 100644 --- a/litellm/llms/openai_like/providers.json +++ b/litellm/llms/openai_like/providers.json @@ -319,6 +319,9 @@ "base_url": "https://aistupidlevel.info/v1", "api_key_env": "AISTUPIDLEVEL_API_KEY", "api_base_env": "AISTUPIDLEVEL_API_BASE", + "special_handling": { + "require_api_key": true + }, "provider_info": { "supports_function_calling": true } diff --git a/litellm/main.py b/litellm/main.py index 8cb133bf76b..a418386a5eb 100644 --- a/litellm/main.py +++ b/litellm/main.py @@ -2792,6 +2792,15 @@ def _complete_custom_openai( raise litellm.AuthenticationError( message="Set BIGMODEL_API_KEY or pass api_key", llm_provider="bigmodel", model=model ) + # A JSON provider with `require_api_key` gets its own key or nothing: without this, the + # fallback below sends litellm.openai_key / OPENAI_API_KEY to the provider's host. + json_provider: Final = None if api_key else JSONProviderRegistry.get(custom_llm_provider) + if json_provider is not None and json_provider.special_handling.get("require_api_key"): + raise litellm.AuthenticationError( + message=f"Set {json_provider.api_key_env} or pass api_key", + llm_provider=custom_llm_provider, + model=model, + ) organization = ( organization or (None if custom_llm_provider == "bigmodel" else litellm.organization or get_secret("OPENAI_ORGANIZATION")) diff --git a/tests/unit/llms/openai_like/test_aistupidlevel_provider.py b/tests/unit/llms/openai_like/test_aistupidlevel_provider.py index 87fd0594766..283e25c1b57 100644 --- a/tests/unit/llms/openai_like/test_aistupidlevel_provider.py +++ b/tests/unit/llms/openai_like/test_aistupidlevel_provider.py @@ -171,6 +171,42 @@ def test_aistupidlevel_chat_completion_request(): assert response.choices[0].message.content == "Hello from the router" +@pytest.mark.asyncio +@pytest.mark.parametrize("use_async", [False, True]) +async def test_aistupidlevel_missing_key_never_sends_openai_credentials( + monkeypatch: pytest.MonkeyPatch, use_async: bool +): + monkeypatch.delenv("AISTUPIDLEVEL_API_KEY", raising=False) + monkeypatch.setenv("OPENAI_API_KEY", "sk-openai-secret") + monkeypatch.setattr(litellm, "openai_key", "sk-openai-secret") + monkeypatch.setattr(litellm, "disable_aiohttp_transport", True) + monkeypatch.setattr(litellm, "in_memory_llm_clients_cache", LLMClientCache()) + with respx.mock(assert_all_called=False) as upstream: + route: Final = upstream.post(f"{_BASE}/chat/completions").respond(200, json=_CHAT_COMPLETION) + with pytest.raises(litellm.AuthenticationError, match="AISTUPIDLEVEL_API_KEY"): + kwargs: Final = { + "model": "aistupidlevel/auto-coding", + "messages": [{"role": "user", "content": "Say hello"}], + } + if use_async: + await litellm.acompletion(**kwargs) + else: + litellm.completion(**kwargs) + + assert route.call_count == 0 + + +def test_aistupidlevel_env_key_is_sent_instead_of_openai_credentials(monkeypatch: pytest.MonkeyPatch): + monkeypatch.setenv("AISTUPIDLEVEL_API_KEY", "aism-env-key") + monkeypatch.setenv("OPENAI_API_KEY", "sk-openai-secret") + monkeypatch.setattr(litellm, "openai_key", "sk-openai-secret") + with respx.mock() as upstream: + route: Final = upstream.post(f"{_BASE}/chat/completions").respond(200, json=_CHAT_COMPLETION) + litellm.completion(model="aistupidlevel/auto-coding", messages=[{"role": "user", "content": "Say hello"}]) + + assert route.calls.last.request.headers["authorization"] == "Bearer aism-env-key" + + def test_aistupidlevel_tools_are_forwarded(): tools: Final = [ {