Back

How to Run AI on Cloudflare Workers

Running AI inference at the edge with Cloudflare Workers AI — what models you get, how requests work, and when the edge beats a traditional server.

How to Run AI on Cloudflare Workers
Written by
BSH Technologies
Published on2026-04-06

How do you run AI on Cloudflare Workers?

Cloudflare Workers AI lets you call machine-learning models from a Worker that runs at the edge, close to your users, without managing any GPU or server. You bind the AI service to your Worker, send it a prompt or input, and get inference back — all inside Cloudflare's network, billed per request rather than per idle hour.

This matters because traditional AI hosting means renting a GPU box that costs money whether or not anyone is using it. Workers AI flips that to a serverless model: there is nothing to keep warm, it scales to zero, and your code already sits in hundreds of locations worldwide, so latency to the user is low.

What you can run at the edge

Workers AI ships a catalogue of ready models you invoke by name, covering the common needs of an AI feature.

  • Text generation with open large language models for chat, summarization and rewriting.
  • Embeddings for semantic search and retrieval, which pair naturally with Cloudflare's Vectorize vector database.
  • Image and vision tasks such as classification and captioning.
  • Speech to text for transcription workloads.

You do not download or host these models yourself. They run on Cloudflare's GPUs; your Worker just sends inputs and receives outputs, which keeps your code tiny and your deploy fast.

What a request looks like

The flow is deliberately simple. In your Worker you reference the bound AI service, pick a model by its identifier, and pass your input. The Worker awaits the result and returns it to the caller. Because Workers run on a request-response basis, you wire AI into an HTTP endpoint, a scheduled trigger or a queue consumer with the same few lines. Keys and bindings are configured in your Worker settings, so nothing sensitive ends up in client code. Pair Workers AI with KV for caching, R2 for file storage and Vectorize for embeddings, and you have an entire AI backend that never provisions a server.

When the edge beats a traditional server

Workers AI shines for short, stateless inference where low latency and scale-to-zero matter: a chat endpoint, an embedding generator behind search, a classification call inside a form. You pay per request, so a feature with spiky or low traffic costs almost nothing when idle, which is impossible with an always-on GPU instance.

It is less suited to very large frontier models, long-running multi-minute jobs, or workloads that need a specific framework and full control of the runtime. Workers have execution-time and memory limits, and you are choosing from the provided model catalogue rather than running arbitrary checkpoints. When you need that level of control, a dedicated GPU host or a managed inference service is the better fit — but for a great many AI features, the edge is faster to ship and cheaper to run.

Watch the limits and the cost model

Two things catch people out. The first is the execution and memory ceiling on a Worker: a single inference call is fine, but chaining several model calls or processing a large payload in one request can bump the limit, so push heavy or multi-step work onto a queue consumer rather than cramming it into one request. The second is billing. Workers AI is priced by usage measured in the units each model consumes, so a chatty endpoint without caching can cost more than you expect even though there is no idle charge. Put a cache in front of identical or near-identical requests and the per-request cost drops sharply, because the cheapest inference is the one you never run. Knowing both ceilings up front lets you design around them instead of discovering them in production.

A sensible edge AI architecture

A clean pattern: a Worker receives the request, checks KV for a cached answer, calls Workers AI on a miss, stores the result and responds. For search, generate embeddings with Workers AI, store them in Vectorize, and query Vectorize at request time to find relevant context before a generation call. This keeps the whole pipeline inside Cloudflare, with no origin server to maintain and no cold GPU to pay for.

Prefer it built and managed for you?

Edge AI is powerful but the right-fit decision — edge versus dedicated GPU — is easy to get wrong and expensive to undo. Talk to BSH Technologies and we will help you decide where your inference belongs and build it cleanly. Take a look at our cloud engineering services to see how we design serverless and edge architectures that stay cheap under real load.

Frequently asked questions

What is Cloudflare Workers AI?

It is a service that runs machine-learning models on Cloudflare GPUs, callable from a Worker at the edge. You bind the AI service to your Worker, send an input, and receive inference back. There is no GPU to manage, it scales to zero, and you are billed per request rather than per idle hour.

What models can I run on Workers AI?

Cloudflare provides a catalogue you invoke by name, including open large language models for text generation, embedding models for semantic search, image and vision models, and speech-to-text models. You do not host the models yourself; the Worker simply sends inputs and returns outputs from the provided catalogue.

When should I use edge AI instead of a server?

Use it for short, stateless inference where low latency and scale-to-zero matter, such as chat endpoints, embedding generation or classification. It is less suited to very large frontier models, multi-minute jobs, or workloads needing full runtime control, where a dedicated GPU host fits better.

How does Workers AI handle vector search?

It pairs with Vectorize, the Cloudflare vector database. You generate embeddings with Workers AI, store them in Vectorize, then query Vectorize at request time to find relevant context before a generation call. The whole retrieval pipeline stays inside Cloudflare with no separate database server to run.

Is Workers AI cheaper than running my own GPU?

For spiky or low-traffic features, usually yes, because you pay per request and nothing while idle. An always-on GPU instance bills whether or not it is used. For sustained, high-volume inference on large models, a dedicated GPU can become more economical, so it depends on your traffic shape.

Related Topics

#Cloudflare#Edge#AI

From the blog

View all posts
Apple Intelligence Is Coming to China With Alibaba's Qwen: Features, iOS 27.3 Dates, iPhones and the Catch
blog.categories.ai

Apple Intelligence Is Coming to China With Alibaba's Qwen: Features, iOS 27.3 Dates, iPhones and the Catch

On October 31, 2026, Apple confirmed that the first Apple Intelligence features are coming to iPhone users in mainland China, with Alibaba's Qwen built into Siri, Writing Tools and Visual Intelligence. Testing starts November 4 in the iOS developer beta and the public launch comes with iOS 27.3 in December. Here is every feature, how the Qwen hand-off works, which iPhones qualify and what is still missing.

BSH Technologies
BSH Technologies · 2026-11-01
One robots.txt Line to Opt Out of AI Training: OpenAI, Google, Microsoft and Anthropic Back __usage_ai-training
blog.categories.ai

One robots.txt Line to Opt Out of AI Training: OpenAI, Google, Microsoft and Anthropic Back __usage_ai-training

On October 30, 2026, OpenAI, Google and Microsoft said they will honor a shared robots.txt token, __usage_ai-training, drafted at the IETF by Anthropic's Kevin Kelley. One group in robots.txt can now tell every participating AI lab not to train on your site. Here is the exact syntax, each company's timeline, Bing's new grounding controls and what the token cannot do.

BSH Technologies
BSH Technologies · 2026-10-31