[{"data":1,"prerenderedAt":825},["ShallowReactive",2],{"page-\u002Fblog\u002Fcloudflare-workers-ai-edge-2026":3,"\u002Fblog\u002Fcloudflare-workers-ai-edge-2026-surround":817},{"id":4,"title":5,"author":6,"body":11,"category":797,"date":798,"description":799,"extension":800,"image":801,"meta":802,"navigation":234,"ogImage":809,"path":810,"published":234,"robots":809,"schemaOrg":809,"seo":811,"seoDescription":812,"seoTitle":813,"sitemap":814,"stem":815,"__hash__":816},"blog\u002Fblog\u002Fcloudflare-workers-ai-edge-2026.md","Cloudflare Workers AI in 2026: Shipping AI Features Without a GPU Bill",{"name":7,"role":8,"imageUrl":9,"href":10},"Bret Oreta","Admin","https:\u002F\u002Fbretoreta.me\u002Fimages\u002Fopt\u002Favatar-96.webp","https:\u002F\u002Fbretoreta.me\u002Fabout",{"type":12,"value":13,"toc":780},"minimark",[14,18,29,32,37,40,59,62,88,91,108,112,115,126,129,132,136,139,523,526,530,535,538,542,545,549,552,556,559,563,566,570,609,616,620,623,637,640,657,660,664,667,688,691,695,756,760,763,776],[15,16,17],"p",{},"Not every AI feature needs a GPU cluster. A lot of useful work — classification, embeddings, moderation, short summaries, image generation, simple chat — can run on serverless inference close to the user.",[15,19,20,21,28],{},"Cloudflare Workers AI is one option in that space. It lets a Worker call hosted models without managing infrastructure, and it pairs with the rest of Cloudflare’s developer platform: R2 for storage, D1 for relational data, Vectorize for embeddings, and AI Gateway for observability and controls. The ",[22,23,27],"a",{"href":24,"rel":25},"https:\u002F\u002Fdevelopers.cloudflare.com\u002Fworkers-ai\u002F",[26],"nofollow","Workers AI documentation"," is the source of truth for the current model catalog and limits.",[15,30,31],{},"This is not a “run your whole AI company on the edge” pitch. It is a guide to the features where edge inference is a good fit.",[33,34,36],"h2",{"id":35},"what-workers-ai-is-good-for","What Workers AI is good for",[15,38,39],{},"Workers AI works best when the task is:",[41,42,43,47,50,53,56],"ul",{},[44,45,46],"li",{},"short-running,",[44,48,49],{},"stateless or lightly stateful,",[44,51,52],{},"tolerant of model limits,",[44,54,55],{},"close to the user,",[44,57,58],{},"cost-sensitive.",[15,60,61],{},"Good examples:",[41,63,64,67,70,73,76,79,82,85],{},[44,65,66],{},"text classification and routing,",[44,68,69],{},"embeddings for search and recommendations,",[44,71,72],{},"content moderation,",[44,74,75],{},"short summarization,",[44,77,78],{},"translation,",[44,80,81],{},"image generation,",[44,83,84],{},"lightweight chat or extraction,",[44,86,87],{},"spam and intent detection.",[15,89,90],{},"Poor examples:",[41,92,93,96,99,102,105],{},[44,94,95],{},"training or fine-tuning large models,",[44,97,98],{},"long-context document analysis,",[44,100,101],{},"workloads that need a specific GPU shape or framework,",[44,103,104],{},"strict data-residency requirements you cannot satisfy,",[44,106,107],{},"complex multi-step agents with heavy orchestration.",[33,109,111],{"id":110},"the-practical-architecture","The practical architecture",[15,113,114],{},"A typical edge AI feature looks like this:",[116,117,123],"pre",{"className":118,"code":120,"language":121,"meta":122},[119],"language-text","Browser\n  → Worker\n    → AI binding (inference)\n    → Vectorize (retrieval)\n    → R2 (documents\u002Fimages)\n    → D1 (metadata)\n    → AI Gateway (logs, limits, caching)\n","text","",[124,125,120],"code",{"__ignoreMap":122},[15,127,128],{},"The Worker handles authentication, input validation, prompt construction, rate limits, and response shaping. The model is one dependency, not the application.",[15,130,131],{},"Keep the orchestration in code you control. If the model provider changes, you should be able to swap the call without rewriting the product.",[33,133,135],{"id":134},"a-minimal-example","A minimal example",[15,137,138],{},"The exact model names available in Workers AI change, so use the current catalog in the Cloudflare dashboard. The shape of the call is stable:",[116,140,144],{"className":141,"code":142,"language":143,"meta":122,"style":122},"language-ts shiki shiki-themes material-theme-lighter github-light github-dark","export default {\n  async fetch(request, env) {\n    const { prompt } = await request.json()\n\n    if (typeof prompt !== 'string' || prompt.length > 2000) {\n      return Response.json({ error: 'Invalid prompt' }, { status: 400 })\n    }\n\n    const result = await env.AI.run(env.AI_MODEL, {\n      messages: [\n        { role: 'system', content: 'Answer in two short sentences.' },\n        { role: 'user', content: prompt },\n      ],\n    })\n\n    return Response.json({ answer: result.response })\n  },\n}\n","ts",[124,145,146,162,191,229,236,287,336,342,347,385,396,431,457,466,474,479,511,517],{"__ignoreMap":122},[147,148,151,155,158],"span",{"class":149,"line":150},"line",1,[147,152,154],{"class":153},"sVHd0","export",[147,156,157],{"class":153}," default",[147,159,161],{"class":160},"sP7_E"," {\n",[147,163,165,169,173,176,180,183,186,189],{"class":149,"line":164},2,[147,166,168],{"class":167},"sbsja","  async",[147,170,172],{"class":171},"sVXei"," fetch",[147,174,175],{"class":160},"(",[147,177,179],{"class":178},"s99_P","request",[147,181,182],{"class":160},",",[147,184,185],{"class":178}," env",[147,187,188],{"class":160},")",[147,190,161],{"class":160},[147,192,194,197,200,204,207,211,214,218,221,225],{"class":149,"line":193},3,[147,195,196],{"class":167},"    const",[147,198,199],{"class":160}," {",[147,201,203],{"class":202},"s_hVV"," prompt",[147,205,206],{"class":160}," }",[147,208,210],{"class":209},"smGrS"," =",[147,212,213],{"class":153}," await",[147,215,217],{"class":216},"su5hD"," request",[147,219,220],{"class":160},".",[147,222,224],{"class":223},"sGLFI","json",[147,226,228],{"class":227},"skxfh","()\n",[147,230,232],{"class":149,"line":231},4,[147,233,235],{"emptyLinePlaceholder":234},true,"\n",[147,237,239,242,245,248,250,253,257,261,264,267,269,271,274,277,281,284],{"class":149,"line":238},5,[147,240,241],{"class":153},"    if",[147,243,244],{"class":227}," (",[147,246,247],{"class":209},"typeof",[147,249,203],{"class":216},[147,251,252],{"class":209}," !==",[147,254,256],{"class":255},"sjJ54"," '",[147,258,260],{"class":259},"s_sjI","string",[147,262,263],{"class":255},"'",[147,265,266],{"class":209}," ||",[147,268,203],{"class":216},[147,270,220],{"class":160},[147,272,273],{"class":202},"length",[147,275,276],{"class":209}," >",[147,278,280],{"class":279},"srdBf"," 2000",[147,282,283],{"class":227},") ",[147,285,286],{"class":160},"{\n",[147,288,290,293,296,298,300,302,305,308,311,313,316,318,321,323,326,328,331,333],{"class":149,"line":289},6,[147,291,292],{"class":153},"      return",[147,294,295],{"class":216}," Response",[147,297,220],{"class":160},[147,299,224],{"class":223},[147,301,175],{"class":227},[147,303,304],{"class":160},"{",[147,306,307],{"class":227}," error",[147,309,310],{"class":160},":",[147,312,256],{"class":255},[147,314,315],{"class":259},"Invalid prompt",[147,317,263],{"class":255},[147,319,320],{"class":160}," },",[147,322,199],{"class":160},[147,324,325],{"class":227}," status",[147,327,310],{"class":160},[147,329,330],{"class":279}," 400",[147,332,206],{"class":160},[147,334,335],{"class":227},")\n",[147,337,339],{"class":149,"line":338},7,[147,340,341],{"class":160},"    }\n",[147,343,345],{"class":149,"line":344},8,[147,346,235],{"emptyLinePlaceholder":234},[147,348,350,352,355,357,359,361,363,366,368,371,373,376,378,381,383],{"class":149,"line":349},9,[147,351,196],{"class":167},[147,353,354],{"class":202}," result",[147,356,210],{"class":209},[147,358,213],{"class":153},[147,360,185],{"class":216},[147,362,220],{"class":160},[147,364,365],{"class":202},"AI",[147,367,220],{"class":160},[147,369,370],{"class":223},"run",[147,372,175],{"class":227},[147,374,375],{"class":216},"env",[147,377,220],{"class":160},[147,379,380],{"class":202},"AI_MODEL",[147,382,182],{"class":160},[147,384,161],{"class":160},[147,386,388,391,393],{"class":149,"line":387},10,[147,389,390],{"class":227},"      messages",[147,392,310],{"class":160},[147,394,395],{"class":227}," [\n",[147,397,399,402,405,407,409,412,414,416,419,421,423,426,428],{"class":149,"line":398},11,[147,400,401],{"class":160},"        {",[147,403,404],{"class":227}," role",[147,406,310],{"class":160},[147,408,256],{"class":255},[147,410,411],{"class":259},"system",[147,413,263],{"class":255},[147,415,182],{"class":160},[147,417,418],{"class":227}," content",[147,420,310],{"class":160},[147,422,256],{"class":255},[147,424,425],{"class":259},"Answer in two short sentences.",[147,427,263],{"class":255},[147,429,430],{"class":160}," },\n",[147,432,434,436,438,440,442,445,447,449,451,453,455],{"class":149,"line":433},12,[147,435,401],{"class":160},[147,437,404],{"class":227},[147,439,310],{"class":160},[147,441,256],{"class":255},[147,443,444],{"class":259},"user",[147,446,263],{"class":255},[147,448,182],{"class":160},[147,450,418],{"class":227},[147,452,310],{"class":160},[147,454,203],{"class":216},[147,456,430],{"class":160},[147,458,460,463],{"class":149,"line":459},13,[147,461,462],{"class":227},"      ]",[147,464,465],{"class":160},",\n",[147,467,469,472],{"class":149,"line":468},14,[147,470,471],{"class":160},"    }",[147,473,335],{"class":227},[147,475,477],{"class":149,"line":476},15,[147,478,235],{"emptyLinePlaceholder":234},[147,480,482,485,487,489,491,493,495,498,500,502,504,507,509],{"class":149,"line":481},16,[147,483,484],{"class":153},"    return",[147,486,295],{"class":216},[147,488,220],{"class":160},[147,490,224],{"class":223},[147,492,175],{"class":227},[147,494,304],{"class":160},[147,496,497],{"class":227}," answer",[147,499,310],{"class":160},[147,501,354],{"class":216},[147,503,220],{"class":160},[147,505,506],{"class":216},"response",[147,508,206],{"class":160},[147,510,335],{"class":227},[147,512,514],{"class":149,"line":513},17,[147,515,516],{"class":160},"  },\n",[147,518,520],{"class":149,"line":519},18,[147,521,522],{"class":160},"}\n",[15,524,525],{},"The important parts are not the model name. They are input limits, a system instruction, a timeout, and a response contract your frontend can trust.",[33,527,529],{"id":528},"cost-control-that-actually-works","Cost control that actually works",[531,532,534],"h3",{"id":533},"cache-aggressively","Cache aggressively",[15,536,537],{},"If the same prompt or document is requested repeatedly, cache the result. A semantic cache can help, but start with exact-match caching and a short TTL.",[531,539,541],{"id":540},"choose-the-smallest-model-that-passes","Choose the smallest model that passes",[15,543,544],{},"Do not default to the biggest model for every task. Build a small evaluation set and test cheaper models first.",[531,546,548],{"id":547},"limit-input-and-output","Limit input and output",[15,550,551],{},"Cap prompt length, retrieved context, output tokens, and file size. Long inputs are the easiest way to turn a cheap feature into an expensive one.",[531,553,555],{"id":554},"rate-limit-by-user-and-tenant","Rate limit by user and tenant",[15,557,558],{},"Protect the endpoint from abuse and runaway loops. Workers rate limiting or a Durable Object can enforce per-user budgets.",[531,560,562],{"id":561},"use-ai-gateway","Use AI Gateway",[15,564,565],{},"Cloudflare’s AI Gateway can add caching, retries, logging, and cost visibility across providers. Use it as an operational layer, not a replacement for application-level limits.",[33,567,569],{"id":568},"security-considerations","Security considerations",[41,571,572,579,585,591,597,603],{},[44,573,574,578],{},[575,576,577],"strong",{},"Never expose provider keys to the browser."," Keep calls in the Worker.",[44,580,581,584],{},[575,582,583],{},"Validate input"," before it reaches the model.",[44,586,587,590],{},[575,588,589],{},"Treat retrieved content as untrusted."," RAG documents can contain prompt injection.",[44,592,593,596],{},[575,594,595],{},"Redact sensitive data"," before logging.",[44,598,599,602],{},[575,600,601],{},"Set timeouts and fallbacks."," The model should not hang the user experience.",[44,604,605,608],{},[575,606,607],{},"Use separate environments"," for development and production.",[15,610,611,612,220],{},"If the feature can take actions, not just generate text, read ",[22,613,615],{"href":614},"\u002Fblog\u002Fhow-to-secure-ai-agents-2026","How to Secure AI Agents",[33,617,619],{"id":618},"workers-ai-vs-a-dedicated-inference-provider","Workers AI vs a dedicated inference provider",[15,621,622],{},"Choose Workers AI when:",[41,624,625,628,631,634],{},[44,626,627],{},"you already run on Cloudflare,",[44,629,630],{},"the task is small and latency-sensitive,",[44,632,633],{},"you want simple deployment and billing,",[44,635,636],{},"you do not need a specific model or GPU.",[15,638,639],{},"Choose a dedicated provider when:",[41,641,642,645,648,651,654],{},[44,643,644],{},"you need a model that is not available,",[44,646,647],{},"you need fine-tuning or custom weights,",[44,649,650],{},"you have heavy batch workloads,",[44,652,653],{},"you need advanced compliance or residency guarantees,",[44,655,656],{},"you need predictable throughput at large scale.",[15,658,659],{},"The right answer may be both: edge inference for fast, cheap tasks and a dedicated provider for the heavy work.",[33,661,663],{"id":662},"rag-on-the-edge","RAG on the edge",[15,665,666],{},"A practical pattern:",[668,669,670,673,676,679,682,685],"ol",{},[44,671,672],{},"Store source documents in R2.",[44,674,675],{},"Chunk and embed them into Vectorize.",[44,677,678],{},"On request, embed the query and retrieve top matches.",[44,680,681],{},"Send only the relevant chunks to the model.",[44,683,684],{},"Return the answer with source links.",[44,686,687],{},"Log the question, sources, and latency.",[15,689,690],{},"This keeps the context small, improves accuracy, and gives users a way to verify the answer.",[33,692,694],{"id":693},"deployment-checklist","Deployment checklist",[41,696,699,708,714,720,726,732,738,744,750],{"className":697},[698],"contains-task-list",[44,700,703,707],{"className":701},[702],"task-list-item",[704,705],"input",{"disabled":234,"type":706},"checkbox"," Input and output limits defined",[44,709,711,713],{"className":710},[702],[704,712],{"disabled":234,"type":706}," Model chosen from a tested evaluation set",[44,715,717,719],{"className":716},[702],[704,718],{"disabled":234,"type":706}," Caching and rate limits enabled",[44,721,723,725],{"className":722},[702],[704,724],{"disabled":234,"type":706}," Prompt injection considered for retrieved content",[44,727,729,731],{"className":728},[702],[704,730],{"disabled":234,"type":706}," Logs redact personal data",[44,733,735,737],{"className":734},[702],[704,736],{"disabled":234,"type":706}," Fallback response implemented",[44,739,741,743],{"className":740},[702],[704,742],{"disabled":234,"type":706}," Cost alerts configured",[44,745,747,749],{"className":746},[702],[704,748],{"disabled":234,"type":706}," Model version pinned or monitored",[44,751,753,755],{"className":752},[702],[704,754],{"disabled":234,"type":706}," Load test completed",[33,757,759],{"id":758},"the-bottom-line","The bottom line",[15,761,762],{},"Workers AI is a useful tool for shipping focused AI features without building an inference platform. It is not a replacement for architecture, evaluation, or security.",[15,764,765,766,770,771,775],{},"Start with a small task, measure quality, control cost, and keep the model behind a layer you own. If you want help choosing the right stack for an AI feature, ",[22,767,769],{"href":768},"\u002Fcontact","book a free call",". You can also read about ",[22,772,774],{"href":773},"\u002Fblog\u002Flaravel-ai-agents-architecture-2026","adding AI to an existing Laravel app"," for a server-side comparison.",[777,778,779],"style",{},"html pre.shiki code .sVHd0, html code.shiki .sVHd0{--shiki-light:#39ADB5;--shiki-light-font-style:italic;--shiki-default:#D73A49;--shiki-default-font-style:inherit;--shiki-dark:#F97583;--shiki-dark-font-style:inherit}html pre.shiki code .sP7_E, html code.shiki .sP7_E{--shiki-light:#39ADB5;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sbsja, html code.shiki .sbsja{--shiki-light:#9C3EDA;--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sVXei, html code.shiki .sVXei{--shiki-light:#E53935;--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .s99_P, html code.shiki .s99_P{--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#E36209;--shiki-default-font-style:inherit;--shiki-dark:#FFAB70;--shiki-dark-font-style:inherit}html pre.shiki code .s_hVV, html code.shiki .s_hVV{--shiki-light:#90A4AE;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .smGrS, html code.shiki .smGrS{--shiki-light:#39ADB5;--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .su5hD, html code.shiki .su5hD{--shiki-light:#90A4AE;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sGLFI, html code.shiki .sGLFI{--shiki-light:#6182B8;--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .skxfh, html code.shiki .skxfh{--shiki-light:#E53935;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sjJ54, html code.shiki .sjJ54{--shiki-light:#39ADB5;--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .s_sjI, html code.shiki .s_sjI{--shiki-light:#91B859;--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .srdBf, html code.shiki .srdBf{--shiki-light:#F76D47;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":122,"searchDepth":164,"depth":193,"links":781},[782,783,784,785,792,793,794,795,796],{"id":35,"depth":164,"text":36},{"id":110,"depth":164,"text":111},{"id":134,"depth":164,"text":135},{"id":528,"depth":164,"text":529,"children":786},[787,788,789,790,791],{"id":533,"depth":193,"text":534},{"id":540,"depth":193,"text":541},{"id":547,"depth":193,"text":548},{"id":554,"depth":193,"text":555},{"id":561,"depth":193,"text":562},{"id":568,"depth":164,"text":569},{"id":618,"depth":164,"text":619},{"id":662,"depth":164,"text":663},{"id":693,"depth":164,"text":694},{"id":758,"depth":164,"text":759},"Cloud-Computing","2026-10-16","How to use Cloudflare Workers AI and the edge stack for practical AI features, with architecture patterns, limits, and cost controls.","md","\u002Fimages\u002Fblog\u002Fcloudflare-workers-ai-edge-2026.png",{"tags":803},[804,805,806,807,808],"cloudflare","workers-ai","edge-computing","ai","serverless",null,"\u002Fblog\u002Fcloudflare-workers-ai-edge-2026",{"title":5,"description":799},"A practical guide to Cloudflare Workers AI: good use cases, edge architecture, cost control, security, and when not to use serverless inference.","Cloudflare Workers AI: A 2026 Guide for Web Developers",{"loc":810},"blog\u002Fcloudflare-workers-ai-edge-2026","WyKr4zPRMI74L9KegpgwXRUT0W9BetOj15j_oSODrf4",[818,821],{"title":819,"path":614,"stem":820,"children":-1},"How to Secure AI Agents: Prompt Injection, Permissions, and Human Approval","blog\u002Fhow-to-secure-ai-agents-2026",{"title":822,"path":823,"stem":824,"children":-1},"Core Web Vitals in 2026: INP, AI-Generated Sites, and the Performance Mistakes Costing You Customers","\u002Fblog\u002Fcore-web-vitals-2026-inp-ai-sites","blog\u002Fcore-web-vitals-2026-inp-ai-sites",1793181057514]