Back to all labs
LAB 04

Workers AI

Building, Governing, and Automating AI at the Edge with Cloudflare

45 minutes Level 1-2 2 Captains
Workers AIAI GatewayBrowser Rendering

Summary

This hands-on lab introduces participants to building and operating AI-powered applications at the edge using Cloudflare's AI platform. Participants will deploy AI inference using Workers AI, apply governance and security controls through AI Gateway, and optionally automate real-world web interactions using Cloudflare's AI-driven browser rendering capabilities. By the end of the lab, participants will understand how to safely operationalize AI workloads with performance, visibility, and control built in from day one.

Objectives

  • Deploy an edge-native AI application using Cloudflare Workers AI to perform real-time AI inference.
  • Configure and operate an AI Gateway to monitor usage, enforce rate limits, and apply governance controls across AI traffic.
  • Analyze AI request logs and metrics to gain visibility into model usage, performance, and operational behavior.
  • (Optional) Implement AI-driven browser automation using Cloudflare Browser Rendering and Stagehand to execute and extract data from dynamic web pages using natural-language instructions.

Lab Authors

ST
Siwat Tantikul Senior Solutions Engineer
NN
Nathan Neo Solutions Engineer

Lab Modules

Step-by-step hands-on modules

1

Introduction to Workers AI

15 min

Explore Cloudflare Workers AI -- Cloudflare's serverless AI inference platform that lets you run AI models at the edge directly from Cloudflare Workers. Understand the key concepts, see how to invoke a model, and build a simple Worker script that performs an inference task (e.g., text classification or summarization). This sets the foundation for all subsequent AI workflows.

Objective: Deploy a Cloudflare Worker that successfully invokes an AI model via Workers AI and returns a model response.

Key Steps:

  • Create a Cloudflare Worker project using wrangler CLI
  • Write code to call an AI model via Workers AI (e.g., send a prompt and receive output)
  • Deploy and test the Worker using a sample prompt
  • Inspect logs/outputs and perform basic debugging
2

Operating an AI Gateway -- Governance, Security, and Scale

20 min

Introduces Cloudflare AI Gateway, a control plane to govern, monitor, secure, and scale AI applications. Learn how to configure an AI Gateway, set rate limits, enable caching, track metrics, and observe logs for AI usage. See how AI Gateway helps manage multi-provider AI models (like OpenAI and Workers AI) through a single unified control layer.

Objective: Set up and configure a Cloudflare AI Gateway to control and monitor AI application traffic, including applying rate limits and viewing usage metrics.

Key Steps:

  • Create an AI Gateway instance in the Cloudflare dashboard
  • Connect the existing AI app (Worker from Module 1) to the Gateway
  • Configure analytics and logging
  • Enable caching for cost and latency savings
  • Set up rate limiting and retries
  • Configure fallback models for resilience
  • Configure dynamic routing (A/B testing, gradual rollouts)
  • Review logs/metrics to verify traffic flows and policy enforcement
3

Browser Rendering -- AI-Powered Browser Automation (Optional)

25 min

Dive into Cloudflare's Browser Rendering API and Stagehand, an AI-powered browser automation library. Build a Worker that automates a simple website interaction using natural-language instructions interpreted by Stagehand and rendered via Browser Rendering. This showcases how AI can orchestrate browser tasks at the edge.

Objective: Deploy a Cloudflare Worker that uses Stagehand, Browser Rendering and Workers AI to perform an automated browser task via natural language instructions, eliminating the need for exact selector/steps as often required with automated testing.

Key Steps:

  • Create a new Worker project with Browser Rendering and Stagehand enabled
  • Write Worker code that launches a browser instance
  • Use Stagehand with a natural-language instruction (e.g., "Search for a product, extract price")
  • Return structured data and optionally a screenshot
  • Deploy and test the project

Ready to start this lab?

Join the hands-on session and build something real.