跳到主内容
@wquguru
精选85Cloudflare AI Gateway(Changelog)AI 编程与模型

Cloudflare 弃用 AI 提供商,引入 createAI 统一接入

Agents, Workers AI, AI Gateway - createAI replaces workers-ai-provider and ai-gateway-provider

原文
发到 X
推荐理由

核心依赖库弃用,影响现有集成代码。请检查项目中是否使用了 workers-ai-provider 或 ai-gateway-provider,并尽快按文档迁移至新的 createAI 接口,避免未来版本更新导致兼容性问题。

The Agents SDK has a new createAI function for the AI SDK and Pi AI. It unifies what workers-ai-provider and ai-gateway-provider did: Workers AI models, AI Gateway catalog models, dynamic routes, and vendor models, through the AI binding or an account id and API token.

Agents SDK 为 AI SDK 和 Pi AI 新增了 createAI 函数。它统一了 workers-ai-provider 和 ai-gateway-provider 的功能:通过 AI 绑定或账户 ID 与 API 令牌,提供 Workers AI 模型、AI Gateway 目录模型、动态路由以及供应商模型。

workers-ai-provider and ai-gateway-provider are now feature frozen and marked as deprecated. Please migrate at your convenience.

workers-ai-provider 和 ai-gateway-provider 现已功能冻结并标记为已弃用。请酌情进行迁移。

代码 · 1 行
npm i agents
代码 · 14 行
import { createAI } from "agents/models/ai-sdk";
import { streamText } from "ai";
export default {
	async fetch(request, env) {
		const ai = createAI({ binding: env.AI, id: "my-gateway" });
		const result = streamText({
			model: ai("anthropic/claude-opus-5.5", {
				fallback: ["@cf/zai-org/glm-4.7-flash"],
			}),
			prompt: "Write a haiku about Durable Objects",
		});
		return result.toTextStreamResponse();
	},
};
代码 · 14 行
import { createAI } from "agents/models/ai-sdk";
import { streamText } from "ai";
export default {
	async fetch(request: Request, env: Env) {
		const ai = createAI({ binding: env.AI, id: "my-gateway" });
		const result = streamText({
			model: ai("anthropic/claude-opus-5.5", {
				fallback: ["@cf/zai-org/glm-4.7-flash"],
			}),
			prompt: "Write a haiku about Durable Objects",
		});
		return result.toTextStreamResponse();
	},
};

With createAI you get:

使用 createAI 你可以获得:

  • Every model by id. Workers AI @cf/ ids, any model in the AI Gateway catalog, and dynamic routes as dynamic/<route>.
  • Vendor model objects. Pass a model from the vendor's own package, such as ai(anthropic("claude-opus-5-5")). It goes unchanged to AI Gateway's provider-native endpoint.
  • The binding, or an account id and API token. Use a gateway in another account, or call from outside a Worker.
  • Gateway options, fallback, and BYOK. Caching, logging, metadata, retries, byokAlias, zdr, and vendorKey.
  • Stream resume. Through the binding, a catalog or dynamic route stream that drops mid-answer resumes.
  • Other model types. Embeddings, images, speech, transcription, and reranking in the AI SDK provider, and images in Pi AI.
  • 按 ID 访问每个模型。Workers AI @cf/ ID、AI Gateway 目录中的任何模型,以及作为 dynamic/<route> 的动态路由。
  • 供应商模型对象。传递来自供应商自身包的模型,例如 ai(anthropic("claude-opus-5-5"))。它将原样传递至 AI Gateway 的提供商原生端点。
  • 绑定,或账户 ID 与 API 令牌。使用其他账户中的网关,或从 Worker 外部调用。
  • 网关选项、回退机制和 BYOK(自带密钥)。包括缓存、日志记录、元数据、重试、byokAlias、zdr 和 vendorKey。
  • 流式传输恢复。通过绑定、目录或动态路由,在回答中途断开的流式传输可恢复。
  • 其他模型类型。AI SDK 提供商支持嵌入、图像、语音、转录和重排序,Pi AI 支持图像。
BeforeAfter
createWorkersAI({ binding })createAI({ binding })
createWorkersAI({ accountId, apiKey })createAI({ accountId, apiToken })
createAiGateway(...)createAI(...), with fallback for a list of models
createAISearch from workers-ai-providercreateAISearchNamespace from ai-search-provider
BeforeAfter
createWorkersAI({ binding })createAI({ binding })
createWorkersAI({ accountId, apiKey })createAI({ accountId, apiToken })
createAiGateway(...)createAI(...), 带有模型列表的回退机制
createAISearch from workers-ai-providercreateAISearchNamespace from ai-search-provider

For AI Search, use ai-search-provider. For more information, refer to Models.

对于 AI Search,请使用 ai-search-provider。更多信息,请参阅 Models。

更进一步:量化金融体系

看懂新闻只是起点——沿量化金融路径,把它变成能交付的工程能力

进入量化体系 →

相似阅读

关联信息,但可能不是同一事件