diff --git a/litellm/constants.py b/litellm/constants.py index 8d05115e76e..e8afddc452a 100644 --- a/litellm/constants.py +++ b/litellm/constants.py @@ -1097,6 +1097,7 @@ openai_compatible_endpoints: Final[list[str]] = [ "https://gigachat.devices.sberbank.ru/api/v1", "https://api.openinfer.ai/v1", "https://vanchin.streamlake.ai/api/gateway/v1/endpoints", + "https://aistupidlevel.info/v1", ] @@ -1169,6 +1170,7 @@ openai_compatible_providers: Final[list[str]] = [ "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/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 f937e4d2f75..c5256bb7bd4 100644 --- a/litellm/llms/openai_like/providers.json +++ b/litellm/llms/openai_like/providers.json @@ -314,5 +314,16 @@ "supports_function_calling": true, "supports_reasoning": true } + }, + "aistupidlevel": { + "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/litellm/model_prices_and_context_window_backup.json b/litellm/model_prices_and_context_window_backup.json index 1bda9d24c8e..4cc7a1f0afc 100644 --- a/litellm/model_prices_and_context_window_backup.json +++ b/litellm/model_prices_and_context_window_backup.json @@ -73989,6 +73989,116 @@ "supports_tool_choice": true, "supports_vision": true }, + "aistupidlevel/auto": { + "litellm_provider": "aistupidlevel", + "max_input_tokens": 262144, + "max_output_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, + "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, + "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, + "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, + "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, + "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, + "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, + "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, + "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, + "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/litellm/provider_endpoints_support_backup.json b/litellm/provider_endpoints_support_backup.json index 00fee0a0d5a..7db886a5dd4 100644 --- a/litellm/provider_endpoints_support_backup.json +++ b/litellm/provider_endpoints_support_backup.json @@ -215,6 +215,24 @@ "generateContent": 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 5ded2fa5f5e..f8196ca5376 100644 --- a/litellm/proxy/public_endpoints/provider_create_fields.json +++ b/litellm/proxy/public_endpoints/provider_create_fields.json @@ -91,6 +91,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 ba29a67a36c..4d4404fb6ce 100644 --- a/litellm/types/utils.py +++ b/litellm/types/utils.py @@ -4781,6 +4781,7 @@ class LlmProviders(str, Enum): REKA = "reka" STREAMLAKE = "streamlake" WALLY = "wally" + AISTUPIDLEVEL = "aistupidlevel" LITELLM_AGENT = "litellm_agent" CURSOR = "cursor" BEDROCK_MANTLE = "bedrock_mantle" diff --git a/model_prices_and_context_window.json b/model_prices_and_context_window.json index 1bda9d24c8e..4cc7a1f0afc 100644 --- a/model_prices_and_context_window.json +++ b/model_prices_and_context_window.json @@ -73989,6 +73989,116 @@ "supports_tool_choice": true, "supports_vision": true }, + "aistupidlevel/auto": { + "litellm_provider": "aistupidlevel", + "max_input_tokens": 262144, + "max_output_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, + "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, + "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, + "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, + "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, + "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, + "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, + "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, + "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, + "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/provider_endpoints_support.json b/provider_endpoints_support.json index 00fee0a0d5a..7db886a5dd4 100644 --- a/provider_endpoints_support.json +++ b/provider_endpoints_support.json @@ -215,6 +215,24 @@ "generateContent": 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..283e25c1b57 --- /dev/null +++ b/tests/unit/llms/openai_like/test_aistupidlevel_provider.py @@ -0,0 +1,271 @@ +""" +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_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()) + 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" + + +@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 = [ + { + "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"