From d57c45fe2b9e711428fe914490bccf9e4427e642 Mon Sep 17 00:00:00 2001 From: BeEdward <62042559+BeEdward@users.noreply.github.com> Date: Fri, 2 Oct 2026 09:07:26 +0000 Subject: [PATCH 1/4] feat(providers): add Tokenify as an OpenAI-compatible provider Tokenify serves DeepSeek and GLM models on /v1/chat/completions, /v1/responses and /v1/messages at https://api.tokenify.dev/v1. Registered through the JSON provider config, following the Cortecs provider. Co-Authored-By: Claude Opus 5.5 (1M context) --- litellm/constants.py | 2 + litellm/llms/openai_like/providers.json | 6 + .../provider_endpoints_support_backup.json | 18 ++ .../provider_create_fields.json | 28 +++ litellm/types/utils.py | 1 + provider_endpoints_support.json | 18 ++ .../openai_like/test_tokenify_provider.py | 187 ++++++++++++++++++ 7 files changed, 260 insertions(+) create mode 100644 tests/unit/llms/openai_like/test_tokenify_provider.py diff --git a/litellm/constants.py b/litellm/constants.py index af4d1268c036..c0e20172019e 100644 --- a/litellm/constants.py +++ b/litellm/constants.py @@ -960,6 +960,7 @@ "https://pinstripes.io/v1", "https://api.meta.ai/v1", "https://api.sailresearch.com/v1", + "https://api.tokenify.dev/v1", "https://api.cognition.ai/v1", "https://api.cortecs.ai/v1", "https://api.scx.ai/v1", @@ -1040,6 +1041,7 @@ "scx-ai", "prism", "sail", + "tokenify", ] 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 61ff4be3a462..a5136770457a 100644 --- a/litellm/llms/openai_like/providers.json +++ b/litellm/llms/openai_like/providers.json @@ -218,5 +218,11 @@ "api_key_env": "SAIL_API_KEY", "api_base_env": "SAIL_API_BASE", "supported_endpoints": ["/v1/chat/completions", "/v1/responses", "/v1/messages"] + }, + "tokenify": { + "base_url": "https://api.tokenify.dev/v1", + "api_key_env": "TOKENIFY_API_KEY", + "api_base_env": "TOKENIFY_API_BASE", + "supported_endpoints": ["/v1/chat/completions", "/v1/responses", "/v1/messages"] } } diff --git a/litellm/provider_endpoints_support_backup.json b/litellm/provider_endpoints_support_backup.json index c9635587eeba..6bdeb9847b33 100644 --- a/litellm/provider_endpoints_support_backup.json +++ b/litellm/provider_endpoints_support_backup.json @@ -636,6 +636,24 @@ "interactions": false } }, + "tokenify": { + "display_name": "Tokenify (`tokenify`)", + "url": "https://docs.litellm.ai/docs/providers/tokenify", + "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 + } + }, "custom": { "display_name": "Custom (`custom`)", "url": "https://docs.litellm.ai/docs/providers/custom_llm_server", diff --git a/litellm/proxy/public_endpoints/provider_create_fields.json b/litellm/proxy/public_endpoints/provider_create_fields.json index 11d2ff61b952..80f53c045a5f 100644 --- a/litellm/proxy/public_endpoints/provider_create_fields.json +++ b/litellm/proxy/public_endpoints/provider_create_fields.json @@ -1043,6 +1043,34 @@ ], "default_model_placeholder": "cortecs/gpt-6-sol" }, + { + "provider": "TOKENIFY", + "provider_display_name": "Tokenify", + "litellm_provider": "tokenify", + "credential_fields": [ + { + "key": "api_base", + "label": "API Base", + "placeholder": "https://api.tokenify.dev/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": "tokenify/deepseek/deepseek-v4-pro" + }, { "provider": "CUSTOM", "provider_display_name": "Custom", diff --git a/litellm/types/utils.py b/litellm/types/utils.py index 8c10b9e3497f..8f964e434e27 100644 --- a/litellm/types/utils.py +++ b/litellm/types/utils.py @@ -4158,6 +4158,7 @@ class LlmProviders(str, Enum): DARKBLOOM = "darkbloom" META = "meta" SAIL = "sail" + TOKENIFY = "tokenify" LITELLM_AGENT = "litellm_agent" CURSOR = "cursor" BEDROCK_MANTLE = "bedrock_mantle" diff --git a/provider_endpoints_support.json b/provider_endpoints_support.json index 9cbd326277e6..96a12e45e8ba 100644 --- a/provider_endpoints_support.json +++ b/provider_endpoints_support.json @@ -689,6 +689,24 @@ "interactions": false } }, + "tokenify": { + "display_name": "Tokenify (`tokenify`)", + "url": "https://docs.litellm.ai/docs/providers/tokenify", + "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 + } + }, "crusoe": { "display_name": "Crusoe (`crusoe`)", "url": "https://docs.litellm.ai/docs/providers/crusoe", diff --git a/tests/unit/llms/openai_like/test_tokenify_provider.py b/tests/unit/llms/openai_like/test_tokenify_provider.py new file mode 100644 index 000000000000..080b45f56e0f --- /dev/null +++ b/tests/unit/llms/openai_like/test_tokenify_provider.py @@ -0,0 +1,187 @@ +import json +from pathlib import Path +from typing import Final + +import pytest +import respx + +import litellm +from litellm.caching.llm_caching_handler import LLMClientCache + + +def test_tokenify_provider_resolution(monkeypatch: pytest.MonkeyPatch): + from litellm.litellm_core_utils.get_llm_provider_logic import get_llm_provider + + monkeypatch.setenv("TOKENIFY_API_KEY", "tokenify-test-key") + + model, provider, api_key, api_base = get_llm_provider( + model="tokenify/deepseek/deepseek-v4-pro", + custom_llm_provider=None, + api_base=None, + api_key=None, + ) + + assert model == "deepseek/deepseek-v4-pro" + assert provider == "tokenify" + assert api_key == "tokenify-test-key" + assert api_base == "https://api.tokenify.dev/v1" + + +def test_tokenify_provider_keeps_explicit_credentials(monkeypatch: pytest.MonkeyPatch): + from litellm.litellm_core_utils.get_llm_provider_logic import get_llm_provider + + monkeypatch.setenv("TOKENIFY_API_KEY", "tokenify-env-key") + + _, provider, api_key, api_base = get_llm_provider( + model="tokenify/deepseek/deepseek-v4-pro", + custom_llm_provider=None, + api_base="https://tokenify.internal.example/v1", + api_key="tokenify-explicit-key", + ) + + assert provider == "tokenify" + assert api_key == "tokenify-explicit-key" + assert api_base == "https://tokenify.internal.example/v1" + + +def test_tokenify_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()) + tokenify = next(provider for provider in providers if provider["litellm_provider"] == "tokenify") + + assert tokenify["provider"] == "TOKENIFY" + assert tokenify["provider_display_name"] == "Tokenify" + assert tokenify["default_model_placeholder"] == "tokenify/deepseek/deepseek-v4-pro" + assert {field["key"]: field["required"] for field in tokenify["credential_fields"]} == { + "api_base": False, + "api_key": True, + } + + +def test_tokenify_supported_endpoints(): + matrix_path = Path(litellm.__file__).parent / "provider_endpoints_support_backup.json" + providers = json.loads(matrix_path.read_text())["providers"] + + assert providers["tokenify"]["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, + } + + +def test_tokenify_chat_completion_request(): + with respx.mock() as upstream: + route: Final = upstream.post("https://api.tokenify.dev/v1/chat/completions").respond( + 200, + json={ + "id": "chatcmpl_tokenify", + "object": "chat.completion", + "created": 1_789_550_000, + "model": "deepseek/deepseek-v4-pro", + "choices": [ + { + "index": 0, + "message": {"role": "assistant", "content": "Hello from Tokenify"}, + "finish_reason": "stop", + } + ], + "usage": {"prompt_tokens": 4, "completion_tokens": 3, "total_tokens": 7}, + }, + ) + response: Final = litellm.completion( + model="tokenify/deepseek/deepseek-v4-pro", + messages=[{"role": "user", "content": "Say hello"}], + api_key="tokenify-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.tokenify.dev/v1/chat/completions" + assert request.headers["authorization"] == "Bearer tokenify-test-key" + assert body["model"] == "deepseek/deepseek-v4-pro" + assert body["messages"] == [{"role": "user", "content": "Say hello"}] + assert response.choices[0].message.content == "Hello from Tokenify" + + +def test_tokenify_responses_request(): + with respx.mock() as upstream: + route: Final = upstream.post("https://api.tokenify.dev/v1/responses").respond( + 200, + json={ + "id": "resp_tokenify", + "object": "response", + "created_at": 1_789_550_000, + "model": "deepseek/deepseek-v4-pro", + "status": "completed", + "output": [ + { + "id": "msg_tokenify", + "type": "message", + "role": "assistant", + "status": "completed", + "content": [{"type": "output_text", "text": "Hello from Tokenify", "annotations": []}], + } + ], + "usage": {"input_tokens": 4, "output_tokens": 3, "total_tokens": 7}, + }, + ) + response: Final = litellm.responses( + model="tokenify/deepseek/deepseek-v4-pro", + input="Say hello", + api_key="tokenify-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.tokenify.dev/v1/responses" + assert request.headers["authorization"] == "Bearer tokenify-test-key" + assert body["model"] == "deepseek/deepseek-v4-pro" + assert body["input"] == "Say hello" + assert response.output[0].content[0].text == "Hello from Tokenify" + + +@pytest.mark.asyncio +async def test_tokenify_anthropic_messages_request(monkeypatch: pytest.MonkeyPatch): + monkeypatch.setattr(litellm, "disable_aiohttp_transport", True) + monkeypatch.setattr(litellm, "in_memory_llm_clients_cache", LLMClientCache()) + with respx.mock() as upstream: + route: Final = upstream.post("https://api.tokenify.dev/v1/messages").respond( + 200, + json={ + "id": "msg_tokenify", + "type": "message", + "role": "assistant", + "model": "deepseek/deepseek-v4-pro", + "content": [{"type": "text", "text": "Hello from Tokenify"}], + "stop_reason": "end_turn", + "stop_sequence": None, + "usage": {"input_tokens": 4, "output_tokens": 3}, + }, + ) + response: Final = await litellm.anthropic.messages.acreate( + model="tokenify/deepseek/deepseek-v4-pro", + messages=[{"role": "user", "content": "Say hello"}], + max_tokens=32, + api_key="tokenify-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.tokenify.dev/v1/messages" + assert request.headers["authorization"] == "Bearer tokenify-test-key" + assert request.headers["anthropic-version"] == "2023-06-01" + assert body["model"] == "deepseek/deepseek-v4-pro" + assert body["messages"] == [{"role": "user", "content": "Say hello"}] + assert response["content"][0]["text"] == "Hello from Tokenify" From 9e20075f91003bec5f0c75e7ab93a784274dc8ea Mon Sep 17 00:00:00 2001 From: BeEdward <62042559+BeEdward@users.noreply.github.com> Date: Fri, 2 Oct 2026 09:39:21 +0000 Subject: [PATCH 2/4] feat(providers): price the Tokenify models Adds cost-map entries for the five models Tokenify serves (identical in the root and backup maps), with capabilities taken from its GET /v1/models, and tests that the costs match the published per-1M prices and that the Admin UI placeholder model is priced. Co-Authored-By: Claude Opus 5.5 (1M context) --- ...odel_prices_and_context_window_backup.json | 125 ++++++++++++++++++ model_prices_and_context_window.json | 125 ++++++++++++++++++ .../openai_like/test_tokenify_provider.py | 56 ++++++++ 3 files changed, 306 insertions(+) diff --git a/litellm/model_prices_and_context_window_backup.json b/litellm/model_prices_and_context_window_backup.json index 3b9956ad1a62..961a915db06a 100644 --- a/litellm/model_prices_and_context_window_backup.json +++ b/litellm/model_prices_and_context_window_backup.json @@ -79628,5 +79628,130 @@ "supports_response_schema": true, "supports_tool_choice": true, "supports_vision": true + }, + "tokenify/deepseek/deepseek-v4-flash": { + "cache_read_input_token_cost": 1.4e-08, + "input_cost_per_token": 2.2e-07, + "litellm_provider": "tokenify", + "max_input_tokens": 1048576, + "max_output_tokens": 393216, + "max_tokens": 393216, + "mode": "chat", + "output_cost_per_token": 6.6e-07, + "source": "https://www.tokenify.dev/pricing/", + "supported_endpoints": [ + "/v1/chat/completions", + "/v1/responses", + "/v1/messages" + ], + "supports_function_calling": true, + "supports_native_streaming": true, + "supports_parallel_function_calling": true, + "supports_prompt_caching": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_system_messages": true, + "supports_tool_choice": true, + "supports_vision": false + }, + "tokenify/deepseek/deepseek-v4-pro": { + "cache_read_input_token_cost": 4.4e-08, + "input_cost_per_token": 6.6e-07, + "litellm_provider": "tokenify", + "max_input_tokens": 1048576, + "max_output_tokens": 393216, + "max_tokens": 393216, + "mode": "chat", + "output_cost_per_token": 1.98e-06, + "source": "https://www.tokenify.dev/pricing/", + "supported_endpoints": [ + "/v1/chat/completions", + "/v1/responses", + "/v1/messages" + ], + "supports_function_calling": true, + "supports_native_streaming": true, + "supports_parallel_function_calling": true, + "supports_prompt_caching": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_system_messages": true, + "supports_tool_choice": true, + "supports_vision": false + }, + "tokenify/deepseek/deepseek-v4.1-flash": { + "cache_read_input_token_cost": 6e-09, + "input_cost_per_token": 1.5e-07, + "litellm_provider": "tokenify", + "max_input_tokens": 1048576, + "max_output_tokens": 393216, + "max_tokens": 393216, + "mode": "chat", + "output_cost_per_token": 6e-07, + "source": "https://www.tokenify.dev/pricing/", + "supported_endpoints": [ + "/v1/chat/completions", + "/v1/responses", + "/v1/messages" + ], + "supports_function_calling": true, + "supports_native_streaming": true, + "supports_parallel_function_calling": true, + "supports_prompt_caching": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_system_messages": true, + "supports_tool_choice": true, + "supports_vision": true + }, + "tokenify/z-ai/glm-5.2": { + "cache_read_input_token_cost": 2.6e-07, + "input_cost_per_token": 7e-07, + "litellm_provider": "tokenify", + "max_input_tokens": 1048576, + "max_output_tokens": 131072, + "max_tokens": 131072, + "mode": "chat", + "output_cost_per_token": 2.2e-06, + "source": "https://www.tokenify.dev/pricing/", + "supported_endpoints": [ + "/v1/chat/completions", + "/v1/responses", + "/v1/messages" + ], + "supports_function_calling": true, + "supports_native_streaming": true, + "supports_parallel_function_calling": true, + "supports_prompt_caching": true, + "supports_reasoning": true, + "supports_response_schema": false, + "supports_system_messages": true, + "supports_tool_choice": true, + "supports_vision": false + }, + "tokenify/z-ai/glm-5.3-flash": { + "cache_read_input_token_cost": 3e-08, + "input_cost_per_token": 1.5e-07, + "litellm_provider": "tokenify", + "max_input_tokens": 1048576, + "max_output_tokens": 131072, + "max_tokens": 131072, + "mode": "chat", + "output_cost_per_token": 5e-07, + "source": "https://www.tokenify.dev/pricing/", + "supported_endpoints": [ + "/v1/chat/completions", + "/v1/responses", + "/v1/messages" + ], + "supports_function_calling": true, + "supports_native_streaming": true, + "supports_parallel_function_calling": true, + "supports_prompt_caching": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_system_messages": true, + "supports_tool_choice": true, + "supports_vision": true } } diff --git a/model_prices_and_context_window.json b/model_prices_and_context_window.json index 3b9956ad1a62..961a915db06a 100644 --- a/model_prices_and_context_window.json +++ b/model_prices_and_context_window.json @@ -79628,5 +79628,130 @@ "supports_response_schema": true, "supports_tool_choice": true, "supports_vision": true + }, + "tokenify/deepseek/deepseek-v4-flash": { + "cache_read_input_token_cost": 1.4e-08, + "input_cost_per_token": 2.2e-07, + "litellm_provider": "tokenify", + "max_input_tokens": 1048576, + "max_output_tokens": 393216, + "max_tokens": 393216, + "mode": "chat", + "output_cost_per_token": 6.6e-07, + "source": "https://www.tokenify.dev/pricing/", + "supported_endpoints": [ + "/v1/chat/completions", + "/v1/responses", + "/v1/messages" + ], + "supports_function_calling": true, + "supports_native_streaming": true, + "supports_parallel_function_calling": true, + "supports_prompt_caching": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_system_messages": true, + "supports_tool_choice": true, + "supports_vision": false + }, + "tokenify/deepseek/deepseek-v4-pro": { + "cache_read_input_token_cost": 4.4e-08, + "input_cost_per_token": 6.6e-07, + "litellm_provider": "tokenify", + "max_input_tokens": 1048576, + "max_output_tokens": 393216, + "max_tokens": 393216, + "mode": "chat", + "output_cost_per_token": 1.98e-06, + "source": "https://www.tokenify.dev/pricing/", + "supported_endpoints": [ + "/v1/chat/completions", + "/v1/responses", + "/v1/messages" + ], + "supports_function_calling": true, + "supports_native_streaming": true, + "supports_parallel_function_calling": true, + "supports_prompt_caching": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_system_messages": true, + "supports_tool_choice": true, + "supports_vision": false + }, + "tokenify/deepseek/deepseek-v4.1-flash": { + "cache_read_input_token_cost": 6e-09, + "input_cost_per_token": 1.5e-07, + "litellm_provider": "tokenify", + "max_input_tokens": 1048576, + "max_output_tokens": 393216, + "max_tokens": 393216, + "mode": "chat", + "output_cost_per_token": 6e-07, + "source": "https://www.tokenify.dev/pricing/", + "supported_endpoints": [ + "/v1/chat/completions", + "/v1/responses", + "/v1/messages" + ], + "supports_function_calling": true, + "supports_native_streaming": true, + "supports_parallel_function_calling": true, + "supports_prompt_caching": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_system_messages": true, + "supports_tool_choice": true, + "supports_vision": true + }, + "tokenify/z-ai/glm-5.2": { + "cache_read_input_token_cost": 2.6e-07, + "input_cost_per_token": 7e-07, + "litellm_provider": "tokenify", + "max_input_tokens": 1048576, + "max_output_tokens": 131072, + "max_tokens": 131072, + "mode": "chat", + "output_cost_per_token": 2.2e-06, + "source": "https://www.tokenify.dev/pricing/", + "supported_endpoints": [ + "/v1/chat/completions", + "/v1/responses", + "/v1/messages" + ], + "supports_function_calling": true, + "supports_native_streaming": true, + "supports_parallel_function_calling": true, + "supports_prompt_caching": true, + "supports_reasoning": true, + "supports_response_schema": false, + "supports_system_messages": true, + "supports_tool_choice": true, + "supports_vision": false + }, + "tokenify/z-ai/glm-5.3-flash": { + "cache_read_input_token_cost": 3e-08, + "input_cost_per_token": 1.5e-07, + "litellm_provider": "tokenify", + "max_input_tokens": 1048576, + "max_output_tokens": 131072, + "max_tokens": 131072, + "mode": "chat", + "output_cost_per_token": 5e-07, + "source": "https://www.tokenify.dev/pricing/", + "supported_endpoints": [ + "/v1/chat/completions", + "/v1/responses", + "/v1/messages" + ], + "supports_function_calling": true, + "supports_native_streaming": true, + "supports_parallel_function_calling": true, + "supports_prompt_caching": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_system_messages": true, + "supports_tool_choice": true, + "supports_vision": true } } diff --git a/tests/unit/llms/openai_like/test_tokenify_provider.py b/tests/unit/llms/openai_like/test_tokenify_provider.py index 080b45f56e0f..698c9b44a3e5 100644 --- a/tests/unit/llms/openai_like/test_tokenify_provider.py +++ b/tests/unit/llms/openai_like/test_tokenify_provider.py @@ -44,6 +44,62 @@ def test_tokenify_provider_keeps_explicit_credentials(monkeypatch: pytest.Monkey assert api_base == "https://tokenify.internal.example/v1" +TOKENIFY_MODELS = tuple(sorted(name for name in litellm.model_cost if name.startswith("tokenify/"))) + +# USD per 1M tokens (input, output), as published on https://www.tokenify.dev/pricing/ +TOKENIFY_PUBLISHED_PRICES: Final = { + "tokenify/deepseek/deepseek-v4-flash": (0.22, 0.66), + "tokenify/deepseek/deepseek-v4-pro": (0.66, 1.98), + "tokenify/deepseek/deepseek-v4.1-flash": (0.15, 0.6), + "tokenify/z-ai/glm-5.2": (0.7, 2.2), + "tokenify/z-ai/glm-5.3-flash": (0.15, 0.5), +} + + +def test_tokenify_models_are_priced(): + assert TOKENIFY_MODELS == tuple(sorted(TOKENIFY_PUBLISHED_PRICES)) + + +@pytest.mark.parametrize("model", TOKENIFY_MODELS) +def test_tokenify_model_cost_and_capabilities(model: str): + from litellm.cost_calculator import cost_per_token + + prompt_cost, completion_cost = cost_per_token( + model=model, + prompt_tokens=1_000_000, + completion_tokens=1_000_000, + custom_llm_provider="tokenify", + ) + model_info = litellm.get_model_info(model) + + assert (prompt_cost, completion_cost) == pytest.approx(TOKENIFY_PUBLISHED_PRICES[model]) + assert 0 < model_info["cache_read_input_token_cost"] < model_info["input_cost_per_token"] + assert model_info["max_tokens"] == model_info["max_output_tokens"] <= model_info["max_input_tokens"] + assert model_info["litellm_provider"] == "tokenify" + assert model_info["mode"] == "chat" + assert model_info["supports_function_calling"] is True + assert model_info["supports_reasoning"] is True + assert litellm.supports_vision(model) is model_info["supports_vision"] + + +def test_tokenify_admin_placeholder_model_is_priced(): + fields_path = Path(litellm.__file__).parent / "proxy" / "public_endpoints" / "provider_create_fields.json" + providers = json.loads(fields_path.read_text()) + tokenify = next(provider for provider in providers if provider["litellm_provider"] == "tokenify") + + assert tokenify["default_model_placeholder"] in TOKENIFY_MODELS + + +def test_tokenify_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()) + tokenify_entries = {name: entry for name, entry in cost_map.items() if name.startswith("tokenify/")} + + assert tuple(sorted(tokenify_entries)) == TOKENIFY_MODELS + assert tokenify_entries == {name: backup[name] for name in tokenify_entries} + + def test_tokenify_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 97a34da116d1ff466a7cc990f3a08c6aba18970a Mon Sep 17 00:00:00 2001 From: BeEdward <62042559+BeEdward@users.noreply.github.com> Date: Fri, 2 Oct 2026 09:44:19 +0000 Subject: [PATCH 3/4] test(providers): assert Tokenify costs against the cost map, not vendor price literals Co-Authored-By: Claude Opus 5.5 (1M context) --- .../openai_like/test_tokenify_provider.py | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/tests/unit/llms/openai_like/test_tokenify_provider.py b/tests/unit/llms/openai_like/test_tokenify_provider.py index 698c9b44a3e5..3bdfc09b9db8 100644 --- a/tests/unit/llms/openai_like/test_tokenify_provider.py +++ b/tests/unit/llms/openai_like/test_tokenify_provider.py @@ -46,18 +46,12 @@ def test_tokenify_provider_keeps_explicit_credentials(monkeypatch: pytest.Monkey TOKENIFY_MODELS = tuple(sorted(name for name in litellm.model_cost if name.startswith("tokenify/"))) -# USD per 1M tokens (input, output), as published on https://www.tokenify.dev/pricing/ -TOKENIFY_PUBLISHED_PRICES: Final = { - "tokenify/deepseek/deepseek-v4-flash": (0.22, 0.66), - "tokenify/deepseek/deepseek-v4-pro": (0.66, 1.98), - "tokenify/deepseek/deepseek-v4.1-flash": (0.15, 0.6), - "tokenify/z-ai/glm-5.2": (0.7, 2.2), - "tokenify/z-ai/glm-5.3-flash": (0.15, 0.5), -} - def test_tokenify_models_are_priced(): - assert TOKENIFY_MODELS == tuple(sorted(TOKENIFY_PUBLISHED_PRICES)) + assert TOKENIFY_MODELS + for model in TOKENIFY_MODELS: + entry = litellm.model_cost[model] + assert 0 < entry["input_cost_per_token"] <= entry["output_cost_per_token"] @pytest.mark.parametrize("model", TOKENIFY_MODELS) @@ -72,7 +66,12 @@ def test_tokenify_model_cost_and_capabilities(model: str): ) model_info = litellm.get_model_info(model) - assert (prompt_cost, completion_cost) == pytest.approx(TOKENIFY_PUBLISHED_PRICES[model]) + assert (prompt_cost, completion_cost) == pytest.approx( + ( + model_info["input_cost_per_token"] * 1_000_000, + model_info["output_cost_per_token"] * 1_000_000, + ) + ) assert 0 < model_info["cache_read_input_token_cost"] < model_info["input_cost_per_token"] assert model_info["max_tokens"] == model_info["max_output_tokens"] <= model_info["max_input_tokens"] assert model_info["litellm_provider"] == "tokenify" From f28f328715f40916151fd3c2c96e300f02499949 Mon Sep 17 00:00:00 2001 From: BeEdward <62042559+BeEdward@users.noreply.github.com> Date: Fri, 2 Oct 2026 13:08:50 +0000 Subject: [PATCH 4/4] test(providers): pin the expected Tokenify model list Co-Authored-By: Claude Opus 5.5 (1M context) --- tests/unit/llms/openai_like/test_tokenify_provider.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/unit/llms/openai_like/test_tokenify_provider.py b/tests/unit/llms/openai_like/test_tokenify_provider.py index 3bdfc09b9db8..080e417a4162 100644 --- a/tests/unit/llms/openai_like/test_tokenify_provider.py +++ b/tests/unit/llms/openai_like/test_tokenify_provider.py @@ -44,11 +44,17 @@ def test_tokenify_provider_keeps_explicit_credentials(monkeypatch: pytest.Monkey assert api_base == "https://tokenify.internal.example/v1" -TOKENIFY_MODELS = tuple(sorted(name for name in litellm.model_cost if name.startswith("tokenify/"))) +TOKENIFY_MODELS: Final = ( + "tokenify/deepseek/deepseek-v4-flash", + "tokenify/deepseek/deepseek-v4-pro", + "tokenify/deepseek/deepseek-v4.1-flash", + "tokenify/z-ai/glm-5.2", + "tokenify/z-ai/glm-5.3-flash", +) def test_tokenify_models_are_priced(): - assert TOKENIFY_MODELS + assert tuple(sorted(name for name in litellm.model_cost if name.startswith("tokenify/"))) == TOKENIFY_MODELS for model in TOKENIFY_MODELS: entry = litellm.model_cost[model] assert 0 < entry["input_cost_per_token"] <= entry["output_cost_per_token"]