最新资讯
dev.to 精简 MCP server 工具数量:更少工具、更小影响面,双重收益 dev.to 为什么 git checkout 无法撤销 AI 编码 agent 的改动? wechat AI短剧门槛降降降!实测即梦短剧工作室:剧本分镜预演一条龙,伙伴计划长期护航 dev.to 让模型改写文档前,先量化事实保真度 dev.to 回放 153 个 Claude Code 与 Codex 会话,审计 Agent 的生产影响范围 dev.to 银行 77 意图分类最便宜 LLM:GPT-6.1 Terra 每次成功任务 $0.000727 theinformation.com Chesky的副业:Airbnb向CEO新设AI实验室出售IP theverge.com OpenAI 宣布数据中心项目不再与公职人员签署保密协议 dev.to NVIDIA 发布四个开放 Cosmos 3 仿真模型 dev.to 真实 MCP 客户端击穿我们服务器的五种方式 theverge.com Airbnb 正在开发 AI 旅行 agent,计划 2027 年上半年推出 wechat 这可能是美国AI最魔幻的一天。
多元动态
登录 注册
智能体 developers.cloudflare.com · @Cloudflare Developers

Cloudflare Agents SDK 新增 createAI,统一 Workers AI 与 AI Gateway 接入

原文 我的收藏

Cloudflare 在 Agents SDK 中推出 createAI 函数,统一原先 workers-ai-provider 和 ai-gateway-provider 的能力,支持 Workers AI 模型、AI Gateway 目录模型、动态路由和厂商模型对象,并可通过 binding 或账号 ID 加 API token 调用;旧包已冻结并标记弃用,官方给出迁移对照表与示例代码。

AI推荐理由 Cloudflare 官方 changelog 给出明确的 API 变更:Agents SDK 新增 createAI,统一 workers-ai-provider 与 ai-gateway-provider,旧包冻结弃用,并附迁移对照表和代码示例,对使用 Workers AI/AI Gateway 的开发者有直接迁移价值;局限是仅为厂商文档更新,无性能或效果数据。

78

正文

The Agents SDK has a new [`createAI`](https://developers.cloudflare.com/agents/models/) function for the [AI SDK](https://developers.cloudflare.com/agents/models/ai-sdk/) and [Pi AI](https://developers.cloudflare.com/agents/models/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. `workers-ai-provider` and `ai-gateway-provider` are now feature frozen and marked as deprecated. Please migrate at your convenience. ``` npm i agents ``` ``` 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(); }, }; ``` ``` 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: * **Every model by id.** Workers AI `@cf/` ids, any model in the [AI Gateway catalog](https://developers.cloudflare.com/ai/models/), and [dynamic routes](https://developers.cloudflare.com/ai-gateway/features/dynamic-routing/) as `dynamic/`. * **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](https://developers.cloudflare.com/ai-gateway/usage/providers/). * **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. | Before | After | | --- | --- | | `createWorkersAI({ binding })` | `createAI({ binding })` | | `createWorkersAI({ accountId, apiKey })` | `createAI({ accountId, apiToken })` | | `createAiGateway(...)` | `createAI(...)`, with `fallback` for a list of models | | `createAISearch` from `workers-ai-provider` | `createAISearchNamespace` from `ai-search-provider` | For AI Search, use [`ai-search-provider`](https://developers.cloudflare.com/ai-search/agent-sdks/ai-sdk/). For more information, refer to [Models](https://developers.cloudflare.com/agents/models/).

来源报道 · 1 篇 · 以下链接均前往原始媒体

← 返回精选动态 原文

更多内容