Cloudflare tutor

A morning desk for Kotha · Gold Coast

· Australia/Brisbane · Lesson

Workers AI: run AI models on Cloudflare from inside a Worker

Workers AI (AI models as a Worker binding)

What it is

Workers AI lets a Worker run an AI model on Cloudflare's own servers, without you renting a GPU or signing up with a separate AI company. Cloudflare hosts a catalogue of open models: text models that answer questions or summarise, models that turn speech into text, models that describe or label images, translation models, and embedding models that turn text into numbers for search.

You connect it the same way as KV, D1, and R2: with a binding. In wrangler.toml you add an [ai] block with a binding name such as AI. In the script you then call something like env.AI.run("<model name>", { prompt: "..." }) or pass a list of chat messages, and the model's answer comes back to the Worker, which can show it on a page or save it to D1.

The dashboard lists the available models and has a playground where you can type a prompt and see an answer before writing any code (look under AI, then Workers AI; the wording may differ slightly). Usage is measured in units Cloudflare calls neurons. There is a free daily allowance, and beyond it the Workers Paid plan bills per use, so check the pricing page before building anything heavy.

Why it matters

Many of your small apps need a little AI: tidy up dictated notes, summarise a newsletter, draft a plain-English explanation, or classify a message. Workers AI keeps that inside the same Cloudflare account that already hosts the app, with no API key to store as a secret, because the binding itself is the permission.

It also keeps the moving parts few. The Worker, the database, the files, and the model all live on Cloudflare, so one Wrangler deploy updates the whole thing. If you later want a stronger commercial model, the AI Gateway lesson coming up shows how to put a single front door in front of several providers.

The caution: these are open models and they can be wrong with confidence. Treat their answers as drafts, never as clinical advice, and do not send identifiable patient information to any model unless you have checked where the data goes and that it meets your privacy obligations.

On your account

From your own setup: the Clinic Triage Desk at triage.kosan.xyz calls an outside model through OpenRouter with a stored key. A Workers AI version of the same idea would add [ai] binding = "AI" to that Worker's wrangler.toml and call env.AI.run with a short system prompt, so no OpenRouter key would be needed for the simple steps.

Another natural fit is notes.kosan.xyz, your dictation notes app: a Worker could pass a day's note text to a text model with the instruction "summarise in three dot points" and store the summary in D1 next to the note.

This tutor, cloudflare.kosan.xyz, served by the cloudflare-tutor Worker, has no [ai] binding and calls no model; its lessons are fixed text in worker.js. Nothing in this lesson adds a binding, deploys a Worker, or changes any app.

Do this yourself

These stay in the dashboard, on your side. This site does not change DNS, routes, or other Workers.

  1. In the Cloudflare dashboard, open AI, then Workers AI (wording may differ slightly), open the model playground, pick any text-generation model, and paste a made-up, non-patient paragraph such as a clinic newsletter blurb with the instruction "rewrite this in plain English in three dot points"; then try a second model with the same text and write down which answer you preferred and why. Do not create a Worker, add a binding, or deploy anything.