feat(ai): add Qwen Token Plan as built-in provider (#6858)
Add Alibaba Cloud Model Studio Token Plan subscription service as two built-in API-key providers: qwen-token-plan (international, Singapore) and qwen-token-plan-cn (China, Beijing). Each provider exposes 15 text-generation models (Qwen, DeepSeek, GLM, Kimi, MiniMax) via the OpenAI-compatible endpoint with DashScope enable_thinking support. Model metadata is sourced from models.dev; qwen3.8-max-preview is hardcoded until models.dev includes it. Also fixes kimi-coding test references (k2p7 -> kimi-for-coding) after models.dev catalog update picked up by generate-models. Closes #6850
This commit is contained in:
@@ -73,6 +73,8 @@ function getApiKeyEnvVars(provider: string): readonly string[] | undefined {
|
||||
|
||||
const envMap: Record<string, string> = {
|
||||
"ant-ling": "ANT_LING_API_KEY",
|
||||
"qwen-token-plan": "QWEN_TOKEN_PLAN_API_KEY",
|
||||
"qwen-token-plan-cn": "QWEN_TOKEN_PLAN_CN_API_KEY",
|
||||
openai: "OPENAI_API_KEY",
|
||||
"azure-openai-responses": "AZURE_OPENAI_API_KEY",
|
||||
nvidia: "NVIDIA_API_KEY",
|
||||
|
||||
@@ -27,6 +27,8 @@ import { OPENAI_CODEX_MODELS } from "./providers/openai-codex.models.ts";
|
||||
import { OPENCODE_MODELS } from "./providers/opencode.models.ts";
|
||||
import { OPENCODE_GO_MODELS } from "./providers/opencode-go.models.ts";
|
||||
import { OPENROUTER_MODELS } from "./providers/openrouter.models.ts";
|
||||
import { QWEN_TOKEN_PLAN_MODELS } from "./providers/qwen-token-plan.models.ts";
|
||||
import { QWEN_TOKEN_PLAN_CN_MODELS } from "./providers/qwen-token-plan-cn.models.ts";
|
||||
import { TOGETHER_MODELS } from "./providers/together.models.ts";
|
||||
import { VERCEL_AI_GATEWAY_MODELS } from "./providers/vercel-ai-gateway.models.ts";
|
||||
import { XAI_MODELS } from "./providers/xai.models.ts";
|
||||
@@ -64,6 +66,8 @@ export const MODELS = {
|
||||
"opencode": OPENCODE_MODELS,
|
||||
"opencode-go": OPENCODE_GO_MODELS,
|
||||
"openrouter": OPENROUTER_MODELS,
|
||||
"qwen-token-plan": QWEN_TOKEN_PLAN_MODELS,
|
||||
"qwen-token-plan-cn": QWEN_TOKEN_PLAN_CN_MODELS,
|
||||
"together": TOGETHER_MODELS,
|
||||
"vercel-ai-gateway": VERCEL_AI_GATEWAY_MODELS,
|
||||
"xai": XAI_MODELS,
|
||||
|
||||
@@ -29,6 +29,8 @@ import { opencodeProvider } from "./opencode.ts";
|
||||
import { opencodeGoProvider } from "./opencode-go.ts";
|
||||
import { openrouterProvider } from "./openrouter.ts";
|
||||
import { openrouterImagesProvider } from "./openrouter-images.ts";
|
||||
import { qwenTokenPlanProvider } from "./qwen-token-plan.ts";
|
||||
import { qwenTokenPlanCnProvider } from "./qwen-token-plan-cn.ts";
|
||||
import { radiusProvider } from "./radius.ts";
|
||||
import { togetherProvider } from "./together.ts";
|
||||
import { vercelAIGatewayProvider } from "./vercel-ai-gateway.ts";
|
||||
@@ -103,6 +105,8 @@ export function builtinProviders(): Provider[] {
|
||||
opencodeProvider(),
|
||||
opencodeGoProvider(),
|
||||
openrouterProvider(),
|
||||
qwenTokenPlanProvider(),
|
||||
qwenTokenPlanCnProvider(),
|
||||
radiusProvider(),
|
||||
togetherProvider(),
|
||||
vercelAIGatewayProvider(),
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
// This file is auto-generated by scripts/generate-models.ts
|
||||
// Do not edit manually - run 'npm run generate-models' to update
|
||||
|
||||
import values from "./data/qwen-token-plan-cn.json" with { type: "json" };
|
||||
import type { Model } from "../types.ts";
|
||||
|
||||
export const QWEN_TOKEN_PLAN_CN_MODELS = values as {
|
||||
"MiniMax-M2.5": Model<"openai-completions"> & {
|
||||
id: "MiniMax-M2.5";
|
||||
provider: "qwen-token-plan-cn";
|
||||
};
|
||||
"deepseek-v3.2": Model<"openai-completions"> & {
|
||||
id: "deepseek-v3.2";
|
||||
provider: "qwen-token-plan-cn";
|
||||
};
|
||||
"deepseek-v4-flash": Model<"openai-completions"> & {
|
||||
id: "deepseek-v4-flash";
|
||||
provider: "qwen-token-plan-cn";
|
||||
};
|
||||
"deepseek-v4-pro": Model<"openai-completions"> & {
|
||||
id: "deepseek-v4-pro";
|
||||
provider: "qwen-token-plan-cn";
|
||||
};
|
||||
"glm-5": Model<"openai-completions"> & {
|
||||
id: "glm-5";
|
||||
provider: "qwen-token-plan-cn";
|
||||
};
|
||||
"glm-5.1": Model<"openai-completions"> & {
|
||||
id: "glm-5.1";
|
||||
provider: "qwen-token-plan-cn";
|
||||
};
|
||||
"glm-5.2": Model<"openai-completions"> & {
|
||||
id: "glm-5.2";
|
||||
provider: "qwen-token-plan-cn";
|
||||
};
|
||||
"kimi-k2.5": Model<"openai-completions"> & {
|
||||
id: "kimi-k2.5";
|
||||
provider: "qwen-token-plan-cn";
|
||||
};
|
||||
"kimi-k2.6": Model<"openai-completions"> & {
|
||||
id: "kimi-k2.6";
|
||||
provider: "qwen-token-plan-cn";
|
||||
};
|
||||
"kimi-k2.7-code": Model<"openai-completions"> & {
|
||||
id: "kimi-k2.7-code";
|
||||
provider: "qwen-token-plan-cn";
|
||||
};
|
||||
"qwen3.6-flash": Model<"openai-completions"> & {
|
||||
id: "qwen3.6-flash";
|
||||
provider: "qwen-token-plan-cn";
|
||||
};
|
||||
"qwen3.6-plus": Model<"openai-completions"> & {
|
||||
id: "qwen3.6-plus";
|
||||
provider: "qwen-token-plan-cn";
|
||||
};
|
||||
"qwen3.7-max": Model<"openai-completions"> & {
|
||||
id: "qwen3.7-max";
|
||||
provider: "qwen-token-plan-cn";
|
||||
};
|
||||
"qwen3.7-plus": Model<"openai-completions"> & {
|
||||
id: "qwen3.7-plus";
|
||||
provider: "qwen-token-plan-cn";
|
||||
};
|
||||
"qwen3.8-max-preview": Model<"openai-completions"> & {
|
||||
id: "qwen3.8-max-preview";
|
||||
provider: "qwen-token-plan-cn";
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,15 @@
|
||||
import { openAICompletionsApi } from "../api/openai-completions.lazy.ts";
|
||||
import { envApiKeyAuth } from "../auth/helpers.ts";
|
||||
import { createProvider, type Provider } from "../models.ts";
|
||||
import { QWEN_TOKEN_PLAN_CN_MODELS } from "./qwen-token-plan-cn.models.ts";
|
||||
|
||||
export function qwenTokenPlanCnProvider(): Provider<"openai-completions"> {
|
||||
return createProvider({
|
||||
id: "qwen-token-plan-cn",
|
||||
name: "Qwen Token Plan CN",
|
||||
baseUrl: "https://token-plan.cn-beijing.maas.aliyuncs.com/compatible-mode/v1",
|
||||
auth: { apiKey: envApiKeyAuth("Qwen Token Plan CN API key", ["QWEN_TOKEN_PLAN_CN_API_KEY"]) },
|
||||
models: Object.values(QWEN_TOKEN_PLAN_CN_MODELS),
|
||||
api: openAICompletionsApi(),
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
// This file is auto-generated by scripts/generate-models.ts
|
||||
// Do not edit manually - run 'npm run generate-models' to update
|
||||
|
||||
import values from "./data/qwen-token-plan.json" with { type: "json" };
|
||||
import type { Model } from "../types.ts";
|
||||
|
||||
export const QWEN_TOKEN_PLAN_MODELS = values as {
|
||||
"MiniMax-M2.5": Model<"openai-completions"> & {
|
||||
id: "MiniMax-M2.5";
|
||||
provider: "qwen-token-plan";
|
||||
};
|
||||
"deepseek-v3.2": Model<"openai-completions"> & {
|
||||
id: "deepseek-v3.2";
|
||||
provider: "qwen-token-plan";
|
||||
};
|
||||
"deepseek-v4-flash": Model<"openai-completions"> & {
|
||||
id: "deepseek-v4-flash";
|
||||
provider: "qwen-token-plan";
|
||||
};
|
||||
"deepseek-v4-pro": Model<"openai-completions"> & {
|
||||
id: "deepseek-v4-pro";
|
||||
provider: "qwen-token-plan";
|
||||
};
|
||||
"glm-5": Model<"openai-completions"> & {
|
||||
id: "glm-5";
|
||||
provider: "qwen-token-plan";
|
||||
};
|
||||
"glm-5.1": Model<"openai-completions"> & {
|
||||
id: "glm-5.1";
|
||||
provider: "qwen-token-plan";
|
||||
};
|
||||
"glm-5.2": Model<"openai-completions"> & {
|
||||
id: "glm-5.2";
|
||||
provider: "qwen-token-plan";
|
||||
};
|
||||
"kimi-k2.5": Model<"openai-completions"> & {
|
||||
id: "kimi-k2.5";
|
||||
provider: "qwen-token-plan";
|
||||
};
|
||||
"kimi-k2.6": Model<"openai-completions"> & {
|
||||
id: "kimi-k2.6";
|
||||
provider: "qwen-token-plan";
|
||||
};
|
||||
"kimi-k2.7-code": Model<"openai-completions"> & {
|
||||
id: "kimi-k2.7-code";
|
||||
provider: "qwen-token-plan";
|
||||
};
|
||||
"qwen3.6-flash": Model<"openai-completions"> & {
|
||||
id: "qwen3.6-flash";
|
||||
provider: "qwen-token-plan";
|
||||
};
|
||||
"qwen3.6-plus": Model<"openai-completions"> & {
|
||||
id: "qwen3.6-plus";
|
||||
provider: "qwen-token-plan";
|
||||
};
|
||||
"qwen3.7-max": Model<"openai-completions"> & {
|
||||
id: "qwen3.7-max";
|
||||
provider: "qwen-token-plan";
|
||||
};
|
||||
"qwen3.7-plus": Model<"openai-completions"> & {
|
||||
id: "qwen3.7-plus";
|
||||
provider: "qwen-token-plan";
|
||||
};
|
||||
"qwen3.8-max-preview": Model<"openai-completions"> & {
|
||||
id: "qwen3.8-max-preview";
|
||||
provider: "qwen-token-plan";
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,15 @@
|
||||
import { openAICompletionsApi } from "../api/openai-completions.lazy.ts";
|
||||
import { envApiKeyAuth } from "../auth/helpers.ts";
|
||||
import { createProvider, type Provider } from "../models.ts";
|
||||
import { QWEN_TOKEN_PLAN_MODELS } from "./qwen-token-plan.models.ts";
|
||||
|
||||
export function qwenTokenPlanProvider(): Provider<"openai-completions"> {
|
||||
return createProvider({
|
||||
id: "qwen-token-plan",
|
||||
name: "Qwen Token Plan",
|
||||
baseUrl: "https://token-plan.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1",
|
||||
auth: { apiKey: envApiKeyAuth("Qwen Token Plan API key", ["QWEN_TOKEN_PLAN_API_KEY"]) },
|
||||
models: Object.values(QWEN_TOKEN_PLAN_MODELS),
|
||||
api: openAICompletionsApi(),
|
||||
});
|
||||
}
|
||||
@@ -64,6 +64,8 @@ export type KnownProvider =
|
||||
| "kimi-coding"
|
||||
| "cloudflare-workers-ai"
|
||||
| "cloudflare-ai-gateway"
|
||||
| "qwen-token-plan"
|
||||
| "qwen-token-plan-cn"
|
||||
| "xiaomi"
|
||||
| "xiaomi-token-plan-cn"
|
||||
| "xiaomi-token-plan-ams"
|
||||
|
||||
@@ -31,6 +31,7 @@ import type { AssistantMessage } from "../types.ts";
|
||||
* - Xiaomi MiMo: Truncates input to fill contextWindow exactly, then returns finish_reason "length"
|
||||
* with output=0 (no room left to generate). Detected via stopReason "length" + zero output +
|
||||
* input filling the context window.
|
||||
* - DashScope/Qwen: "Range of input length should be [1, X]" (HTTP 400 invalid_parameter_error)
|
||||
* - Ollama: Some deployments truncate silently, others return errors like "prompt too long; exceeded max context length by X tokens"
|
||||
*/
|
||||
const OVERFLOW_PATTERNS = [
|
||||
@@ -54,6 +55,7 @@ const OVERFLOW_PATTERNS = [
|
||||
/prompt has [\d,]+ tokens?, but the configured context size is [\d,]+ tokens?/i, // DS4 server
|
||||
/model_context_window_exceeded/i, // z.ai non-standard finish_reason surfaced as error text
|
||||
/prompt too long; exceeded (?:max )?context length/i, // Ollama explicit overflow error
|
||||
/range of input length should be/i, // DashScope / Qwen Token Plan
|
||||
/context[_ ]length[_ ]exceeded/i, // Generic fallback
|
||||
/too many tokens/i, // Generic fallback
|
||||
/token limit exceeded/i, // Generic fallback
|
||||
@@ -101,6 +103,7 @@ const NON_OVERFLOW_PATTERNS = [
|
||||
* - LM Studio: "greater than the context length"
|
||||
* - Kimi For Coding: "exceeded model token limit: X (requested: Y)"
|
||||
* - DS4: "Prompt has X tokens, but the configured context size is Y tokens"
|
||||
* - DashScope/Qwen: "Range of input length should be [1, X]"
|
||||
*
|
||||
* **Unreliable detection:**
|
||||
* - z.ai: Sometimes accepts overflow silently (detectable via usage.input > contextWindow),
|
||||
|
||||
Reference in New Issue
Block a user