Agents, Workers AI, AI Gateway - createAI replaces workers-ai-provider and ai-gateway-provider
- Announced
- Tags
- Agents, Workers-AI, AI-Gateway
- Severity
- info, set by
reef/rss-rule-v1 - Source
- https://developers.cloudflare.com/changelog/post/2026-10-21-createai/
<p>The Agents SDK has a new <a href="https://developers.cloudflare.com/agents/models/"><code>createAI</code></a> function for the <a href="https://developers.cloudflare.com/agents/models/ai-sdk/">AI SDK</a> and <a href="https://developers.cloudflare.com/agents/models/pi-ai/">Pi AI</a>. It unifies what <code>workers-ai-provider</code> and <code>ai-gateway-provider</code> did: Workers AI models, AI Gateway catalog models, dynamic routes, and vendor models, through the <code>AI</code> binding or an account id and API token.</p> <p><code>workers-ai-provider</code> and <code>ai-gateway-provider</code> are now feature frozen and marked as deprecated. Please migrate at your convenience.</p> <figure class="nb-code-figure" data-nb-lang="sh"><pre class="astro-code astro-code-themes github-light github-dark nb-shiki-c6xiwz" tabindex="0" data-language="sh" data-nb-lang="sh"><code><span class="line"><span class="nb-shiki-1t8gfj">npm</span><span class="nb-shiki-mdbnqw"> i</span><span class="nb-shiki-mdbnqw"> agents</span></span></code></pre></figure> <div><div data-nb-tabs data-nb-sync-key="workersExamples" class><div class="relative flex border-b border-border" role="tablist" data-nb-tabs-list><span class="bg-primary pointer-events-none absolute -bottom-px h-0.5 rounded-t-sm transition-[left,width] duration-200 ease-out" data-nb-tabs-indicator aria-hidden="true"></span></div><div class="mt-3"><div role="tabpanel" data-nb-tabs-content data-nb-tab-label="JavaScript" class><figure class="nb-code-figure" data-nb-lang="js"><pre class="astro-code astro-code-themes github-light github-dark nb-shiki-c6xiwz" tabindex="0" data-language="js" data-nb-lang="js"><code><span class="line"><span class="nb-shiki-1itgoe">import</span><span class="nb-shiki-140thh"> { createAI } </span><span class="nb-shiki-1itgoe">from</span><span class="nb-shiki-mdbnqw"> "agents/models/ai-sdk"</span><span class="nb-shiki-140thh">;</span></span> <span class="line"><span class="nb-shiki-1itgoe">import</span><span class="nb-shiki-140thh"> { streamText } </span><span class="nb-shiki-1itgoe">from</span><span class="nb-shiki-mdbnqw"> "ai"</span><span class="nb-shiki-140thh">;</span></span> <span class="line"></span> <span class="line"><span class="nb-shiki-1itgoe">export</span><span class="nb-shiki-1itgoe"> default</span><span class="nb-shiki-140thh"> {</span></span> <span class="line"><span class="nb-shiki-1itgoe"> async</span><span class="nb-shiki-1t8gfj"> fetch</span><span class="nb-shiki-140thh">(</span><span class="nb-shiki-1jdh33">request</span><span class="nb-shiki-140thh">, </span><span class="nb-shiki-1jdh33">env</span><span class="nb-shiki-140thh">) {</span></span> <span class="line"><span class="nb-shiki-1itgoe"> const</span><span class="nb-shiki-dzsirb"> ai</span><span class="nb-shiki-1itgoe"> =</span><span class="nb-shiki-1t8gfj"> createAI</span><span class="nb-shiki-140thh">({ binding: env.</span><span class="nb-shiki-dzsirb">AI</span><span class="nb-shiki-140thh">, id: </span><span class="nb-shiki-mdbnqw">"my-gateway"</span><span class="nb-shiki-140thh"> });</span></span> <span class="line"></span> <span class="line"><span class="nb-shiki-1itgoe"> const</span><span class="nb-shiki-dzsirb"> result</span><span class="nb-shiki-1itgoe"> =</span><span class="nb-shiki-1t8gfj"> streamText</span><span class="nb-shiki-140thh">({</span></span> <span class="line"><span class="nb-shiki-140thh"> model: </span><span class="nb-shiki-1t8gfj">ai</span><span class="nb-shiki-140thh">(</span><span class="nb-shiki-mdbnqw">"anthropic/claude-opus-5.5"</span><span class="nb-shiki-140thh">, {</span></span> <span class="line"><span class="nb-shiki-140thh"> fallback: [</span><span class="nb-shiki-mdbnqw">"@cf/zai-org/glm-4.7-flash"</span><span class="nb-shiki-140thh">],</span></span> <span class="line"><span class="nb-shiki-140thh"> }),</span></span> <span class="line"><span class="nb-shiki-140thh"> prompt: </span><span class="nb-shiki-mdbnqw">"Write a haiku about Durable Objects"</span><span class="nb-shiki-140thh">,</span></span> <span class="line"><span class="nb-shiki-140thh"> });</span></span> <span class="line"></span> <span class="line"><span class="nb-shiki-1itgoe"> return</span><span class="nb-shiki-140thh"> result.</span><span class="nb-shiki-1t8gfj">toTextStreamResponse</span><span class="nb-shiki-140thh">();</span></span> <span class="line"><span class="nb-shiki-140thh"> },</span></span> <span class="line"><span class="nb-shiki-140thh">};</span></span></code></pre></figure></div><div role="tabpanel" data-nb-tabs-content data-nb-tab-label="TypeScript" class><figure class="nb-code-figure" data-nb-lang="ts"><pre class="astro-code astro-code-themes github-light github-dark nb-shiki-c6xiwz" tabindex="0" data-language="ts" data-nb-lang="ts"><code><span class="line"><span class="nb-shiki-1itgoe">import</span><span class="nb-shiki-140thh"> { createAI } </span><span class="nb-shiki-1itgoe">from</span><span class="nb-shiki-mdbnqw"> "agents/models/ai-sdk"</span><span class="nb-shiki-140thh">;</span></span> <span class="line"><span class="nb-shiki-1itgoe">import</span><span class="nb-shiki-140thh"> { streamText } </span><span class="nb-shiki-1itgoe">from</span><span class="nb-shiki-mdbnqw"> "ai"</span><span class="nb-shiki-140thh">;</span></span> <span class="line"></span> <span class="line"><span class="nb-shiki-1itgoe">export</span><span class="nb-shiki-1itgoe"> default</span><span class="nb-shiki-140thh"> {</span></span> <span class="line"><span class="nb-shiki-1itgoe"> async</span><span class="nb-shiki-1t8gfj"> fetch</span><span class="nb-shiki-140thh">(</span><span class="nb-shiki-1jdh33">request</span><span class="nb-shiki-1itgoe">:</span><span class="nb-shiki-1t8gfj"> Request</span><span class="nb-shiki-140thh">, </span><span class="nb-shiki-1jdh33">env</span><span class="nb-shiki-1itgoe">:</span><span class="nb-shiki-1t8gfj"> Env</span><span class="nb-shiki-140thh">) {</span></span> <span class="line"><span class="nb-shiki-1itgoe"> const</span><span class="nb-shiki-dzsirb"> ai</span><span class="nb-shiki-1itgoe"> =</span><span class="nb-shiki-1t8gfj"> createAI</span><span class="nb-shiki-140thh">({ binding: env.</span><span class="nb-shiki-dzsirb">AI</span><span class="nb-shiki-140thh">, id: </span><span class="nb-shiki-mdbnqw">"my-gateway"</span><span class="nb-shiki-140thh"> });</span></span> <span class="line"></span> <span class="line"><span class="nb-shiki-1itgoe"> const</span><span class="nb-shiki-dzsirb"> result</span><span class="nb-shiki-1itgoe"> =</span><span class="nb-shiki-1t8gfj"> streamText</span><span class="nb-shiki-140thh">({</span></span> <span class="line"><span class="nb-shiki-140thh"> model: </span><span class="nb-shiki-1t8gfj">ai</span><span class="nb-shiki-140thh">(</span><span class="nb-shiki-mdbnqw">"anthropic/claude-opus-5.5"</span><span class="nb-shiki-140thh">, {</span></span> <span class="line"><span class="nb-shiki-140thh"> fallback: [</span><span class="nb-shiki-mdbnqw">"@cf/zai-org/glm-4.7-flash"</span><span class="nb-shiki-140thh">],</span></span> <span class="line"><span class="nb-shiki-140thh"> }),</span></span> <span class="line"><span class="nb-shiki-140thh"> prompt: </span><span class="nb-shiki-mdbnqw">"Write a haiku about Durable Objects"</span><span class="nb-shiki-140thh">,</span></span> <span class="line"><span class="nb-shiki-140thh"> });</span></span> <span class="line"></span> <span class="line"><span class="nb-shiki-1itgoe"> return</span><span class="nb-shiki-140thh"> result.</span><span class="nb-shiki-1t8gfj">toTextStreamResponse</span><span class="nb-shiki-140thh">();</span></span> <span class="line"><span class="nb-shiki-140thh"> },</span></span> <span class="line"><span class="nb-shiki-140thh">};</span></span></code></pre></figure></div></div></div><script type="module" src="https://developers.cloudflare.com/home/runner/work/cloudflare-docs/cloudflare-docs/src/components/ui/tabs/Tabs.astro?astro&type=script&index=0&lang.ts"></script></div> <p>With <code>createAI</code> you get:</p> <ul> <li><strong>Every model by id.</strong> Workers AI <code>@cf/</code> ids, any model in the <a href="https://developers.cloudflare.com/ai/models/">AI Gateway catalog</a>, and <a href="https://developers.cloudflare.com/ai-gateway/features/dynamic-routing/">dynamic routes</a> as <code>dynamic/<route></code>.</li> <li><strong>Vendor model objects.</strong> Pass a model from the vendor's own package, such as <code>ai(anthropic("claude-opus-5-5"))</code>. It goes unchanged to AI Gateway's <a href="https://developers.cloudflare.com/ai-gateway/usage/providers/">provider-native endpoint</a>.</li> <li><strong>The binding, or an account id and API token.</strong> Use a gateway in another account, or call from outside a Worker.</li> <li><strong>Gateway options, fallback, and BYOK.</strong> Caching, logging, metadata, retries, <code>byokAlias</code>, <code>zdr</code>, and <code>vendorKey</code>.</li> <li><strong>Stream resume.</strong> Through the binding, a catalog or dynamic route stream that drops mid-answer resumes.</li> <li><strong>Other model types.</strong> Embeddings, images, speech, transcription, and reranking in the AI SDK provider, and images in Pi AI.</li> </ul> <div class="table-scroll" tabindex="0" role="region" aria-label="Table"><table> <thead> <tr> <th>Before</th> <th>After</th> </tr> </thead> <tbody> <tr> <td><code>createWorkersAI({ binding })</code></td> <td><code>createAI({ binding })</code></td> </tr> <tr> <td><code>createWorkersAI({ accountId, apiKey })</code></td> <td><code>createAI({ accountId, apiToken })</code></td> </tr> <tr> <td><code>createAiGateway(...)</code></td> <td><code>createAI(...)</code>, with <code>fallback</code> for a list of models</td> </tr> <tr> <td><code>createAISearch</code> from <code>workers-ai-provider</code></td> <td><code>createAISearchNamespace</code> from <code>ai-search-provider</code></td> </tr> </tbody> </table></div> <p>For AI Search, use <a href="https://developers.cloudflare.com/ai-search/agent-sdks/ai-sdk/"><code>ai-search-provider</code></a>. For more information, refer to <a href="https://developers.cloudflare.com/agents/models/">Models</a>.</p>
The text above is the source's. reef added the severity, the dates it could read from the text, and the endpoints and scopes named in code.