How do you ship AI features without provisioning and operating GPU infrastructure?
Self-hosting an LLM means renting expensive GPUs (or buying them), provisioning across regions for latency, managing CUDA versions and model serving, and paying for idle GPU time when traffic is low. Using OpenAI is great for prototyping but the per-call costs add up, your data leaves your control, and you're tied to one vendor's roadmap. You need a third option: open models, hosted close to users, billed only when you actually run inference.
How it fits together
Diagram coming soon
Architecture diagram for this solution will be added here.
How Cloudflare solves it
- 50+ open models out of the box. Llama 3.x, Mistral, Gemma, Stable Diffusion, Whisper, BGE embeddings, m2m translation, summarization, classification, and more. New models added regularly.
- Inference on Cloudflare's GPU network. GPUs deployed across Cloudflare's edge so inference happens near the user. No region selection, no provisioning, no warm-pool worry.
- Per-token billing. Pay only for tokens generated and processed. No idle GPU charges. Models priced individually — small models (1–8B) are cheap enough for high-volume use cases.
- Native Workers binding. Inside a Worker, run inference with <code>await env.AI.run('@cf/meta/llama-3.1-8b-instruct', { prompt: '...' })</code>. No HTTP, no auth tokens — just a function call.
- Integrated stack. Pair Workers AI with Vectorize (vector DB), R2 (object storage), D1 (SQL), and AI Gateway (observability, caching, fallback) — all on one platform, with sub-millisecond bindings between them.
- RAG in a few lines with AI Search. AI Search (AutoRAG) turns an R2 bucket into a managed retrieval pipeline: it chunks and embeds your documents into Vectorize, then at query time embeds the question, retrieves the closest chunks, reranks them for true relevance, and feeds them to a Workers AI model — every step powered by Workers AI models (embeddings, reranker, and the LLM). The demo below toggles this on and off.
Common questions
How does this differ from calling OpenAI from a Worker?
What models are available?
Can I fine-tune models on Workers AI?
What's the latency like compared to a self-hosted GPU?
What is RAG, and how does the toggle in the demo work?
Does RAG replace the model's general knowledge?
Try it live
Send a prompt below. With RAG off, it runs against Llama 3.3 70B via this site's AI Gateway → Workers AI pipeline (the same path the chatbot uses). Flip on Enable RAG to route through AI Search (AutoRAG) instead — the question is embedded, matched against a private /aboutme profile stored in R2 + Vectorize, reranked, and answered with citations. Try “What is Remy Calder's internal codename?” both ways: off, the model doesn't know; on, it answers from the retrieved source. Ask a general question like “What is Cloudflare?” with RAG on and it falls back to the model's own knowledge.
Send a prompt below. With RAG off, the request goes
browser → /api/chat → AI Gateway → Workers AI (Llama 3.3 70B).
With RAG on, it goes
browser → /api/aboutme-rag → AI Search (AutoRAG) → Vectorize + R2 → Workers AI.