Create each key on its own page, paste it below, then copy the finished lines into your project's .env file. What you paste stays in this tab. It is never sent to Wirestack or saved.
Cloudflare Workers AI Account IDCLOUDFLARE_ACCOUNT_IDGet key
Click Use REST API. Your Account ID is shown there
Cloudflare Workers AI API tokenCLOUDFLARE_API_TOKENGet key
Click Use REST API, then Create a Workers AI API Token
On October 21, 2026 Cloudflare added createAI to the Agents SDK. One function now reaches Workers AI models, AI Gateway catalog models, dynamic routes and other vendors' models from the Vercel AI SDK. It supports fallback models, BYOK and resuming a stream.
The old workers-ai-provider and ai-gateway-provider packages are feature frozen and deprecated. They still work, and Cloudflare asks you to move over when it suits you.
Prerequisites
A Cloudflare Worker with the AI binding, or your Account ID in CLOUDFLARE_ACCOUNT_ID and a Workers AI API token in CLOUDFLARE_API_TOKEN
An AI Gateway, if you want to route through one
The Vercel AI SDK (ai package)
Steps
Install the package: npm i agents
Replace the import from workers-ai-provider or ai-gateway-provider with import { createAI } from "agents/models/ai-sdk";
Create the provider with createAI({ binding: env.AI, id: "my-gateway" }) and pass a model name to it.
If you used createAISearch from workers-ai-provider, switch to createAISearchNamespace from the ai-search-provider package.
Test it
JavaScript
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(); },};
Deploy the Worker and open its URL: you should see the haiku stream in.
Not confirmed
Cloudflare gives no date when the old packages will be removed.