From f230fb4714f91b381c1dba7e9e92bb85323eb171 Mon Sep 17 00:00:00 2001 From: Mario Date: Thu, 17 Sep 2026 14:10:47 +0800 Subject: [PATCH 1/2] feat(providers): add ainetcafe as a JSON-configured OpenAI-compatible provider Register ainetcafe (Kimi K3 served at native MXFP4 precision) in litellm/llms/openai_like/providers.json, add Kimi-K3 to the cost map with cached-input pricing, and register the provider in the endpoint matrix, the dashboard provider list and the README provider table. --- README.md | 1 + litellm/constants.py | 2 + litellm/llms/openai_like/providers.json | 6 + ...odel_prices_and_context_window_backup.json | 17 ++ .../provider_endpoints_support_backup.json | 17 ++ .../provider_create_fields.json | 28 +++ litellm/types/utils.py | 1 + model_prices_and_context_window.json | 17 ++ provider_endpoints_support.json | 17 ++ .../openai_like/test_ainetcafe_provider.py | 171 ++++++++++++++++++ .../public/assets/logos/ainetcafe.svg | 11 ++ .../components/provider_info_helpers.test.tsx | 15 ++ .../src/components/provider_info_helpers.tsx | 5 + 13 files changed, 308 insertions(+) create mode 100644 tests/test_litellm/llms/openai_like/test_ainetcafe_provider.py create mode 100644 ui/litellm-dashboard/public/assets/logos/ainetcafe.svg diff --git a/README.md b/README.md index 901cc5b0cea..c40cd732ebd 100644 --- a/README.md +++ b/README.md @@ -276,6 +276,7 @@ For MCP OAuth, an upstream may advertise dynamic client registration but refuse | [AI/ML API (`aiml`)](https://docs.litellm.ai/docs/providers/aiml) | ✅ | ✅ | ✅ | ✅ | ✅ | | | | | | | [AI21 (`ai21`)](https://docs.litellm.ai/docs/providers/ai21) | ✅ | ✅ | ✅ | | | | | | | | | [AI21 Chat (`ai21_chat`)](https://docs.litellm.ai/docs/providers/ai21) | ✅ | ✅ | ✅ | | | | | | | | +| [ainetcafe (`ainetcafe`)](https://docs.litellm.ai/docs/providers/ainetcafe) | ✅ | | | | | | | | | | | [Aleph Alpha](https://docs.litellm.ai/docs/providers/aleph_alpha) | ✅ | ✅ | ✅ | | | | | | | | | [Amazon Nova](https://docs.litellm.ai/docs/providers/amazon_nova) | ✅ | ✅ | ✅ | | | | | | | | | [Anthropic (`anthropic`)](https://docs.litellm.ai/docs/providers/anthropic) | ✅ | ✅ | ✅ | | | | | | ✅ | | diff --git a/litellm/constants.py b/litellm/constants.py index 8409a161800..d095e242135 100644 --- a/litellm/constants.py +++ b/litellm/constants.py @@ -914,6 +914,7 @@ openai_compatible_endpoints: Final[list] = [ "https://api.meta.ai/v1", "https://api.cognition.ai/v1", "https://api.scx.ai/v1", + "https://microquickjs.com/v1", "https://gigachat.devices.sberbank.ru/api/v1", ] @@ -986,6 +987,7 @@ openai_compatible_providers: Final[list] = [ "meta", # Meta Model API (Muse Spark) - JSON-configured provider "cognition", "scx-ai", + "ainetcafe", # ainetcafe (Kimi K3) - JSON-configured provider ] openai_text_completion_compatible_providers: Final[list] = [ # providers that support `/v1/completions` "together_ai", diff --git a/litellm/llms/openai_like/providers.json b/litellm/llms/openai_like/providers.json index fe10293c420..4826efbe1dd 100644 --- a/litellm/llms/openai_like/providers.json +++ b/litellm/llms/openai_like/providers.json @@ -200,5 +200,11 @@ "temperature_max": 1.99 }, "supported_endpoints": ["/v1/chat/completions"] + }, + "ainetcafe": { + "base_url": "https://microquickjs.com/v1", + "api_key_env": "AINETCAFE_API_KEY", + "api_base_env": "AINETCAFE_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 e87a3fec99b..155a0ac552d 100644 --- a/litellm/model_prices_and_context_window_backup.json +++ b/litellm/model_prices_and_context_window_backup.json @@ -44143,6 +44143,23 @@ "supports_tool_choice": true, "supports_vision": true }, + "ainetcafe/Kimi-K3": { + "cache_read_input_token_cost": 3e-07, + "input_cost_per_token": 2.1e-06, + "litellm_provider": "ainetcafe", + "max_input_tokens": 262144, + "max_output_tokens": 131072, + "max_tokens": 131072, + "mode": "chat", + "output_cost_per_token": 1.05e-05, + "source": "https://ainetcafe.com/k3/#pricing", + "supports_function_calling": true, + "supports_prompt_caching": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_tool_choice": true, + "supports_vision": true + }, "snowflake/claude-3-5-sonnet": { "litellm_provider": "snowflake", "max_input_tokens": 200000, diff --git a/litellm/provider_endpoints_support_backup.json b/litellm/provider_endpoints_support_backup.json index dbeaccdda2d..cb0a69a4175 100644 --- a/litellm/provider_endpoints_support_backup.json +++ b/litellm/provider_endpoints_support_backup.json @@ -2082,6 +2082,23 @@ "a2a": false } }, + "ainetcafe": { + "display_name": "ainetcafe (`ainetcafe`)", + "url": "https://docs.litellm.ai/docs/providers/ainetcafe", + "endpoints": { + "chat_completions": true, + "messages": false, + "responses": false, + "embeddings": false, + "image_generations": false, + "audio_transcriptions": false, + "audio_speech": false, + "moderations": false, + "batches": false, + "rerank": false, + "a2a": false + } + }, "snowflake": { "display_name": "Snowflake (`snowflake`)", "url": "https://docs.litellm.ai/docs/providers/snowflake", diff --git a/litellm/proxy/public_endpoints/provider_create_fields.json b/litellm/proxy/public_endpoints/provider_create_fields.json index cd781abee26..4194d9bf1e3 100644 --- a/litellm/proxy/public_endpoints/provider_create_fields.json +++ b/litellm/proxy/public_endpoints/provider_create_fields.json @@ -2879,6 +2879,34 @@ ], "default_model_placeholder": "scx-ai/GLM-5.2" }, + { + "provider": "AINETCAFE", + "provider_display_name": "ainetcafe", + "litellm_provider": "ainetcafe", + "credential_fields": [ + { + "key": "api_base", + "label": "API Base", + "placeholder": "https://microquickjs.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": "ainetcafe/Kimi-K3" + }, { "provider": "Snowflake", "provider_display_name": "Snowflake", diff --git a/litellm/types/utils.py b/litellm/types/utils.py index aaa16fd2d44..9211b3740a5 100644 --- a/litellm/types/utils.py +++ b/litellm/types/utils.py @@ -4105,6 +4105,7 @@ class LlmProviders(str, Enum): PINSTRIPES = "pinstripes" COGNITION = "cognition" SCX_AI = "scx-ai" + AINETCAFE = "ainetcafe" DARKBLOOM = "darkbloom" META = "meta" LITELLM_AGENT = "litellm_agent" diff --git a/model_prices_and_context_window.json b/model_prices_and_context_window.json index e87a3fec99b..155a0ac552d 100644 --- a/model_prices_and_context_window.json +++ b/model_prices_and_context_window.json @@ -44143,6 +44143,23 @@ "supports_tool_choice": true, "supports_vision": true }, + "ainetcafe/Kimi-K3": { + "cache_read_input_token_cost": 3e-07, + "input_cost_per_token": 2.1e-06, + "litellm_provider": "ainetcafe", + "max_input_tokens": 262144, + "max_output_tokens": 131072, + "max_tokens": 131072, + "mode": "chat", + "output_cost_per_token": 1.05e-05, + "source": "https://ainetcafe.com/k3/#pricing", + "supports_function_calling": true, + "supports_prompt_caching": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_tool_choice": true, + "supports_vision": true + }, "snowflake/claude-3-5-sonnet": { "litellm_provider": "snowflake", "max_input_tokens": 200000, diff --git a/provider_endpoints_support.json b/provider_endpoints_support.json index c71f4a82a4a..7ad7eae92cd 100644 --- a/provider_endpoints_support.json +++ b/provider_endpoints_support.json @@ -2316,6 +2316,23 @@ "a2a": false } }, + "ainetcafe": { + "display_name": "ainetcafe (`ainetcafe`)", + "url": "https://docs.litellm.ai/docs/providers/ainetcafe", + "endpoints": { + "chat_completions": true, + "messages": false, + "responses": false, + "embeddings": false, + "image_generations": false, + "audio_transcriptions": false, + "audio_speech": false, + "moderations": false, + "batches": false, + "rerank": false, + "a2a": false + } + }, "snowflake": { "display_name": "Snowflake (`snowflake`)", "url": "https://docs.litellm.ai/docs/providers/snowflake", diff --git a/tests/test_litellm/llms/openai_like/test_ainetcafe_provider.py b/tests/test_litellm/llms/openai_like/test_ainetcafe_provider.py new file mode 100644 index 00000000000..14c5c903491 --- /dev/null +++ b/tests/test_litellm/llms/openai_like/test_ainetcafe_provider.py @@ -0,0 +1,171 @@ +""" +Tests for the ainetcafe (Kimi K3) provider configuration and integration. +""" + +import litellm + + +class TestAinetcafeProviderConfig: + def test_ainetcafe_in_provider_list(self): + from litellm import LlmProviders + + assert hasattr(LlmProviders, "AINETCAFE") + assert LlmProviders.AINETCAFE.value == "ainetcafe" + assert "ainetcafe" in litellm.provider_list + + def test_ainetcafe_json_config_exists(self): + from litellm.llms.openai_like.json_loader import JSONProviderRegistry + + assert JSONProviderRegistry.exists("ainetcafe") + + provider = JSONProviderRegistry.get("ainetcafe") + assert provider is not None + assert provider.base_url == "https://microquickjs.com/v1" + assert provider.api_key_env == "AINETCAFE_API_KEY" + assert provider.api_base_env == "AINETCAFE_API_BASE" + assert "/v1/chat/completions" in provider.supported_endpoints + + def test_ainetcafe_in_openai_compatible_providers(self): + from litellm.constants import openai_compatible_providers + + assert "ainetcafe" in openai_compatible_providers + + def test_ainetcafe_provider_resolution(self): + from litellm.litellm_core_utils.get_llm_provider_logic import get_llm_provider + + model, provider, api_key, api_base = get_llm_provider( + model="ainetcafe/Kimi-K3", + custom_llm_provider=None, + api_base=None, + api_key=None, + ) + + assert model == "Kimi-K3" + assert provider == "ainetcafe" + assert api_base == "https://microquickjs.com/v1" + + def test_ainetcafe_api_base_override(self): + from litellm.litellm_core_utils.get_llm_provider_logic import get_llm_provider + + model, provider, api_key, api_base = get_llm_provider( + model="ainetcafe/Kimi-K3", + custom_llm_provider=None, + api_base="https://dedicated.example.com/v1", + api_key="sk-test", + ) + + assert provider == "ainetcafe" + assert api_base == "https://dedicated.example.com/v1" + assert api_key == "sk-test" + + def test_ainetcafe_url_autodetection(self): + from litellm.litellm_core_utils.get_llm_provider_logic import get_llm_provider + + model, provider, api_key, api_base = get_llm_provider( + model="Kimi-K3", + custom_llm_provider=None, + api_base="https://microquickjs.com/v1", + api_key=None, + ) + assert provider == "ainetcafe" + assert api_base == "https://microquickjs.com/v1" + + def test_ainetcafe_passes_reasoning_effort_and_max_completion_tokens(self): + from litellm.llms.openai_like.dynamic_config import create_config_class + from litellm.llms.openai_like.json_loader import JSONProviderRegistry + + provider = JSONProviderRegistry.get("ainetcafe") + assert provider is not None + config = create_config_class(provider)() + + optional_params = config.map_openai_params( + non_default_params={"max_completion_tokens": 256, "reasoning_effort": "high"}, + optional_params={}, + model="Kimi-K3", + drop_params=False, + ) + # The endpoint accepts both fields natively; nothing is renamed. + assert optional_params["max_completion_tokens"] == 256 + assert optional_params["reasoning_effort"] == "high" + + def test_ainetcafe_router_config(self): + from litellm import Router + + router = Router( + model_list=[ + { + "model_name": "k3", + "litellm_params": { + "model": "ainetcafe/Kimi-K3", + "api_key": "test-key", + }, + } + ] + ) + + assert len(router.model_list) == 1 + assert router.model_list[0]["model_name"] == "k3" + + +class TestAinetcafeModelMetadata: + MODEL = "ainetcafe/Kimi-K3" + + @staticmethod + def _load(path_parts): + import json + from pathlib import Path + + json_path = Path(__file__).parents[4].joinpath(*path_parts) + with open(json_path) as f: + return json.load(f) + + def test_ainetcafe_model_registered_with_correct_metadata(self): + model_cost = self._load(("model_prices_and_context_window.json",)) + info = model_cost.get(self.MODEL) + assert info is not None, f"{self.MODEL} missing from model_prices_and_context_window.json" + assert info["litellm_provider"] == "ainetcafe" + assert info["mode"] == "chat" + assert info["input_cost_per_token"] == 2.1e-06 + assert info["output_cost_per_token"] == 1.05e-05 + assert info["cache_read_input_token_cost"] == 3e-07 + assert info["supports_function_calling"] is True + assert info["supports_tool_choice"] is True + assert info["supports_reasoning"] is True + assert info["supports_response_schema"] is True + assert info["supports_vision"] is True + assert info["supports_prompt_caching"] is True + assert info["max_tokens"] == info["max_output_tokens"] + assert info["max_input_tokens"] == 262144 + + def test_ainetcafe_model_synced_to_backup(self): + model_cost = self._load(("model_prices_and_context_window.json",)) + backup = self._load(("litellm", "model_prices_and_context_window_backup.json")) + assert self.MODEL in backup, f"{self.MODEL} missing from backup json" + assert backup[self.MODEL] == model_cost[self.MODEL] + + +class TestAinetcafeDashboardRegistration: + @staticmethod + def _provider_create_fields(): + import json + from pathlib import Path + + import litellm + + path = Path(litellm.__file__).parent / "proxy" / "public_endpoints" / "provider_create_fields.json" + with open(path) as f: + return json.load(f) + + def test_ainetcafe_is_selectable_in_the_add_model_form(self): + entries = [e for e in self._provider_create_fields() if e["litellm_provider"] == "ainetcafe"] + assert len(entries) == 1, "ainetcafe must appear exactly once in provider_create_fields.json" + + entry = entries[0] + assert entry["provider"] == "AINETCAFE" + assert entry["provider_display_name"] == "ainetcafe" + assert entry["default_model_placeholder"] == "ainetcafe/Kimi-K3" + + fields = {f["key"]: f for f in entry["credential_fields"]} + assert fields["api_key"]["required"] is True + assert fields["api_key"]["field_type"] == "password" + assert fields["api_base"]["required"] is False diff --git a/ui/litellm-dashboard/public/assets/logos/ainetcafe.svg b/ui/litellm-dashboard/public/assets/logos/ainetcafe.svg new file mode 100644 index 00000000000..b7ea7eccecd --- /dev/null +++ b/ui/litellm-dashboard/public/assets/logos/ainetcafe.svg @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/ui/litellm-dashboard/src/components/provider_info_helpers.test.tsx b/ui/litellm-dashboard/src/components/provider_info_helpers.test.tsx index 4c68e302267..7ccf7deaa3e 100644 --- a/ui/litellm-dashboard/src/components/provider_info_helpers.test.tsx +++ b/ui/litellm-dashboard/src/components/provider_info_helpers.test.tsx @@ -73,6 +73,17 @@ describe("provider_info_helpers", () => { expect(fromEnumKey.logo).toBe(providerLogoMap[Providers.SCX_AI]); }); + it("should map ainetcafe slug and AINETCAFE enum key to the ainetcafe display name and logo", () => { + const fromSlug = getProviderLogoAndName("ainetcafe"); + expect(fromSlug.displayName).toBe(Providers.AINETCAFE); + expect(fromSlug.logo).toBe(providerLogoMap[Providers.AINETCAFE]); + expect(fromSlug.logo).toBeTruthy(); + + const fromEnumKey = getProviderLogoAndName("AINETCAFE"); + expect(fromEnumKey.displayName).toBe(Providers.AINETCAFE); + expect(fromEnumKey.logo).toBe(providerLogoMap[Providers.AINETCAFE]); + }); + it("should map bedrock_mantle slug to Bedrock Mantle display name and logo", () => { const result = getProviderLogoAndName("bedrock_mantle"); expect(result.displayName).toBe(Providers.BedrockMantle); @@ -205,6 +216,10 @@ describe("provider_info_helpers", () => { expect(getPlaceholder(Providers.SCX_AI)).toBe("scx-ai/GLM-5.2"); }); + it("should return an ainetcafe model placeholder for AINETCAFE provider", () => { + expect(getPlaceholder(Providers.AINETCAFE)).toBe("ainetcafe/Kimi-K3"); + }); + it("should return claude-3-opus placeholder for Anthropic provider", () => { expect(getPlaceholder(Providers.Anthropic)).toBe("claude-3-opus"); }); diff --git a/ui/litellm-dashboard/src/components/provider_info_helpers.tsx b/ui/litellm-dashboard/src/components/provider_info_helpers.tsx index de83cd00790..37cb0b7b2f7 100644 --- a/ui/litellm-dashboard/src/components/provider_info_helpers.tsx +++ b/ui/litellm-dashboard/src/components/provider_info_helpers.tsx @@ -52,6 +52,7 @@ import runwayLogo from "../../public/assets/logos/runway.png"; import sambanovaLogo from "../../public/assets/logos/sambanova.svg"; import sapLogo from "../../public/assets/logos/sap.png"; import scxAiLogo from "../../public/assets/logos/scx_ai.svg"; +import ainetcafeLogo from "../../public/assets/logos/ainetcafe.svg"; import snowflakeLogo from "../../public/assets/logos/snowflake.svg"; import sonioxLogo from "../../public/assets/logos/soniox.svg"; import togetheraiLogo from "../../public/assets/logos/togetherai.svg"; @@ -160,6 +161,7 @@ export enum Providers { Sambanova = "Sambanova", SAP = "SAP Generative AI Hub", SCX_AI = "SCX.ai", + AINETCAFE = "ainetcafe", Snowflake = "Snowflake", Soniox = "Soniox", TEXT_COMPLETION_CODESTRAL = "Text-Completion-Codestral", @@ -276,6 +278,7 @@ export const provider_map: Record = { Sambanova: "sambanova", SAP: "sap", SCX_AI: "scx-ai", + AINETCAFE: "ainetcafe", Snowflake: "snowflake", Soniox: "soniox", TEXT_COMPLETION_CODESTRAL: "text-completion-codestral", @@ -373,6 +376,7 @@ export const providerLogoMap: Partial> = { [Providers.Sambanova]: sambanovaLogo.src, [Providers.SAP]: sapLogo.src, [Providers.SCX_AI]: scxAiLogo.src, + [Providers.AINETCAFE]: ainetcafeLogo.src, [Providers.Snowflake]: snowflakeLogo.src, [Providers.Soniox]: sonioxLogo.src, [Providers.TEXT_COMPLETION_CODESTRAL]: mistralLogo.src, @@ -440,6 +444,7 @@ const providerPlaceholderMap: Partial> = { [Providers.RunwayML]: "runwayml/gen4_turbo", [Providers.SageMaker]: "sagemaker/jumpstart-dft-meta-textgeneration-llama-2-7b", [Providers.SCX_AI]: "scx-ai/GLM-5.2", + [Providers.AINETCAFE]: "ainetcafe/Kimi-K3", [Providers.Snowflake]: "snowflake/mistral-7b", [Providers.Vertex_AI]: "gemini-pro", [Providers.VolcEngine]: "volcengine/", From 5ca8dfcf5bae29027735920877062b1c0524a898 Mon Sep 17 00:00:00 2001 From: Mario Date: Thu, 17 Sep 2026 14:28:56 +0800 Subject: [PATCH 2/2] test(ainetcafe): exercise request routing, env config and cost tracking instead of registry structure Replace the structure-only checks with mocked-transport completions that assert the outgoing URL, bearer key, reasoning_effort and max_completion_tokens passthrough, and a cost assertion derived from the cost map instead of literal prices. Cite the source and date for the capability flags. Drop the sizing comment from the logo SVG. --- .../openai_like/test_ainetcafe_provider.py | 307 +++++++++--------- .../public/assets/logos/ainetcafe.svg | 1 - 2 files changed, 151 insertions(+), 157 deletions(-) diff --git a/tests/test_litellm/llms/openai_like/test_ainetcafe_provider.py b/tests/test_litellm/llms/openai_like/test_ainetcafe_provider.py index 14c5c903491..fd4874efaa6 100644 --- a/tests/test_litellm/llms/openai_like/test_ainetcafe_provider.py +++ b/tests/test_litellm/llms/openai_like/test_ainetcafe_provider.py @@ -1,171 +1,166 @@ """ -Tests for the ainetcafe (Kimi K3) provider configuration and integration. +Tests for the ainetcafe (Kimi K3) provider: request routing, parameter passthrough, +cost tracking and the consistency of its metadata across the config surfaces. """ +import json +from pathlib import Path + +import pytest +import respx +from httpx import Response + import litellm +BASE_URL = "https://microquickjs.com/v1" +MODEL = "ainetcafe/Kimi-K3" -class TestAinetcafeProviderConfig: - def test_ainetcafe_in_provider_list(self): - from litellm import LlmProviders - assert hasattr(LlmProviders, "AINETCAFE") - assert LlmProviders.AINETCAFE.value == "ainetcafe" - assert "ainetcafe" in litellm.provider_list +def _chat_response(prompt_tokens=100, cached_tokens=60, completion_tokens=20): + return { + "id": "chatcmpl-ainetcafe-test", + "object": "chat.completion", + "created": 1758000000, + "model": "Kimi-K3", + "choices": [ + { + "index": 0, + "message": { + "role": "assistant", + "content": "LiteLLM OK", + "reasoning_content": "The user wants an exact reply.", + }, + "finish_reason": "stop", + } + ], + "usage": { + "prompt_tokens": prompt_tokens, + "completion_tokens": completion_tokens, + "total_tokens": prompt_tokens + completion_tokens, + "prompt_tokens_details": {"cached_tokens": cached_tokens}, + }, + } - def test_ainetcafe_json_config_exists(self): + +@pytest.fixture(autouse=True) +def _local_cost_map(monkeypatch): + monkeypatch.setenv("LITELLM_LOCAL_MODEL_COST_MAP", "True") + litellm.model_cost = litellm.get_model_cost_map(url="") + + +class TestAinetcafeRequests: + @respx.mock + def test_completion_hits_default_base_with_bearer_key_and_passes_reasoning_params(self): + route = respx.post(f"{BASE_URL}/chat/completions").mock(return_value=Response(200, json=_chat_response())) + + response = litellm.completion( + model=MODEL, + messages=[{"role": "user", "content": "Reply with exactly: LiteLLM OK"}], + api_key="sk-test-ainetcafe", + reasoning_effort="high", + max_completion_tokens=256, + ) + + assert route.called + request = route.calls.last.request + assert request.headers["authorization"] == "Bearer sk-test-ainetcafe" + body = json.loads(request.content) + assert body["model"] == "Kimi-K3" + assert body["reasoning_effort"] == "high" + assert body["max_completion_tokens"] == 256 + assert response.choices[0].message.content == "LiteLLM OK" + assert response.choices[0].message.reasoning_content == "The user wants an exact reply." + + @respx.mock + def test_api_key_env_and_api_base_env_are_honoured(self, monkeypatch): + monkeypatch.setenv("AINETCAFE_API_KEY", "sk-from-env") + monkeypatch.setenv("AINETCAFE_API_BASE", "https://dedicated.example.com/v1") + route = respx.post("https://dedicated.example.com/v1/chat/completions").mock( + return_value=Response(200, json=_chat_response()) + ) + + litellm.completion(model=MODEL, messages=[{"role": "user", "content": "hi"}]) + + assert route.called + assert route.calls.last.request.headers["authorization"] == "Bearer sk-from-env" + + def test_base_url_autodetects_provider(self): + from litellm.litellm_core_utils.get_llm_provider_logic import get_llm_provider + + model, provider, _, api_base = get_llm_provider( + model="Kimi-K3", custom_llm_provider=None, api_base=BASE_URL, api_key=None + ) + + assert (model, provider, api_base) == ("Kimi-K3", "ainetcafe", BASE_URL) + + @respx.mock + def test_completion_cost_uses_cost_map_and_cached_input_rate(self): + respx.post(f"{BASE_URL}/chat/completions").mock( + return_value=Response(200, json=_chat_response(prompt_tokens=100, cached_tokens=60, completion_tokens=20)) + ) + info = litellm.get_model_info(MODEL) + + response = litellm.completion(model=MODEL, messages=[{"role": "user", "content": "hi"}], api_key="sk-test") + cost = litellm.completion_cost(completion_response=response) + + expected = ( + 40 * info["input_cost_per_token"] + + 60 * info["cache_read_input_token_cost"] + + 20 * info["output_cost_per_token"] + ) + assert cost == pytest.approx(expected) + assert 0 < info["cache_read_input_token_cost"] < info["input_cost_per_token"] < info["output_cost_per_token"] + + +class TestAinetcafeMetadataConsistency: + @staticmethod + def _load(*parts): + with open(Path(__file__).parents[4].joinpath(*parts)) as f: + return json.load(f) + + def test_model_entry_matches_backup_and_declares_capabilities_the_provider_serves(self): + root = self._load("model_prices_and_context_window.json")[MODEL] + backup = self._load("litellm", "model_prices_and_context_window_backup.json")[MODEL] + + assert root == backup + assert root["litellm_provider"] == "ainetcafe" + assert root["max_tokens"] == root["max_output_tokens"] <= root["max_input_tokens"] + # Source: https://ainetcafe.com/k3/#pricing and https://ainetcafe.com/k3/verifier.html, read 2026-09-17. + # Kimi K3 on ainetcafe reasons, calls tools, returns JSON schema output and takes image input. + assert all( + root[flag] + for flag in ( + "supports_reasoning", + "supports_function_calling", + "supports_tool_choice", + "supports_response_schema", + "supports_vision", + "supports_prompt_caching", + ) + ) + + def test_provider_surfaces_agree_on_slug_base_url_and_env_keys(self): from litellm.llms.openai_like.json_loader import JSONProviderRegistry - assert JSONProviderRegistry.exists("ainetcafe") - provider = JSONProviderRegistry.get("ainetcafe") assert provider is not None - assert provider.base_url == "https://microquickjs.com/v1" - assert provider.api_key_env == "AINETCAFE_API_KEY" - assert provider.api_base_env == "AINETCAFE_API_BASE" - assert "/v1/chat/completions" in provider.supported_endpoints - def test_ainetcafe_in_openai_compatible_providers(self): - from litellm.constants import openai_compatible_providers + create_fields = [ + e + for e in self._load("litellm", "proxy", "public_endpoints", "provider_create_fields.json") + if e["litellm_provider"] == "ainetcafe" + ] + assert len(create_fields) == 1 + api_base_field = next(f for f in create_fields[0]["credential_fields"] if f["key"] == "api_base") + assert api_base_field["placeholder"] == provider.base_url + assert create_fields[0]["default_model_placeholder"] == MODEL + + support = self._load("provider_endpoints_support.json")["providers"]["ainetcafe"] + support_backup = self._load("litellm", "provider_endpoints_support_backup.json")["providers"]["ainetcafe"] + assert support == support_backup + assert support["endpoints"]["chat_completions"] is ("/v1/chat/completions" in provider.supported_endpoints) + + from litellm.constants import openai_compatible_endpoints, openai_compatible_providers assert "ainetcafe" in openai_compatible_providers - - def test_ainetcafe_provider_resolution(self): - from litellm.litellm_core_utils.get_llm_provider_logic import get_llm_provider - - model, provider, api_key, api_base = get_llm_provider( - model="ainetcafe/Kimi-K3", - custom_llm_provider=None, - api_base=None, - api_key=None, - ) - - assert model == "Kimi-K3" - assert provider == "ainetcafe" - assert api_base == "https://microquickjs.com/v1" - - def test_ainetcafe_api_base_override(self): - from litellm.litellm_core_utils.get_llm_provider_logic import get_llm_provider - - model, provider, api_key, api_base = get_llm_provider( - model="ainetcafe/Kimi-K3", - custom_llm_provider=None, - api_base="https://dedicated.example.com/v1", - api_key="sk-test", - ) - - assert provider == "ainetcafe" - assert api_base == "https://dedicated.example.com/v1" - assert api_key == "sk-test" - - def test_ainetcafe_url_autodetection(self): - from litellm.litellm_core_utils.get_llm_provider_logic import get_llm_provider - - model, provider, api_key, api_base = get_llm_provider( - model="Kimi-K3", - custom_llm_provider=None, - api_base="https://microquickjs.com/v1", - api_key=None, - ) - assert provider == "ainetcafe" - assert api_base == "https://microquickjs.com/v1" - - def test_ainetcafe_passes_reasoning_effort_and_max_completion_tokens(self): - from litellm.llms.openai_like.dynamic_config import create_config_class - from litellm.llms.openai_like.json_loader import JSONProviderRegistry - - provider = JSONProviderRegistry.get("ainetcafe") - assert provider is not None - config = create_config_class(provider)() - - optional_params = config.map_openai_params( - non_default_params={"max_completion_tokens": 256, "reasoning_effort": "high"}, - optional_params={}, - model="Kimi-K3", - drop_params=False, - ) - # The endpoint accepts both fields natively; nothing is renamed. - assert optional_params["max_completion_tokens"] == 256 - assert optional_params["reasoning_effort"] == "high" - - def test_ainetcafe_router_config(self): - from litellm import Router - - router = Router( - model_list=[ - { - "model_name": "k3", - "litellm_params": { - "model": "ainetcafe/Kimi-K3", - "api_key": "test-key", - }, - } - ] - ) - - assert len(router.model_list) == 1 - assert router.model_list[0]["model_name"] == "k3" - - -class TestAinetcafeModelMetadata: - MODEL = "ainetcafe/Kimi-K3" - - @staticmethod - def _load(path_parts): - import json - from pathlib import Path - - json_path = Path(__file__).parents[4].joinpath(*path_parts) - with open(json_path) as f: - return json.load(f) - - def test_ainetcafe_model_registered_with_correct_metadata(self): - model_cost = self._load(("model_prices_and_context_window.json",)) - info = model_cost.get(self.MODEL) - assert info is not None, f"{self.MODEL} missing from model_prices_and_context_window.json" - assert info["litellm_provider"] == "ainetcafe" - assert info["mode"] == "chat" - assert info["input_cost_per_token"] == 2.1e-06 - assert info["output_cost_per_token"] == 1.05e-05 - assert info["cache_read_input_token_cost"] == 3e-07 - assert info["supports_function_calling"] is True - assert info["supports_tool_choice"] is True - assert info["supports_reasoning"] is True - assert info["supports_response_schema"] is True - assert info["supports_vision"] is True - assert info["supports_prompt_caching"] is True - assert info["max_tokens"] == info["max_output_tokens"] - assert info["max_input_tokens"] == 262144 - - def test_ainetcafe_model_synced_to_backup(self): - model_cost = self._load(("model_prices_and_context_window.json",)) - backup = self._load(("litellm", "model_prices_and_context_window_backup.json")) - assert self.MODEL in backup, f"{self.MODEL} missing from backup json" - assert backup[self.MODEL] == model_cost[self.MODEL] - - -class TestAinetcafeDashboardRegistration: - @staticmethod - def _provider_create_fields(): - import json - from pathlib import Path - - import litellm - - path = Path(litellm.__file__).parent / "proxy" / "public_endpoints" / "provider_create_fields.json" - with open(path) as f: - return json.load(f) - - def test_ainetcafe_is_selectable_in_the_add_model_form(self): - entries = [e for e in self._provider_create_fields() if e["litellm_provider"] == "ainetcafe"] - assert len(entries) == 1, "ainetcafe must appear exactly once in provider_create_fields.json" - - entry = entries[0] - assert entry["provider"] == "AINETCAFE" - assert entry["provider_display_name"] == "ainetcafe" - assert entry["default_model_placeholder"] == "ainetcafe/Kimi-K3" - - fields = {f["key"]: f for f in entry["credential_fields"]} - assert fields["api_key"]["required"] is True - assert fields["api_key"]["field_type"] == "password" - assert fields["api_base"]["required"] is False + assert provider.base_url in openai_compatible_endpoints diff --git a/ui/litellm-dashboard/public/assets/logos/ainetcafe.svg b/ui/litellm-dashboard/public/assets/logos/ainetcafe.svg index b7ea7eccecd..497be12efaa 100644 --- a/ui/litellm-dashboard/public/assets/logos/ainetcafe.svg +++ b/ui/litellm-dashboard/public/assets/logos/ainetcafe.svg @@ -6,6 +6,5 @@ -