From cc5c94fe10eff62d5554f2c6377568e47de866fd Mon Sep 17 00:00:00 2001 From: firekou Date: Thu, 3 Sep 2026 13:03:21 +0000 Subject: [PATCH 1/3] feat(providers): add AI Token King (aitokenking) OpenAI-compatible provider with pricing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit AI Token King (api.aitokenking.com.tw) is an OpenAI-compatible LLM gateway that resells 48 chat models from Anthropic, OpenAI, Google, Qwen, DeepSeek, Zhipu, Moonshot, MiniMax and ByteDance under one API key. Users could already point LiteLLM at it via `openai/` + `api_base`, but with two problems this PR fixes: 1. Cost tracking silently reported 0.0. Router registers every deployment with `register_model`, so an unmapped gateway model gets a zero-cost entry and `response_cost` reads as "free" instead of "unknown". 2. The only workaround — registering the gateway's prices under `openai/` — shadows the vendor entries already in the map (13 of the 48 ids collide, e.g. `gpt-5.5`, `claude-sonnet-5`), changing the cost reported for real OpenAI/Anthropic calls in the same process. Adding `aitokenking` as a JSON-configured provider gives the gateway its own namespace, so `aitokenking/qwen3.7-max` resolves the base URL, strips the prefix before sending, and prices from `aitokenking/*` without touching any vendor entry. Changes: - providers.json: `aitokenking` (chat completions only; base URL overridable via AITOKENKING_API_BASE) - LlmProviders enum, openai_compatible_providers, openai_compatible_endpoints - provider_endpoints_support.json entry - model_prices_and_context_window.json (+ backup): 48 chat models keyed `aitokenking/` — input/output cost and max_input_tokens only. Fields the gateway does not publish (max_output_tokens, cache tiers, capability flags) are deliberately omitted rather than guessed. The gateway's 61 image/video models are excluded because it publishes no per-token price for them; an entry with cost 0 would read as free. - tests: provider resolution, URL autodetection, Router config, price-map shape, no vendor-entry shadowing, completion_cost resolves to a non-zero value for a prefixed model. Prices measured 2026-08-23 from the gateway's read-only /models endpoint; the unit (USD per 1M tokens) was cross-checked against two vendors' public list prices. Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_01DBBj5ym47x1LmSxurSxbKH --- litellm/constants.py | 2 + litellm/llms/openai_like/providers.json | 11 + ...odel_prices_and_context_window_backup.json | 384 ++++++++++++++++++ litellm/types/utils.py | 1 + model_prices_and_context_window.json | 384 ++++++++++++++++++ provider_endpoints_support.json | 17 + .../openai_like/test_aitokenking_provider.py | 168 ++++++++ 7 files changed, 967 insertions(+) create mode 100644 tests/test_litellm/llms/openai_like/test_aitokenking_provider.py diff --git a/litellm/constants.py b/litellm/constants.py index ef9329b9dfce..17b15d637b0f 100644 --- a/litellm/constants.py +++ b/litellm/constants.py @@ -848,6 +848,7 @@ "https://serverless.tensormesh.ai/v1", "https://api.stima.tech/v1", "https://nano-gpt.com/api/v1", + "https://api.aitokenking.com.tw/api/v1", "https://api.poe.com/v1", "https://llm.chutes.ai/v1/", "https://api.v0.dev/v1", @@ -932,6 +933,7 @@ "docker_model_runner", "ragflow", "pinstripes", # Pinstripes - JSON-configured provider + "aitokenking", # AI Token King - JSON-configured provider "darkbloom", "meta", # Meta Model API (Muse Spark) - JSON-configured provider "cognition", diff --git a/litellm/llms/openai_like/providers.json b/litellm/llms/openai_like/providers.json index a458a209ea91..b164a0711d2f 100644 --- a/litellm/llms/openai_like/providers.json +++ b/litellm/llms/openai_like/providers.json @@ -200,5 +200,16 @@ "temperature_max": 1.99 }, "supported_endpoints": ["/v1/chat/completions"] + }, + "aitokenking": { + "base_url": "https://api.aitokenking.com.tw/api/v1", + "api_key_env": "AITOKENKING_API_KEY", + "api_base_env": "AITOKENKING_API_BASE", + "param_mappings": { + "max_completion_tokens": "max_tokens" + }, + "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 d8a8f84b0323..8831451a58a2 100644 --- a/litellm/model_prices_and_context_window_backup.json +++ b/litellm/model_prices_and_context_window_backup.json @@ -58456,5 +58456,389 @@ "supported_endpoints": [ "/v1/audio/transcriptions" ] + }, + "aitokenking/claude-fable-5": { + "input_cost_per_token": 1e-05, + "litellm_provider": "aitokenking", + "max_input_tokens": 1000000, + "mode": "chat", + "output_cost_per_token": 5e-05, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/claude-opus-4.6": { + "input_cost_per_token": 5e-06, + "litellm_provider": "aitokenking", + "max_input_tokens": 1000000, + "mode": "chat", + "output_cost_per_token": 2.5e-05, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/claude-opus-4.7": { + "input_cost_per_token": 5e-06, + "litellm_provider": "aitokenking", + "max_input_tokens": 1000000, + "mode": "chat", + "output_cost_per_token": 2.5e-05, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/claude-opus-4.8": { + "input_cost_per_token": 5e-06, + "litellm_provider": "aitokenking", + "max_input_tokens": 1000000, + "mode": "chat", + "output_cost_per_token": 2.5e-05, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/claude-opus-5": { + "input_cost_per_token": 5e-06, + "litellm_provider": "aitokenking", + "max_input_tokens": 1000000, + "mode": "chat", + "output_cost_per_token": 2.5e-05, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/claude-sonnet-4.6": { + "input_cost_per_token": 3e-06, + "litellm_provider": "aitokenking", + "max_input_tokens": 1000000, + "mode": "chat", + "output_cost_per_token": 1.5e-05, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/claude-sonnet-5": { + "input_cost_per_token": 2e-06, + "litellm_provider": "aitokenking", + "max_input_tokens": 1000000, + "mode": "chat", + "output_cost_per_token": 1e-05, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/deepseek-v3.2": { + "input_cost_per_token": 5.699999999999999e-07, + "litellm_provider": "aitokenking", + "max_input_tokens": 128000, + "mode": "chat", + "output_cost_per_token": 1.71e-06, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/deepseek-v4-flash": { + "input_cost_per_token": 1.4e-07, + "litellm_provider": "aitokenking", + "max_input_tokens": 1000000, + "mode": "chat", + "output_cost_per_token": 2.8e-07, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/deepseek-v4-pro": { + "input_cost_per_token": 1.74e-06, + "litellm_provider": "aitokenking", + "max_input_tokens": 1000000, + "mode": "chat", + "output_cost_per_token": 3.48e-06, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/dola-seed-2-0-mini": { + "input_cost_per_token": 2.0000000000000002e-07, + "litellm_provider": "aitokenking", + "max_input_tokens": 262144, + "mode": "chat", + "output_cost_per_token": 8.000000000000001e-07, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/dola-seed-2-0-mini-white": { + "input_cost_per_token": 2.0000000000000002e-07, + "litellm_provider": "aitokenking", + "max_input_tokens": 262144, + "mode": "chat", + "output_cost_per_token": 8.000000000000001e-07, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/dola-seed-2-1-turbo": { + "input_cost_per_token": 5e-07, + "litellm_provider": "aitokenking", + "max_input_tokens": 262144, + "mode": "chat", + "output_cost_per_token": 2.5e-06, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/dola-seed-2.0-code": { + "input_cost_per_token": 5e-07, + "litellm_provider": "aitokenking", + "max_input_tokens": 262144, + "mode": "chat", + "output_cost_per_token": 3e-06, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/dola-seed-2.0-lite": { + "input_cost_per_token": 5e-07, + "litellm_provider": "aitokenking", + "max_input_tokens": 262144, + "mode": "chat", + "output_cost_per_token": 4e-06, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/dola-seed-2.0-pro": { + "input_cost_per_token": 1e-06, + "litellm_provider": "aitokenking", + "max_input_tokens": 262144, + "mode": "chat", + "output_cost_per_token": 6e-06, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/gemini-3-flash-preview": { + "input_cost_per_token": 5e-07, + "litellm_provider": "aitokenking", + "max_input_tokens": 1048576, + "mode": "chat", + "output_cost_per_token": 3e-06, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/gemini-3.1-pro-preview": { + "input_cost_per_token": 4e-06, + "litellm_provider": "aitokenking", + "max_input_tokens": 1048576, + "mode": "chat", + "output_cost_per_token": 1.8e-05, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/glm-5": { + "input_cost_per_token": 1e-06, + "litellm_provider": "aitokenking", + "max_input_tokens": 200000, + "mode": "chat", + "output_cost_per_token": 3.2000000000000003e-06, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/glm-5-turbo": { + "input_cost_per_token": 1.2e-06, + "litellm_provider": "aitokenking", + "max_input_tokens": 200000, + "mode": "chat", + "output_cost_per_token": 4e-06, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/glm-5.1": { + "input_cost_per_token": 1.4e-06, + "litellm_provider": "aitokenking", + "max_input_tokens": 200000, + "mode": "chat", + "output_cost_per_token": 4.4e-06, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/glm-5.2": { + "input_cost_per_token": 1.4e-06, + "litellm_provider": "aitokenking", + "max_input_tokens": 1000000, + "mode": "chat", + "output_cost_per_token": 4.4e-06, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/glm-5.3": { + "input_cost_per_token": 1.4e-06, + "litellm_provider": "aitokenking", + "max_input_tokens": 1048576, + "mode": "chat", + "output_cost_per_token": 4.4e-06, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/glm-5v-turbo": { + "input_cost_per_token": 1.2e-06, + "litellm_provider": "aitokenking", + "max_input_tokens": 200000, + "mode": "chat", + "output_cost_per_token": 4e-06, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/gpt-5-nano": { + "input_cost_per_token": 5.0000000000000004e-08, + "litellm_provider": "aitokenking", + "max_input_tokens": 400000, + "mode": "chat", + "output_cost_per_token": 4.0000000000000003e-07, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/gpt-5.4": { + "input_cost_per_token": 5e-06, + "litellm_provider": "aitokenking", + "max_input_tokens": 1050000, + "mode": "chat", + "output_cost_per_token": 2.25e-05, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/gpt-5.5": { + "input_cost_per_token": 5e-06, + "litellm_provider": "aitokenking", + "max_input_tokens": 1050000, + "mode": "chat", + "output_cost_per_token": 3e-05, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/gpt-5.6-luna": { + "input_cost_per_token": 2e-06, + "litellm_provider": "aitokenking", + "max_input_tokens": 1050000, + "mode": "chat", + "output_cost_per_token": 9e-06, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/gpt-5.6-sol": { + "input_cost_per_token": 1e-05, + "litellm_provider": "aitokenking", + "max_input_tokens": 1050000, + "mode": "chat", + "output_cost_per_token": 4.5e-05, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/gpt-5.6-terra": { + "input_cost_per_token": 5e-06, + "litellm_provider": "aitokenking", + "max_input_tokens": 1050000, + "mode": "chat", + "output_cost_per_token": 2.25e-05, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/kimi-k2.5": { + "input_cost_per_token": 6e-07, + "litellm_provider": "aitokenking", + "max_input_tokens": 256000, + "mode": "chat", + "output_cost_per_token": 3e-06, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/kimi-k2.6": { + "input_cost_per_token": 8.58e-07, + "litellm_provider": "aitokenking", + "max_input_tokens": 256000, + "mode": "chat", + "output_cost_per_token": 3.566e-06, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/kimi-k2.7-code": { + "input_cost_per_token": 9.499999999999999e-07, + "litellm_provider": "aitokenking", + "max_input_tokens": 256000, + "mode": "chat", + "output_cost_per_token": 4e-06, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/kimi-k2.7-code-highspeed": { + "input_cost_per_token": 1.8999999999999998e-06, + "litellm_provider": "aitokenking", + "max_input_tokens": 256000, + "mode": "chat", + "output_cost_per_token": 8e-06, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/kimi-k3": { + "input_cost_per_token": 3e-06, + "litellm_provider": "aitokenking", + "max_input_tokens": 1000000, + "mode": "chat", + "output_cost_per_token": 1.5e-05, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/minimax-m2.5": { + "input_cost_per_token": 3e-07, + "litellm_provider": "aitokenking", + "max_input_tokens": 200000, + "mode": "chat", + "output_cost_per_token": 1.2e-06, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/minimax-m2.7": { + "input_cost_per_token": 3e-07, + "litellm_provider": "aitokenking", + "max_input_tokens": 200000, + "mode": "chat", + "output_cost_per_token": 1.2e-06, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/minimax-m3": { + "input_cost_per_token": 6e-07, + "litellm_provider": "aitokenking", + "max_input_tokens": 1000000, + "mode": "chat", + "output_cost_per_token": 2.4e-06, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/qwen3-max": { + "input_cost_per_token": 1.2e-06, + "litellm_provider": "aitokenking", + "max_input_tokens": 256000, + "mode": "chat", + "output_cost_per_token": 6e-06, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/qwen3-max-white": { + "input_cost_per_token": 2.4e-06, + "litellm_provider": "aitokenking", + "max_input_tokens": 256000, + "mode": "chat", + "output_cost_per_token": 1.2e-05, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/qwen3-vl-flash": { + "input_cost_per_token": 7.5e-08, + "litellm_provider": "aitokenking", + "max_input_tokens": 256000, + "mode": "chat", + "output_cost_per_token": 6e-07, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/qwen3-vl-plus": { + "input_cost_per_token": 6e-07, + "litellm_provider": "aitokenking", + "max_input_tokens": 256000, + "mode": "chat", + "output_cost_per_token": 4.8e-06, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/qwen3.5-plus": { + "input_cost_per_token": 5e-07, + "litellm_provider": "aitokenking", + "max_input_tokens": 1000000, + "mode": "chat", + "output_cost_per_token": 3e-06, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/qwen3.5-plus-white": { + "input_cost_per_token": 4.0000000000000003e-07, + "litellm_provider": "aitokenking", + "max_input_tokens": 1000000, + "mode": "chat", + "output_cost_per_token": 2.4e-06, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/qwen3.6-plus": { + "input_cost_per_token": 5e-07, + "litellm_provider": "aitokenking", + "max_input_tokens": 1000000, + "mode": "chat", + "output_cost_per_token": 3e-06, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/qwen3.7-max": { + "input_cost_per_token": 2.5e-06, + "litellm_provider": "aitokenking", + "max_input_tokens": 1000000, + "mode": "chat", + "output_cost_per_token": 7.5e-06, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/qwen3.7-plus": { + "input_cost_per_token": 4.0000000000000003e-07, + "litellm_provider": "aitokenking", + "max_input_tokens": 1000000, + "mode": "chat", + "output_cost_per_token": 1.6000000000000001e-06, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/qwen3.8-max": { + "input_cost_per_token": 2e-06, + "litellm_provider": "aitokenking", + "max_input_tokens": 1000000, + "mode": "chat", + "output_cost_per_token": 6e-06, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" } } diff --git a/litellm/types/utils.py b/litellm/types/utils.py index 569fce4f7b8e..bf2566e9b4c5 100644 --- a/litellm/types/utils.py +++ b/litellm/types/utils.py @@ -3906,6 +3906,7 @@ class LlmProviders(str, Enum): TENSORMESH = "tensormesh" LIBERTAI = "libertai" PINSTRIPES = "pinstripes" + AITOKENKING = "aitokenking" COGNITION = "cognition" SCX_AI = "scx-ai" DARKBLOOM = "darkbloom" diff --git a/model_prices_and_context_window.json b/model_prices_and_context_window.json index d8a8f84b0323..8831451a58a2 100644 --- a/model_prices_and_context_window.json +++ b/model_prices_and_context_window.json @@ -58456,5 +58456,389 @@ "supported_endpoints": [ "/v1/audio/transcriptions" ] + }, + "aitokenking/claude-fable-5": { + "input_cost_per_token": 1e-05, + "litellm_provider": "aitokenking", + "max_input_tokens": 1000000, + "mode": "chat", + "output_cost_per_token": 5e-05, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/claude-opus-4.6": { + "input_cost_per_token": 5e-06, + "litellm_provider": "aitokenking", + "max_input_tokens": 1000000, + "mode": "chat", + "output_cost_per_token": 2.5e-05, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/claude-opus-4.7": { + "input_cost_per_token": 5e-06, + "litellm_provider": "aitokenking", + "max_input_tokens": 1000000, + "mode": "chat", + "output_cost_per_token": 2.5e-05, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/claude-opus-4.8": { + "input_cost_per_token": 5e-06, + "litellm_provider": "aitokenking", + "max_input_tokens": 1000000, + "mode": "chat", + "output_cost_per_token": 2.5e-05, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/claude-opus-5": { + "input_cost_per_token": 5e-06, + "litellm_provider": "aitokenking", + "max_input_tokens": 1000000, + "mode": "chat", + "output_cost_per_token": 2.5e-05, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/claude-sonnet-4.6": { + "input_cost_per_token": 3e-06, + "litellm_provider": "aitokenking", + "max_input_tokens": 1000000, + "mode": "chat", + "output_cost_per_token": 1.5e-05, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/claude-sonnet-5": { + "input_cost_per_token": 2e-06, + "litellm_provider": "aitokenking", + "max_input_tokens": 1000000, + "mode": "chat", + "output_cost_per_token": 1e-05, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/deepseek-v3.2": { + "input_cost_per_token": 5.699999999999999e-07, + "litellm_provider": "aitokenking", + "max_input_tokens": 128000, + "mode": "chat", + "output_cost_per_token": 1.71e-06, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/deepseek-v4-flash": { + "input_cost_per_token": 1.4e-07, + "litellm_provider": "aitokenking", + "max_input_tokens": 1000000, + "mode": "chat", + "output_cost_per_token": 2.8e-07, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/deepseek-v4-pro": { + "input_cost_per_token": 1.74e-06, + "litellm_provider": "aitokenking", + "max_input_tokens": 1000000, + "mode": "chat", + "output_cost_per_token": 3.48e-06, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/dola-seed-2-0-mini": { + "input_cost_per_token": 2.0000000000000002e-07, + "litellm_provider": "aitokenking", + "max_input_tokens": 262144, + "mode": "chat", + "output_cost_per_token": 8.000000000000001e-07, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/dola-seed-2-0-mini-white": { + "input_cost_per_token": 2.0000000000000002e-07, + "litellm_provider": "aitokenking", + "max_input_tokens": 262144, + "mode": "chat", + "output_cost_per_token": 8.000000000000001e-07, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/dola-seed-2-1-turbo": { + "input_cost_per_token": 5e-07, + "litellm_provider": "aitokenking", + "max_input_tokens": 262144, + "mode": "chat", + "output_cost_per_token": 2.5e-06, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/dola-seed-2.0-code": { + "input_cost_per_token": 5e-07, + "litellm_provider": "aitokenking", + "max_input_tokens": 262144, + "mode": "chat", + "output_cost_per_token": 3e-06, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/dola-seed-2.0-lite": { + "input_cost_per_token": 5e-07, + "litellm_provider": "aitokenking", + "max_input_tokens": 262144, + "mode": "chat", + "output_cost_per_token": 4e-06, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/dola-seed-2.0-pro": { + "input_cost_per_token": 1e-06, + "litellm_provider": "aitokenking", + "max_input_tokens": 262144, + "mode": "chat", + "output_cost_per_token": 6e-06, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/gemini-3-flash-preview": { + "input_cost_per_token": 5e-07, + "litellm_provider": "aitokenking", + "max_input_tokens": 1048576, + "mode": "chat", + "output_cost_per_token": 3e-06, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/gemini-3.1-pro-preview": { + "input_cost_per_token": 4e-06, + "litellm_provider": "aitokenking", + "max_input_tokens": 1048576, + "mode": "chat", + "output_cost_per_token": 1.8e-05, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/glm-5": { + "input_cost_per_token": 1e-06, + "litellm_provider": "aitokenking", + "max_input_tokens": 200000, + "mode": "chat", + "output_cost_per_token": 3.2000000000000003e-06, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/glm-5-turbo": { + "input_cost_per_token": 1.2e-06, + "litellm_provider": "aitokenking", + "max_input_tokens": 200000, + "mode": "chat", + "output_cost_per_token": 4e-06, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/glm-5.1": { + "input_cost_per_token": 1.4e-06, + "litellm_provider": "aitokenking", + "max_input_tokens": 200000, + "mode": "chat", + "output_cost_per_token": 4.4e-06, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/glm-5.2": { + "input_cost_per_token": 1.4e-06, + "litellm_provider": "aitokenking", + "max_input_tokens": 1000000, + "mode": "chat", + "output_cost_per_token": 4.4e-06, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/glm-5.3": { + "input_cost_per_token": 1.4e-06, + "litellm_provider": "aitokenking", + "max_input_tokens": 1048576, + "mode": "chat", + "output_cost_per_token": 4.4e-06, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/glm-5v-turbo": { + "input_cost_per_token": 1.2e-06, + "litellm_provider": "aitokenking", + "max_input_tokens": 200000, + "mode": "chat", + "output_cost_per_token": 4e-06, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/gpt-5-nano": { + "input_cost_per_token": 5.0000000000000004e-08, + "litellm_provider": "aitokenking", + "max_input_tokens": 400000, + "mode": "chat", + "output_cost_per_token": 4.0000000000000003e-07, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/gpt-5.4": { + "input_cost_per_token": 5e-06, + "litellm_provider": "aitokenking", + "max_input_tokens": 1050000, + "mode": "chat", + "output_cost_per_token": 2.25e-05, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/gpt-5.5": { + "input_cost_per_token": 5e-06, + "litellm_provider": "aitokenking", + "max_input_tokens": 1050000, + "mode": "chat", + "output_cost_per_token": 3e-05, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/gpt-5.6-luna": { + "input_cost_per_token": 2e-06, + "litellm_provider": "aitokenking", + "max_input_tokens": 1050000, + "mode": "chat", + "output_cost_per_token": 9e-06, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/gpt-5.6-sol": { + "input_cost_per_token": 1e-05, + "litellm_provider": "aitokenking", + "max_input_tokens": 1050000, + "mode": "chat", + "output_cost_per_token": 4.5e-05, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/gpt-5.6-terra": { + "input_cost_per_token": 5e-06, + "litellm_provider": "aitokenking", + "max_input_tokens": 1050000, + "mode": "chat", + "output_cost_per_token": 2.25e-05, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/kimi-k2.5": { + "input_cost_per_token": 6e-07, + "litellm_provider": "aitokenking", + "max_input_tokens": 256000, + "mode": "chat", + "output_cost_per_token": 3e-06, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/kimi-k2.6": { + "input_cost_per_token": 8.58e-07, + "litellm_provider": "aitokenking", + "max_input_tokens": 256000, + "mode": "chat", + "output_cost_per_token": 3.566e-06, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/kimi-k2.7-code": { + "input_cost_per_token": 9.499999999999999e-07, + "litellm_provider": "aitokenking", + "max_input_tokens": 256000, + "mode": "chat", + "output_cost_per_token": 4e-06, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/kimi-k2.7-code-highspeed": { + "input_cost_per_token": 1.8999999999999998e-06, + "litellm_provider": "aitokenking", + "max_input_tokens": 256000, + "mode": "chat", + "output_cost_per_token": 8e-06, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/kimi-k3": { + "input_cost_per_token": 3e-06, + "litellm_provider": "aitokenking", + "max_input_tokens": 1000000, + "mode": "chat", + "output_cost_per_token": 1.5e-05, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/minimax-m2.5": { + "input_cost_per_token": 3e-07, + "litellm_provider": "aitokenking", + "max_input_tokens": 200000, + "mode": "chat", + "output_cost_per_token": 1.2e-06, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/minimax-m2.7": { + "input_cost_per_token": 3e-07, + "litellm_provider": "aitokenking", + "max_input_tokens": 200000, + "mode": "chat", + "output_cost_per_token": 1.2e-06, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/minimax-m3": { + "input_cost_per_token": 6e-07, + "litellm_provider": "aitokenking", + "max_input_tokens": 1000000, + "mode": "chat", + "output_cost_per_token": 2.4e-06, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/qwen3-max": { + "input_cost_per_token": 1.2e-06, + "litellm_provider": "aitokenking", + "max_input_tokens": 256000, + "mode": "chat", + "output_cost_per_token": 6e-06, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/qwen3-max-white": { + "input_cost_per_token": 2.4e-06, + "litellm_provider": "aitokenking", + "max_input_tokens": 256000, + "mode": "chat", + "output_cost_per_token": 1.2e-05, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/qwen3-vl-flash": { + "input_cost_per_token": 7.5e-08, + "litellm_provider": "aitokenking", + "max_input_tokens": 256000, + "mode": "chat", + "output_cost_per_token": 6e-07, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/qwen3-vl-plus": { + "input_cost_per_token": 6e-07, + "litellm_provider": "aitokenking", + "max_input_tokens": 256000, + "mode": "chat", + "output_cost_per_token": 4.8e-06, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/qwen3.5-plus": { + "input_cost_per_token": 5e-07, + "litellm_provider": "aitokenking", + "max_input_tokens": 1000000, + "mode": "chat", + "output_cost_per_token": 3e-06, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/qwen3.5-plus-white": { + "input_cost_per_token": 4.0000000000000003e-07, + "litellm_provider": "aitokenking", + "max_input_tokens": 1000000, + "mode": "chat", + "output_cost_per_token": 2.4e-06, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/qwen3.6-plus": { + "input_cost_per_token": 5e-07, + "litellm_provider": "aitokenking", + "max_input_tokens": 1000000, + "mode": "chat", + "output_cost_per_token": 3e-06, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/qwen3.7-max": { + "input_cost_per_token": 2.5e-06, + "litellm_provider": "aitokenking", + "max_input_tokens": 1000000, + "mode": "chat", + "output_cost_per_token": 7.5e-06, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/qwen3.7-plus": { + "input_cost_per_token": 4.0000000000000003e-07, + "litellm_provider": "aitokenking", + "max_input_tokens": 1000000, + "mode": "chat", + "output_cost_per_token": 1.6000000000000001e-06, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" + }, + "aitokenking/qwen3.8-max": { + "input_cost_per_token": 2e-06, + "litellm_provider": "aitokenking", + "max_input_tokens": 1000000, + "mode": "chat", + "output_cost_per_token": 6e-06, + "source": "https://www.aitokenking.com.tw/assets/docs/zh/index.html" } } diff --git a/provider_endpoints_support.json b/provider_endpoints_support.json index ebc220b34965..eb8f02c79149 100644 --- a/provider_endpoints_support.json +++ b/provider_endpoints_support.json @@ -3026,6 +3026,23 @@ "rerank": false, "a2a": false } + }, + "aitokenking": { + "display_name": "AI Token King (`aitokenking`)", + "url": "https://docs.litellm.ai/docs/providers/aitokenking", + "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 + } } }, "endpoints": { diff --git a/tests/test_litellm/llms/openai_like/test_aitokenking_provider.py b/tests/test_litellm/llms/openai_like/test_aitokenking_provider.py new file mode 100644 index 000000000000..433a3f1b81dd --- /dev/null +++ b/tests/test_litellm/llms/openai_like/test_aitokenking_provider.py @@ -0,0 +1,168 @@ +""" +Tests for the AI Token King provider (JSON-configured, OpenAI-compatible gateway). +""" + +import json +from pathlib import Path + +import litellm + +BASE_URL = "https://api.aitokenking.com.tw/api/v1" + + +class TestAITokenKingProviderConfig: + """AI Token King provider configuration and resolution.""" + + def test_aitokenking_in_provider_list(self): + from litellm import LlmProviders + + assert hasattr(LlmProviders, "AITOKENKING") + assert LlmProviders.AITOKENKING.value == "aitokenking" + assert "aitokenking" in litellm.provider_list + + def test_aitokenking_json_config_exists(self): + from litellm.llms.openai_like.json_loader import JSONProviderRegistry + + assert JSONProviderRegistry.exists("aitokenking") + + cfg = JSONProviderRegistry.get("aitokenking") + assert cfg is not None + assert cfg.base_url == BASE_URL + assert cfg.api_key_env == "AITOKENKING_API_KEY" + assert cfg.api_base_env == "AITOKENKING_API_BASE" + assert cfg.param_mappings.get("max_completion_tokens") == "max_tokens" + assert cfg.supported_endpoints == ["/v1/chat/completions"] + + def test_aitokenking_in_openai_compatible_providers(self): + from litellm.constants import openai_compatible_endpoints, openai_compatible_providers + + assert "aitokenking" in openai_compatible_providers + assert BASE_URL in openai_compatible_endpoints + + def test_aitokenking_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="aitokenking/qwen3.7-max", + custom_llm_provider=None, + api_base=None, + api_key=None, + ) + + assert model == "qwen3.7-max" + assert provider == "aitokenking" + assert api_base == BASE_URL + + def test_aitokenking_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="aitokenking/qwen3.7-max", + custom_llm_provider=None, + api_base="https://custom.example.com/v1", + api_key="sk-test", + ) + + assert provider == "aitokenking" + assert api_base == "https://custom.example.com/v1" + assert api_key == "sk-test" + + def test_aitokenking_url_autodetection(self): + """Passing the gateway's api_base without a prefix resolves the provider.""" + from litellm.litellm_core_utils.get_llm_provider_logic import get_llm_provider + + model, provider, api_key, api_base = get_llm_provider( + model="qwen3.7-max", + custom_llm_provider=None, + api_base=BASE_URL, + api_key=None, + ) + assert provider == "aitokenking" + assert api_base == BASE_URL + + def test_aitokenking_router_config(self): + from litellm import Router + + router = Router( + model_list=[ + { + "model_name": "atk-chat", + "litellm_params": { + "model": "aitokenking/qwen3.7-max", + "api_key": "test-key", + }, + } + ] + ) + + assert len(router.model_list) == 1 + assert router.model_list[0]["model_name"] == "atk-chat" + + +class TestAITokenKingPricing: + """Cost tracking is the point of shipping the price map with the provider.""" + + @staticmethod + def _load_price_map() -> dict: + json_path = Path(__file__).parents[4] / "model_prices_and_context_window.json" + with open(json_path) as f: + return json.load(f) + + def test_price_map_entries_use_provider_prefix(self): + model_cost = self._load_price_map() + keys = [k for k in model_cost if k.startswith("aitokenking/")] + assert len(keys) == 48 + for k in keys: + entry = model_cost[k] + assert entry["litellm_provider"] == "aitokenking" + assert entry["mode"] == "chat" + # A zero price would read as "free" rather than "unknown"; never ship one. + assert entry["input_cost_per_token"] > 0 + assert entry["output_cost_per_token"] > 0 + + def test_prefixed_keys_do_not_shadow_upstream_vendor_entries(self): + """Some gateway model ids match vendor ids already in the map (e.g. gpt-5.5). + + The gateway resells at its own price, so the entry must live under the + provider prefix only — a bare-id entry would overwrite the vendor's price + for everyone. + """ + model_cost = self._load_price_map() + for bare in ("gpt-5.5", "claude-sonnet-5", "gemini-3.1-pro-preview"): + assert f"aitokenking/{bare}" in model_cost + assert model_cost[bare]["litellm_provider"] != "aitokenking" + + def test_completion_cost_resolves_for_prefixed_model(self, monkeypatch): + from litellm.types.utils import ModelResponse + + model = "aitokenking/qwen3.7-max" + entry = self._load_price_map()[model] + monkeypatch.setitem(litellm.model_cost, model, entry) + + prompt_tokens, completion_tokens = 100_000, 100_000 + expected = entry["input_cost_per_token"] * prompt_tokens + entry["output_cost_per_token"] * completion_tokens + + response = ModelResponse( + **{ + "id": "chatcmpl-test", + "object": "chat.completion", + "created": 0, + "model": model, + "choices": [ + { + "index": 0, + "finish_reason": "stop", + "message": {"role": "assistant", "content": "ok"}, + } + ], + "usage": { + "prompt_tokens": prompt_tokens, + "completion_tokens": completion_tokens, + "total_tokens": prompt_tokens + completion_tokens, + }, + } + ) + + cost = litellm.completion_cost(completion_response=response, model=model) + assert abs(cost - expected) < 1e-9 + assert cost > 0 From 11693a218010018add0fcc9cd5d0efa2792e1836 Mon Sep 17 00:00:00 2001 From: firekou Date: Fri, 4 Sep 2026 11:30:32 +0000 Subject: [PATCH 2/3] chore(providers): drop redundant inline comment on the aitokenking entry Review feedback: the comment restated the code. The neighbouring JSON-configured entries carry the same trailing comment, but the repo guideline is to reserve comments for non-obvious logic, so the new line drops it rather than adding one more instance. --- litellm/constants.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/litellm/constants.py b/litellm/constants.py index 17b15d637b0f..a4276722265d 100644 --- a/litellm/constants.py +++ b/litellm/constants.py @@ -933,7 +933,7 @@ "docker_model_runner", "ragflow", "pinstripes", # Pinstripes - JSON-configured provider - "aitokenking", # AI Token King - JSON-configured provider + "aitokenking", "darkbloom", "meta", # Meta Model API (Muse Spark) - JSON-configured provider "cognition", From 663a64a41e1240ff3cc2fce1a6b6922a84492b62 Mon Sep 17 00:00:00 2001 From: firekou Date: Fri, 4 Sep 2026 13:55:30 +0000 Subject: [PATCH 3/3] test(providers): exercise the aitokenking dispatch path, not just its config Review feedback: the Router test only asserted the stored model list, which proves nothing about what happens when a request is actually routed. Replaces it with two functional tests through Router.acompletion, following the pattern already used by the neighbouring cognition provider tests: - the routed request resolves to the gateway base URL and the response model is the bare id, so the `aitokenking/` prefix selects the provider without reaching the wire; - the routed response is costed from the aitokenking price-map entry and is non-zero. This is the regression the price map exists to prevent: Router registers every deployment, so an unmapped gateway model reports 0.0, which reads as "free" rather than "unknown". Verified the cost assertion actually catches that regression: with the `aitokenking/qwen3.7-max` entry temporarily renamed the test fails, and it passes again once restored. --- .../openai_like/test_aitokenking_provider.py | 73 ++++++++++++++----- 1 file changed, 55 insertions(+), 18 deletions(-) diff --git a/tests/test_litellm/llms/openai_like/test_aitokenking_provider.py b/tests/test_litellm/llms/openai_like/test_aitokenking_provider.py index 433a3f1b81dd..69b6d8d868d0 100644 --- a/tests/test_litellm/llms/openai_like/test_aitokenking_provider.py +++ b/tests/test_litellm/llms/openai_like/test_aitokenking_provider.py @@ -6,6 +6,7 @@ from pathlib import Path import litellm +import pytest BASE_URL = "https://api.aitokenking.com.tw/api/v1" @@ -80,24 +81,6 @@ def test_aitokenking_url_autodetection(self): assert provider == "aitokenking" assert api_base == BASE_URL - def test_aitokenking_router_config(self): - from litellm import Router - - router = Router( - model_list=[ - { - "model_name": "atk-chat", - "litellm_params": { - "model": "aitokenking/qwen3.7-max", - "api_key": "test-key", - }, - } - ] - ) - - assert len(router.model_list) == 1 - assert router.model_list[0]["model_name"] == "atk-chat" - class TestAITokenKingPricing: """Cost tracking is the point of shipping the price map with the provider.""" @@ -166,3 +149,57 @@ def test_completion_cost_resolves_for_prefixed_model(self, monkeypatch): cost = litellm.completion_cost(completion_response=response, model=model) assert abs(cost - expected) < 1e-9 assert cost > 0 + +class TestAITokenKingRouting: + """Exercises the dispatch path, not just the stored configuration.""" + + @staticmethod + def _router(): + from litellm import Router + + return Router( + model_list=[ + { + "model_name": "atk-chat", + "litellm_params": { + "model": "aitokenking/qwen3.7-max", + "api_key": "sk-test", + }, + } + ] + ) + + @pytest.mark.asyncio + async def test_routed_request_targets_the_gateway_with_the_prefix_stripped(self): + """The prefix selects the provider; it must not reach the wire.""" + response = await self._router().acompletion( + model="atk-chat", + messages=[{"role": "user", "content": "hi"}], + mock_response="ok", + ) + + assert response._hidden_params["api_base"] == BASE_URL + assert response.model == "qwen3.7-max" + + @pytest.mark.asyncio + async def test_routed_spend_is_costed_off_the_aitokenking_entry(self): + """Router registers every deployment, so an unmapped model silently costs 0.0. + + This is the regression the price map exists to prevent: assert the routed + response is costed from the aitokenking entry rather than defaulting to zero. + """ + entry = TestAITokenKingPricing._load_price_map()["aitokenking/qwen3.7-max"] + + response = await self._router().acompletion( + model="atk-chat", + messages=[{"role": "user", "content": "hi"}], + mock_response="ok", + ) + + usage = response.usage + expected = ( + usage.prompt_tokens * entry["input_cost_per_token"] + + usage.completion_tokens * entry["output_cost_per_token"] + ) + assert response._hidden_params["response_cost"] == pytest.approx(expected) + assert response._hidden_params["response_cost"] > 0