The Agents SDK includes model providers for Workers AI and AI Gateway. Each provider is one createAI factory over the Worker's AI binding. There are two, one per framework:
| Import | Framework | Use it with |
|---|---|---|
agents/models/ai-sdk |
AI SDK ↗︎ v7 | generateText, streamText, Think, and any AI SDK consumer |
agents/models/pi-ai |
Pi AI ↗︎ | The Pi harness, and Pi AI's stream |
Both take the same options, route through the same gateway, and handle Workers AI the same way.
The providers keep one model catalog up to date: Workers AI. Every other vendor's models come from that vendor's own package, and the provider routes them through AI Gateway.
- A Workers AI model is a
@cf/id, such asai("@cf/zai-org/glm-4.7-flash"). It runs throughenv.AI.run(). A compatibility layer turns each model's response into the standard OpenAI chat completions shape. - A third-party model is a model object built by the vendor's provider, such as
ai(anthropic("claude-opus-4-8")). The vendor's code builds the request and parses the response. The provider swaps the transport, so the request goes through AI Gateway withenv.AI.gateway(id).run().
The provider does not keep third-party model ids, wire formats, or thinking settings. When a vendor ships a new model, update the vendor's package.
- No API tokens in your Worker. Requests go through the
AIbinding. AI Gateway holds third-party credentials, through Unified Billing or a key you store on the gateway. - Gateway options. Caching, logging, metadata, timeouts, and retries are options on the provider, the model, or the call. The
defaultgateway is created the first time you use it. - Fallback. List models to try in order if the first fails before it produces output. Mix Workers AI and third-party models freely.
- Gateway metadata on every result. Each response carries the gateway log id, cache status, and the model that actually answered.
Both providers need the AI binding:
{
"ai": {
"binding": "AI",
},
}[ai]
binding = "AI"AI SDK
A full AI SDK ProviderV4 for text, tools, structured output, embeddings, images, speech, transcription, and reranking.
Pi AI
Pi AI models for the Pi harness, Pi Durable, and any framework built on a Pi AI Models registry.