AI Gateway 统一 Fast Mode,跨模型兼容切换
Vercel AI Gateway 推出统一的 fast mode 抽象,开发者可用一致 API 在所有模型间切换快速推理,自动兼容降级。
完整中文译文
AI Gateway 推出了统一的 fast mode 抽象,目前处于测试阶段。
现在你可以对 AI Gateway 上的每个模型以相同的方式请求 fast mode。设置 speed 为 fast,网关会在可用时提供 fast 层,否则降级为标准速度。
Fast mode 用较高的单 token 成本换取更低的延迟或更高的吞吐量。无论在哪个可用位置,你都能获得它,无需绑定特定供应商或自行配置。
请求 fast mode
在 providerOptions.gateway 下设置 speed 为 fast,将模型升级到其 fast 服务路径(如果可路由的话):
1import { generateText } from 'ai';2
3const { text, providerMetadata } = await generateText({4 model: 'anthropic/claude-opus-5',5 prompt: 'Explain quantum computing in two sentences.',6 providerOptions: {7 gateway: {8 speed: 'fast',9 },10 },11});12console.log('Served speed:', providerMetadata?.gateway?.routing?.speed);
你也可以直接通过其 fast slug 来指向一个 fast 变体,比如 anthropic/claude-opus-5-fast,这与在基础模型上设置 speed: 'fast' 的效果相同。
当你想保留基础模型 ID 并支持降级到标准速度时,使用 speed 选项。当你想直接指定 fast 变体时使用 fast slug,比如在 gateway.models 降级列表中。speed 选项在所有 AI Gateway API 格式中都适用。
Fast mode 适用于越来越多的模型。在模型列表中,slug 旁有闪电图标的就是支持 fast mode 的模型。对没有 fast 层的模型请求 fast mode 无效,请求将以标准速度运行。模型的 fast 变体通常比基础模型更昂贵:查看价格获取更多详情。
在编码 agent 中使用 fast mode
在 Claude Code 中,设置后可使用 /fast 命令为 Anthropic Opus 模型切换 fast mode。对于其他 agent,在你的模型配置中选择一个 fast slug,比如 anthropic/claude-opus-5-fast。
关于 fast mode 的更多信息,请阅读文档。