文章把模型目录视为部署依赖,通过清单检查模型名称、价格、上下文窗口和弃用状态,并在假设过期时阻断构建。示例面向兼容 OpenAI API 的中国模型网关,但部分数据依赖第三方价格页。
中国大模型 API 的变化速度非常快,硬编码模型名称已经成为一种生产风险。问题不只是模型质量会发生变化,还包括计费方式漂移、上下文窗口变化、模型弃用,以及在各种 OpenAI 兼容客户端中出现的集成差异。
如果你正在运营一项 SaaS 功能、内部编码 Agent,或客服自动化流水线,就应该像对待其他部署时依赖一样对待模型目录:锁定版本、检查内容、设置预算,并在相关假设已经过时时让构建失败。
本文将围绕 AIWave 定价页面构建一个小型 manifest 检查工具,然后在指向 https://aiwave.live/v1 的 OpenAI 兼容客户端中使用该 manifest。AIWave 是一个部署在新加坡的中国 AI 模型网关,只需一个 API key,即可调用多个模型。目前,它通过实时定价页面的 API 提供价格数据;撰写本文时,我于 2026-08-04 获取了这些数据,并根据页面当前的 model_ratio 和 completion_ratio 字段计算出美元价格。
不要将 API key 提交到源代码版本控制中。下文所有代码示例均使用 YOUR_API_KEY_HERE 作为占位符。
官方模型目录并非一成不变。DeepSeek 的 API changelog 记录了向 V4 过渡的过程,以及 deepseek-chat 和 deepseek-reasoner 的别名行为。Moonshot 的 Kimi 模型列表指出,旧版 kimi-k2 模型应迁移至 kimi-k2.6。Qwen 的公开仓库持续记录 Qwen3 和 Qwen3-Coder 2507 的频繁更新。Z.AI 的 release notes 显示,GLM-4.5 于 2025-07-28 发布,GLM-5.1 于 2026-04-07 发布。MiniMax 的模型 release notes 则记录了 2026 年 2 月发布的 M2.5,以及于 2026-03-18 发布的 M2.7。
这些变化会切实影响日常工程工作:
模型别名可能已经指向与上个月不同的后端;
更便宜的模型也许适合分类任务,却不适合 Agent 式编码;
cache 通道可能改变长 prompt 的成本结构;
网关可能已经开放某个模型,但你的应用尚未为它配置重试和预算策略。
安全的做法其实很朴素:将模型列表视为运行时数据,而不是应用中的常量。
数据来源:位于 https://aiwave.live/pricing 背后的 AIWave 实时定价 API,获取时间为 2026-08-04。页面共返回 62 个模型。下文中的输入价格等于 model_ratio * 2,输出价格等于 input_price * completion_ratio。所有数值的单位均为美元/100 万 tokens。
对于一个包含 1000 万输入 tokens 和 200 万输出 tokens 的简单工作负载估算:
这不是 benchmark,只是计费计算。延迟、工具可靠性、上下文行为和输出质量,仍然需要你自行评估。
该脚本读取公开的定价 JSON,计算输入与输出价格,并生成一个精简的模型 manifest。如果缺少任何必需模型,它会以非零状态码退出,因此很适合在 CI 中使用。
#!/usr/bin/env python3
import json
import sys
from datetime import date
from urllib.request import Request, urlopen
PRICING_URL = "https://aiwave.live/api/pricing"
REQUIRED_MODELS = {
"qwen3-235b-a22b-thinking-2507",
"deepseek-r1",
"glm-4.5",
"kimi-k2.6",
}
def fetch_json(url: str) -> dict:
req = Request(url, headers={"User-Agent": "model-manifest-ci/1.0"})
with urlopen(req, timeout=20) as response:
if response.status != 200:
raise RuntimeError(f"pricing API returned HTTP {response.status}")
return json.loads(response.read().decode("utf-8"))
def to_price(row: dict) -> dict:
input_price = float(row["model_ratio"]) * 2
output_price = input_price * float(row.get("completion_ratio", 1))
cache_ratio = row.get("cache_ratio")
cache_read = input_price * float(cache_ratio) if cache_ratio is not None else None
return {
"model": row["model_name"],
"input_usd_per_1m": round(input_price, 6),
"output_usd_per_1m": round(output_price, 6),
"cache_read_usd_per_1m": None if cache_read is None else round(cache_read, 6),
}
payload = fetch_json(PRICING_URL)
manifest = {item["model"]: item for item in map(to_price, payload["data"])}
missing = sorted(REQUIRED_MODELS - set(manifest))
if missing:
print(f"Missing required models: {', '.join(missing)}", file=sys.stderr)
sys.exit(1)
result = {
"source": PRICING_URL,
"verified_on": date.today().isoformat(),
"model_count": len(manifest),
"models": {name: manifest[name] for name in sorted(REQUIRED_MODELS)},
}
print(json.dumps(result, indent=2, sort_keys=True))
在部署流水线中,应将生成的 JSON 保存为构建产物。当某个模型消失、输出价格发生显著变化,或某个此前没有 cache 通道的模型新增了该通道时,都应对其进行审查。
模型路由器不应该凭感觉做决定。应该向它提供成本上限、工作负载类型,以及最新的 manifest。下面的 JavaScript 示例使用 OpenAI SDK,并将 base URL 指向 AIWave 的 OpenAI 兼容地址。
import OpenAI from "openai";
const client = new OpenAI({
apiKey: "YOUR_API_KEY_HERE",
baseURL: "https://aiwave.live/v1",
});
const models = {
"qwen3-235b-a22b-thinking-2507": {
inputUsdPer1m: 0.342466,
outputUsdPer1m: 3.42466,
useFor: ["reasoning", "long_context"],
},
"glm-4.5": {
inputUsdPer1m: 0.6975,
outputUsdPer1m: 2.17,
useFor: ["tools", "structured_output"],
},
"kimi-k2.6": {
inputUsdPer1m: 1.09,
outputUsdPer1m: 4.5998,
useFor: ["agentic_coding", "large_context"],
},
};
function estimateUsd(model, inputTokens, outputTokens) {
const m = models[model];
return (
(inputTokens / 1_000_000) * m.inputUsdPer1m +
(outputTokens / 1_000_000) * m.outputUsdPer1m
);
}
function chooseModel(task, inputTokens, expectedOutputTokens, maxUsd) {
const candidates = Object.entries(models)
.filter(([, spec]) => spec.useFor.includes(task))
.map(([name]) => ({
name,
estimatedUsd: estimateUsd(name, inputTokens, expectedOutputTokens),
}))
.filter((row) => row.estimatedUsd <= maxUsd)
.sort((a, b) => a.estimatedUsd - b.estimatedUsd);
if (candidates.length === 0) {
throw new Error(`No model fits budget for ${task}`);
}
return candidates[0].name;
}
const model = chooseModel("structured_output", 25_000, 1_200, 0.05);
const response = await client.chat.completions.create({
model,
messages: [
{ role: "system", content: "Return compact JSON only." },
{ role: "user", content: "Extract company, role, and required skills from this job post: ..." },
],
response_format: { type: "json_object" },
});
console.log(response.choices[0].message.content);
如果 manifest 由 CI 生成,可以将它保存在应用仓库中,但绝不能提交 API key。在生产环境中,应从 secret manager 或部署环境中读取 key。
预算检查应该在 API 调用之前执行。这样能够提供可预测的失败模式,并避免用户提供的一份文档意外产生高额账单。
from dataclasses import dataclass
@dataclass(frozen=True)
class Price:
input_usd_per_1m: float
output_usd_per_1m: float
PRICES = {
"glm-4.5": Price(input_usd_per_1m=0.6975, output_usd_per_1m=2.17),
"kimi-k2.6": Price(input_usd_per_1m=1.09, output_usd_per_1m=4.5998),
"deepseek-r1": Price(input_usd_per_1m=0.605, output_usd_per_1m=2.409),
}
def estimate_cost(model: str, input_tokens: int, max_output_tokens: int) -> float:
price = PRICES[model]
return (
input_tokens / 1_000_000 * price.input_usd_per_1m
+ max_output_tokens / 1_000_000 * price.output_usd_per_1m
)
def enforce_budget(model: str, input_tokens: int, max_output_tokens: int, limit_usd: float) -> None:
estimated = estimate_cost(model, input_tokens, max_output_tokens)
if estimated > limit_usd:
raise ValueError(
f"{model} estimate ${estimated:.4f} exceeds request budget ${limit_usd:.4f}"
)
enforce_budget("glm-4.5", input_tokens=80_000, max_output_tokens=4_000, limit_usd=0.10)
print("request is inside budget")
这种做法有意采用了较为保守的估算,因为它使用的是 max_output_tokens。如果模型提前停止,实际账单应该会更低。如果 tokenizer 的估算不够准确,应增加安全余量,而不是假设 token 计数绝对精确。
模型路由应该明确记录在日志中。记录所选模型、预估输入 tokens、最大输出 tokens、预估美元成本、重试次数和失败原因。除非你已经为相关数据制定隐私政策和留存流程,否则不要记录原始 prompt。
对于欧盟或英国用户,应将区域控制与模型选择分开处理。部署在新加坡服务器上的网关可能有助于改善延迟和整合调用,但是否符合 GDPR 要求,仍取决于你自己的数据处理协议、数据留存政策、子处理方、用户数据删除流程,以及 prompt 中是否包含个人数据。
同样也应该坦诚说明其缺点。网关会在应用与模型供应商之间增加一层依赖。某些供应商特有的功能,可能比原生 API 晚一些得到支持。定价页面的更新速度也可能快于文档。manifest 检查正是为此而存在。
对于许多 chat-completion 工作负载来说,可以:将 base_url 或 baseURL 设置为 https://aiwave.live/v1,并继续使用 OpenAI SDK。但你仍然需要测试具体模型的行为、tool calling、JSON mode、streaming 和 token 限制。
不应该。先用表格设定预算,再针对自己的任务做 benchmark。客服分类器、代码编辑 Agent 和长上下文法律审查任务,各自的失败成本并不相同。
对于原型项目,硬编码完全没问题。生产系统通常需要准备 fallback,以应对模型不可用、被弃用、响应速度低于预期,或超出单次请求预算等情况。
阅读 AIWave API 文档,在 AIWave pricing 页面核实最新价格,在 CI 中生成 manifest,并确保 YOUR_API_KEY_HERE 不会被提交到 git。
AIWave 定价页面与实时定价 API,获取时间为 2026-08-04。
DeepSeek API changelog:https://api-docs.deepseek.com/updates。
Moonshot Kimi 模型列表:https://platform.kimi.ai/docs/models。
Qwen3-Coder 官方博客与 Qwen3 仓库新闻:https://qwenlm.github.io/blog/qwen3-coder/ 和 https://github.com/QwenLM/Qwen3。
Z.AI release notes 与定价文档:https://docs.z.ai/release-notes/new-released 和 https://docs.z.ai/guides/overview/pricing。
MiniMax release notes:https://platform.minimax.io/docs/release-notes/models。
如需采取进一步措施,你可以考虑屏蔽此人和/或举报滥用行为。