One createAI to Rule Them All: workers-ai-provider and ai-gateway-provider Retire
Hi everyone, Shii-chan here! The way you call AI models from the Agents SDK just got a lot tidier, so let's go through it.
Cloudflare ChangelogWhat was announced?
The Cloudflare Changelog announced a new createAI function in the Agents SDK for the AI SDK and Pi AI. It unifies what workers-ai-provider and ai-gateway-provider used to do.
The story so far
Until now the job was split across packages:
workers-ai-providerfor Workers AI modelsai-gateway-providerfor AI Gateway
Both are now feature frozen and deprecated. You can migrate at your convenience.
What changes
There is now a single entry point, createAI, so switching models and configuring fallbacks gets simpler. You can use everything from Workers AI models to other vendors' models in the same way.
Dive Deep
Install the agents package. The example from the changelog looks like this:
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();
},
};
With createAI you get:
- Every model by id: Workers AI
@cf/ids, any model in the AI Gateway catalog, and dynamic routes asdynamic/{route} - Vendor model objects: pass a model from the vendor's own package and it is sent unchanged to AI Gateway's provider-native endpoint
- Flexible connection: use the binding, or an account id and API token to reach a gateway in another account or call from outside a Worker
- Gateway options: caching, logging, metadata, retries, BYOK alias, zero data retention, and vendor key settings
- Fallbacks: specify a list of fallback models
- Stream resume: with the binding, a catalog or dynamic route stream that drops mid-answer can resume
- Other model types: embeddings, images, speech, transcription, and reranking in the AI SDK provider, and images in Pi AI
Migration at a glance:
createWorkersAI({ binding })becomescreateAI({ binding })createWorkersAI({ accountId, apiKey })becomescreateAI({ accountId, apiToken })(the credential option is renamed toapiToken)createAiGateway(...)becomescreateAI(...), with fallbacks given as a listcreateAISearchfromworkers-ai-provideris replaced bycreateAISearchNamespacefromai-search-provider
Wrap-up
createAIin the Agents SDK unifies Workers AI, AI Gateway, dynamic routes, and vendor modelsworkers-ai-providerandai-gateway-providerare feature frozen and deprecated- Fallbacks, stream resume, and Gateway options come along too
- Migration is mostly renaming the function and a few options (
apiKeytoapiToken)
If you juggle several models or gateways on Workers, this one's for you!