diff --git a/litellm/constants.py b/litellm/constants.py index 8e80c07b4ed..7ec7b5a749c 100644 --- a/litellm/constants.py +++ b/litellm/constants.py @@ -1080,6 +1080,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://api.cheapaimodel.ai/v1", ] @@ -1163,6 +1164,7 @@ openai_compatible_providers: Final[list[str]] = [ "sail", "reka", "streamlake", + "cheapaimodel", ] 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 ad47b334ed4..ff84662992e 100644 --- a/litellm/llms/openai_like/providers.json +++ b/litellm/llms/openai_like/providers.json @@ -292,5 +292,11 @@ "preserve_cache_control": true }, "supported_endpoints": ["/v1/chat/completions"] + }, + "cheapaimodel": { + "base_url": "https://api.cheapaimodel.ai/v1", + "api_key_env": "CHEAPAIMODEL_API_KEY", + "api_base_env": "CHEAPAIMODEL_API_BASE", + "supported_endpoints": ["/v1/chat/completions"] } } diff --git a/litellm/model_prices_and_context_window_backup.json b/litellm/model_prices_and_context_window_backup.json index 0799a298942..473ea7f8815 100644 --- a/litellm/model_prices_and_context_window_backup.json +++ b/litellm/model_prices_and_context_window_backup.json @@ -81100,5 +81100,165 @@ "output_cost_per_token": 0.0, "source": "https://inference.baseten.co/v1/models", "supports_vision": true + }, + "cheapaimodel/deepseek-v4-1-flash": { + "cache_read_input_token_cost": 4.187022e-09, + "input_cost_per_token": 2.093511e-07, + "litellm_provider": "cheapaimodel", + "max_input_tokens": 1000000, + "max_output_tokens": 384000, + "mode": "chat", + "off_peak_pricing": { + "cache_read_input_token_cost": 2.093511e-09, + "input_cost_per_token": 1.0467555e-07, + "output_cost_per_token": 4.187022e-07, + "windows": [ + { + "hours_utc": [ + "00:00-01:00", + "04:00-06:00", + "10:00-00:00" + ], + "weekdays": [ + 1, + 2, + 3, + 4, + 5 + ] + }, + { + "hours_utc": "00:00-00:00", + "weekdays": [ + 6, + 7 + ] + } + ] + }, + "output_cost_per_token": 8.374044e-07, + "source": "https://cheapaimodel.ai/pricing", + "supported_endpoints": [ + "/v1/chat/completions" + ], + "supports_function_calling": true, + "supports_native_streaming": true, + "supports_prompt_caching": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_system_messages": true, + "supports_tool_choice": true, + "supports_vision": true, + "reasoning_effort_levels": [ + "low", + "high", + "max" + ] + }, + "cheapaimodel/glm-5.3": { + "cache_read_input_token_cost": 1.8143762e-07, + "input_cost_per_token": 9.769718e-07, + "litellm_provider": "cheapaimodel", + "max_input_tokens": 1000000, + "max_output_tokens": 128000, + "mode": "chat", + "output_cost_per_token": 3.0704828e-06, + "source": "https://cheapaimodel.ai/pricing", + "supported_endpoints": [ + "/v1/chat/completions" + ], + "supports_function_calling": true, + "supports_native_streaming": true, + "supports_prompt_caching": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_system_messages": true, + "supports_tool_choice": true, + "supports_vision": false, + "reasoning_effort_levels": [ + "low", + "high", + "max" + ] + }, + "cheapaimodel/glm-5.3-flash": { + "cache_read_input_token_cost": 2.093511e-08, + "input_cost_per_token": 1.0467555e-07, + "litellm_provider": "cheapaimodel", + "max_input_tokens": 1000000, + "max_output_tokens": 128000, + "mode": "chat", + "output_cost_per_token": 3.489185e-07, + "source": "https://cheapaimodel.ai/pricing", + "supported_endpoints": [ + "/v1/chat/completions" + ], + "supports_function_calling": true, + "supports_native_streaming": true, + "supports_prompt_caching": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_system_messages": true, + "supports_tool_choice": true, + "supports_vision": true, + "reasoning_effort_levels": [ + "low", + "high", + "max" + ] + }, + "cheapaimodel/grok-4.7": { + "cache_read_input_token_cost": 4.97395e-08, + "input_cost_per_token": 1.98958e-07, + "litellm_provider": "cheapaimodel", + "max_input_tokens": 500000, + "max_output_tokens": 500000, + "mode": "chat", + "output_cost_per_token": 5.96874e-07, + "source": "https://cheapaimodel.ai/pricing", + "supported_endpoints": [ + "/v1/chat/completions" + ], + "supports_function_calling": true, + "supports_native_streaming": true, + "supports_prompt_caching": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_system_messages": true, + "supports_tool_choice": true, + "supports_vision": true, + "reasoning_effort_levels": [ + "low", + "medium", + "high", + "xhigh" + ] + }, + "cheapaimodel/kimi-k3": { + "cache_creation_input_token_cost": 2.093511e-06, + "cache_read_input_token_cost": 2.093511e-07, + "input_cost_per_token": 2.093511e-06, + "litellm_provider": "cheapaimodel", + "max_input_tokens": 1048576, + "max_output_tokens": 1048576, + "mode": "chat", + "output_cost_per_token": 1.0467555e-05, + "source": "https://cheapaimodel.ai/pricing", + "supported_endpoints": [ + "/v1/chat/completions" + ], + "supports_function_calling": true, + "supports_native_streaming": true, + "supports_prompt_caching": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_system_messages": true, + "supports_tool_choice": true, + "supports_vision": true, + "reasoning_effort_levels": [ + "low", + "high", + "max" + ] } } diff --git a/litellm/provider_endpoints_support_backup.json b/litellm/provider_endpoints_support_backup.json index d33e61026df..8daf7c3ec36 100644 --- a/litellm/provider_endpoints_support_backup.json +++ b/litellm/provider_endpoints_support_backup.json @@ -3422,6 +3422,32 @@ "generateContent": true } }, + "cheapaimodel": { + "display_name": "cheapaimodel (`cheapaimodel`)", + "url": "https://docs.litellm.ai/docs/providers/cheapaimodel", + "endpoints": { + "chat_completions": true, + "responses": true, + "text_completion": true, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, + "a2a": true, + "generateContent": true + } + }, "recraft": { "display_name": "Recraft (`recraft`)", "url": "https://docs.litellm.ai/docs/providers/recraft", diff --git a/litellm/proxy/public_endpoints/provider_create_fields.json b/litellm/proxy/public_endpoints/provider_create_fields.json index df3af4ad487..48d7f2c3a08 100644 --- a/litellm/proxy/public_endpoints/provider_create_fields.json +++ b/litellm/proxy/public_endpoints/provider_create_fields.json @@ -4340,5 +4340,33 @@ } ], "default_model_placeholder": "bigmodel/glm-5.3" + }, + { + "provider": "CHEAPAIMODEL", + "provider_display_name": "cheapaimodel", + "litellm_provider": "cheapaimodel", + "credential_fields": [ + { + "key": "api_base", + "label": "API Base", + "placeholder": "https://api.cheapaimodel.ai/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": "cheapaimodel/deepseek-v4-1-flash" } ] diff --git a/litellm/types/utils.py b/litellm/types/utils.py index 5905aaa3380..992a738b972 100644 --- a/litellm/types/utils.py +++ b/litellm/types/utils.py @@ -4611,6 +4611,7 @@ class LlmProviders(str, Enum): CORTECS = "cortecs" SCX_AI = "scx-ai" PRISM = "prism" + CHEAPAIMODEL = "cheapaimodel" OPENINFER = "openinfer" INFERENCEAPIS = "inferenceapis" ZEROGPU = "zerogpu" diff --git a/model_prices_and_context_window.json b/model_prices_and_context_window.json index 0799a298942..473ea7f8815 100644 --- a/model_prices_and_context_window.json +++ b/model_prices_and_context_window.json @@ -81100,5 +81100,165 @@ "output_cost_per_token": 0.0, "source": "https://inference.baseten.co/v1/models", "supports_vision": true + }, + "cheapaimodel/deepseek-v4-1-flash": { + "cache_read_input_token_cost": 4.187022e-09, + "input_cost_per_token": 2.093511e-07, + "litellm_provider": "cheapaimodel", + "max_input_tokens": 1000000, + "max_output_tokens": 384000, + "mode": "chat", + "off_peak_pricing": { + "cache_read_input_token_cost": 2.093511e-09, + "input_cost_per_token": 1.0467555e-07, + "output_cost_per_token": 4.187022e-07, + "windows": [ + { + "hours_utc": [ + "00:00-01:00", + "04:00-06:00", + "10:00-00:00" + ], + "weekdays": [ + 1, + 2, + 3, + 4, + 5 + ] + }, + { + "hours_utc": "00:00-00:00", + "weekdays": [ + 6, + 7 + ] + } + ] + }, + "output_cost_per_token": 8.374044e-07, + "source": "https://cheapaimodel.ai/pricing", + "supported_endpoints": [ + "/v1/chat/completions" + ], + "supports_function_calling": true, + "supports_native_streaming": true, + "supports_prompt_caching": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_system_messages": true, + "supports_tool_choice": true, + "supports_vision": true, + "reasoning_effort_levels": [ + "low", + "high", + "max" + ] + }, + "cheapaimodel/glm-5.3": { + "cache_read_input_token_cost": 1.8143762e-07, + "input_cost_per_token": 9.769718e-07, + "litellm_provider": "cheapaimodel", + "max_input_tokens": 1000000, + "max_output_tokens": 128000, + "mode": "chat", + "output_cost_per_token": 3.0704828e-06, + "source": "https://cheapaimodel.ai/pricing", + "supported_endpoints": [ + "/v1/chat/completions" + ], + "supports_function_calling": true, + "supports_native_streaming": true, + "supports_prompt_caching": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_system_messages": true, + "supports_tool_choice": true, + "supports_vision": false, + "reasoning_effort_levels": [ + "low", + "high", + "max" + ] + }, + "cheapaimodel/glm-5.3-flash": { + "cache_read_input_token_cost": 2.093511e-08, + "input_cost_per_token": 1.0467555e-07, + "litellm_provider": "cheapaimodel", + "max_input_tokens": 1000000, + "max_output_tokens": 128000, + "mode": "chat", + "output_cost_per_token": 3.489185e-07, + "source": "https://cheapaimodel.ai/pricing", + "supported_endpoints": [ + "/v1/chat/completions" + ], + "supports_function_calling": true, + "supports_native_streaming": true, + "supports_prompt_caching": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_system_messages": true, + "supports_tool_choice": true, + "supports_vision": true, + "reasoning_effort_levels": [ + "low", + "high", + "max" + ] + }, + "cheapaimodel/grok-4.7": { + "cache_read_input_token_cost": 4.97395e-08, + "input_cost_per_token": 1.98958e-07, + "litellm_provider": "cheapaimodel", + "max_input_tokens": 500000, + "max_output_tokens": 500000, + "mode": "chat", + "output_cost_per_token": 5.96874e-07, + "source": "https://cheapaimodel.ai/pricing", + "supported_endpoints": [ + "/v1/chat/completions" + ], + "supports_function_calling": true, + "supports_native_streaming": true, + "supports_prompt_caching": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_system_messages": true, + "supports_tool_choice": true, + "supports_vision": true, + "reasoning_effort_levels": [ + "low", + "medium", + "high", + "xhigh" + ] + }, + "cheapaimodel/kimi-k3": { + "cache_creation_input_token_cost": 2.093511e-06, + "cache_read_input_token_cost": 2.093511e-07, + "input_cost_per_token": 2.093511e-06, + "litellm_provider": "cheapaimodel", + "max_input_tokens": 1048576, + "max_output_tokens": 1048576, + "mode": "chat", + "output_cost_per_token": 1.0467555e-05, + "source": "https://cheapaimodel.ai/pricing", + "supported_endpoints": [ + "/v1/chat/completions" + ], + "supports_function_calling": true, + "supports_native_streaming": true, + "supports_prompt_caching": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_system_messages": true, + "supports_tool_choice": true, + "supports_vision": true, + "reasoning_effort_levels": [ + "low", + "high", + "max" + ] } } diff --git a/provider_endpoints_support.json b/provider_endpoints_support.json index d33e61026df..8daf7c3ec36 100644 --- a/provider_endpoints_support.json +++ b/provider_endpoints_support.json @@ -3422,6 +3422,32 @@ "generateContent": true } }, + "cheapaimodel": { + "display_name": "cheapaimodel (`cheapaimodel`)", + "url": "https://docs.litellm.ai/docs/providers/cheapaimodel", + "endpoints": { + "chat_completions": true, + "responses": true, + "text_completion": true, + "embeddings": false, + "image_generations": false, + "image_edits": false, + "audio_transcriptions": false, + "audio_speech": false, + "rerank": false, + "ocr": false, + "search": false, + "moderations": false, + "realtime": false, + "video_generations": false, + "batches": false, + "messages": true, + "interactions": true, + "systemone": false, + "a2a": true, + "generateContent": true + } + }, "recraft": { "display_name": "Recraft (`recraft`)", "url": "https://docs.litellm.ai/docs/providers/recraft", diff --git a/tests/unit/llms/openai_like/test_cheapaimodel_provider.py b/tests/unit/llms/openai_like/test_cheapaimodel_provider.py new file mode 100644 index 00000000000..29e16167b04 --- /dev/null +++ b/tests/unit/llms/openai_like/test_cheapaimodel_provider.py @@ -0,0 +1,170 @@ +import json +from pathlib import Path +from typing import Final + +import pytest +import respx + +import litellm + + +def test_cheapaimodel_provider_resolution(monkeypatch: pytest.MonkeyPatch): + from litellm.litellm_core_utils.get_llm_provider_logic import get_llm_provider + + monkeypatch.setenv("CHEAPAIMODEL_API_KEY", "cheapaimodel-test-key") + + model, provider, api_key, api_base = get_llm_provider( + model="cheapaimodel/deepseek-v4-1-flash", + custom_llm_provider=None, + api_base=None, + api_key=None, + ) + + assert model == "deepseek-v4-1-flash" + assert provider == "cheapaimodel" + assert api_key == "cheapaimodel-test-key" + assert api_base == "https://api.cheapaimodel.ai/v1" + + +def test_cheapaimodel_provider_keeps_explicit_credentials(monkeypatch: pytest.MonkeyPatch): + from litellm.litellm_core_utils.get_llm_provider_logic import get_llm_provider + + monkeypatch.setenv("CHEAPAIMODEL_API_KEY", "cheapaimodel-env-key") + + _, provider, api_key, api_base = get_llm_provider( + model="cheapaimodel/kimi-k3", + custom_llm_provider=None, + api_base="https://cheapaimodel.internal.example/v1", + api_key="cheapaimodel-explicit-key", + ) + + assert provider == "cheapaimodel" + assert api_key == "cheapaimodel-explicit-key" + assert api_base == "https://cheapaimodel.internal.example/v1" + + +CHEAPAIMODEL_MODELS = tuple(sorted(name for name in litellm.model_cost if name.startswith("cheapaimodel/"))) + + +def test_cheapaimodel_models_registered(): + assert CHEAPAIMODEL_MODELS == ( + "cheapaimodel/deepseek-v4-1-flash", + "cheapaimodel/glm-5.3", + "cheapaimodel/glm-5.3-flash", + "cheapaimodel/grok-4.7", + "cheapaimodel/kimi-k3", + ) + + +@pytest.mark.parametrize("model", CHEAPAIMODEL_MODELS) +def test_cheapaimodel_model_cost_and_capabilities(model: str): + from litellm.cost_calculator import cost_per_token + + model_info = litellm.get_model_info(model) + + assert 0 < model_info["cache_read_input_token_cost"] < model_info["input_cost_per_token"] + assert model_info["output_cost_per_token"] > 0 + assert 0 < model_info["max_output_tokens"] <= model_info["max_input_tokens"] + assert model_info["litellm_provider"] == "cheapaimodel" + assert model_info["mode"] == "chat" + assert model_info["supports_function_calling"] is True + assert model_info["supports_reasoning"] is True + assert model_info["supports_response_schema"] is True + assert litellm.supports_vision(model) is model_info["supports_vision"] + + if model == "cheapaimodel/deepseek-v4-1-flash": + return # time-of-day pricing, covered below + prompt_cost, completion_cost = cost_per_token( + model=model, + prompt_tokens=1_000_000, + completion_tokens=1_000_000, + custom_llm_provider="cheapaimodel", + ) + assert prompt_cost == pytest.approx(model_info["input_cost_per_token"] * 1_000_000) + assert completion_cost == pytest.approx(model_info["output_cost_per_token"] * 1_000_000) + + +def test_cheapaimodel_deepseek_has_off_peak_pricing(): + entry = litellm.model_cost["cheapaimodel/deepseek-v4-1-flash"] + off_peak = entry["off_peak_pricing"] + + # Off-peak is half the peak rate, as on DeepSeek's own API. + assert off_peak["input_cost_per_token"] == pytest.approx(entry["input_cost_per_token"] / 2) + assert off_peak["output_cost_per_token"] == pytest.approx(entry["output_cost_per_token"] / 2) + assert off_peak["cache_read_input_token_cost"] == pytest.approx(entry["cache_read_input_token_cost"] / 2) + assert off_peak["windows"] == litellm.model_cost["deepseek/deepseek-v4-flash"]["off_peak_pricing"]["windows"] + + +def test_cheapaimodel_backup_registry_mirrors_cost_map(): + package_root = Path(litellm.__file__).parent + cost_map = json.loads((package_root.parent / "model_prices_and_context_window.json").read_text()) + backup = json.loads((package_root / "model_prices_and_context_window_backup.json").read_text()) + entries = {name: entry for name, entry in cost_map.items() if name.startswith("cheapaimodel/")} + + assert tuple(sorted(entries)) == CHEAPAIMODEL_MODELS + assert entries == {name: backup[name] for name in entries} + + +def test_cheapaimodel_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(provider for provider in providers if provider["litellm_provider"] == "cheapaimodel") + + assert entry["provider"] == "CHEAPAIMODEL" + assert entry["provider_display_name"] == "cheapaimodel" + assert entry["default_model_placeholder"] == "cheapaimodel/deepseek-v4-1-flash" + assert {field["key"]: field["required"] for field in entry["credential_fields"]} == { + "api_base": False, + "api_key": True, + } + + +def test_cheapaimodel_supported_endpoints(): + matrix_path = Path(litellm.__file__).parent / "provider_endpoints_support_backup.json" + endpoints = json.loads(matrix_path.read_text())["providers"]["cheapaimodel"]["endpoints"] + + # The matrix is generated by scripts/generate_provider_endpoints_support.py, which + # also marks the endpoints LiteLLM bridges onto chat completions. cheapaimodel itself + # serves no embeddings, images, audio or rerank. + assert endpoints["chat_completions"] is True + for name in ("embeddings", "image_generations", "audio_transcriptions", "audio_speech", "rerank"): + assert endpoints[name] is False, name + + +def test_cheapaimodel_chat_completion_request(): + with respx.mock() as upstream: + route: Final = upstream.post("https://api.cheapaimodel.ai/v1/chat/completions").respond( + 200, + json={ + "id": "chatcmpl-cheapaimodel", + "object": "chat.completion", + "created": 1_793_000_000, + "model": "deepseek-v4-1-flash", + "choices": [ + { + "index": 0, + "message": { + "role": "assistant", + "content": "Hello from cheapaimodel", + "reasoning_content": "Say hello.", + }, + "finish_reason": "stop", + } + ], + "usage": {"prompt_tokens": 4, "completion_tokens": 5, "total_tokens": 9}, + }, + ) + response: Final = litellm.completion( + model="cheapaimodel/deepseek-v4-1-flash", + messages=[{"role": "user", "content": "Say hello"}], + api_key="cheapaimodel-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.cheapaimodel.ai/v1/chat/completions" + assert request.headers["authorization"] == "Bearer cheapaimodel-test-key" + assert body["model"] == "deepseek-v4-1-flash" + assert response.choices[0].message.content == "Hello from cheapaimodel" + assert response.choices[0].message.reasoning_content == "Say hello."