jackspace/claudeskillz/cloudflare-workers-ai
- community
Checking that the SKILL.md file is still in the repository.
Reference for Cloudflare Workers AI, running AI models on serverless GPUs through the env.AI.run() binding. Covers the AI binding in wrangler.jsonc, model selection (@cf/meta/llama, Flux and Stable Diffusion image generation, BGE embeddings, vision models), streaming responses, AI Gateway caching, RAG with Vectorize, Vercel AI SDK integration and OpenAI-compatible endpoints, plus rate limits, neuron pricing and a production checklist. Use when implementing AI inference in a Cloudflare Worker, generating text or images at the edge, configuring Workers AI bindings, adding AI streaming, wiring up AI Gateway, building embeddings or RAG on Workers, or debugging AI_ERROR, rate limit errors, model not found, model unavailable, token limit exceeded, neurons exceeded, quota exceeded or streaming failures.
Install
npx vskill@latest install jackspace/claudeskillz/cloudflare-workers-aiSKILL.md
Cloudflare Workers AI - Complete Reference
Production-ready knowledge domain for building AI-powered applications with Cloudflare Workers AI.
Status: Production Ready ✅ Last Updated: 2025-10-21 Dependencies: cloudflare-worker-base (for Worker setup) Latest Versions: wrangler@4.43.0, @cloudflare/workers-types@4.20251014.0
Table of Contents
- Quick Start (5 minutes)
- Workers AI API Reference
- Model Selection Guide
- Common Patterns
- AI Gateway Integration
- Rate Limits & Pricing
- Production Checklist
Quick Start (5 minutes)
1. Add AI Binding
wrangler.jsonc:
2. Run Your First Model
3. Add Streaming (Recommended)
Why streaming?
- Prevents buffering large responses in memory
- Faster time-to-first-token
- Better user experience for long-form content
- Avoids Worker timeout issues
Workers AI API Reference
env.AI.run()
Run an AI model inference.
Signature:
Parameters:
model(string, required) - Model ID (e.g.,@cf/meta/llama-3.1-8b-instruct)inputs(object, required) - Model-specific inputsoptions(object, optional) - Additional optionsgateway(object) - AI Gateway configurationid(string) - Gateway IDskipCache(boolean) - Skip AI Gateway cache
Returns:
- Non-streaming:
Promise<ModelOutput>- JSON response - Streaming:
ReadableStream- Server-sent events stream
Text Generation Models
Input Format:
Output Format (Non-Streaming):
Example:
Text Embeddings Models
Input Format:
Output Format:
Example:
Image Generation Models
Input Format:
Output Format:
- Binary image data (PNG/JPEG)
Example:
Vision Models
Input Format:
Example:
Model Selection Guide
Text Generation (LLMs)
| Model | Best For | Rate Limit | Size | |
|---|---|---|---|---|
@cf/meta/llama-3.1-8b-instruct | General purpose, fast | 300/min | 8B | |
@cf/meta/llama-3.2-1b-instruct | Ultra-fast, simple tasks | 300/min | 1B | |
@cf/qwen/qwen1.5-14b-chat-awq | High quality, complex reasoning | 150/min | 14B | |
@cf/deepseek-ai/deepseek-r1-distill-qwen-32b | Coding, technical content | 300/min | 32B | |
@hf/thebloke/mistral-7b-instruct-v0.1-awq | Fast, efficient | 400/min | 7B |
Text Embeddings
| Model | Dimensions | Best For | Rate Limit | |
|---|---|---|---|---|
@cf/baai/bge-base-en-v1.5 | 768 | General purpose RAG | 3000/min | |
@cf/baai/bge-large-en-v1.5 | 1024 | High accuracy search | 1500/min | |
@cf/baai/bge-small-en-v1.5 | 384 | Fast, low storage | 3000/min |
Image Generation
| Model | Best For | Rate Limit | Speed | |
|---|---|---|---|---|
@cf/black-forest-labs/flux-1-schnell | High quality, photorealistic | 720/min | Fast | |
@cf/stabilityai/stable-diffusion-xl-base-1.0 | General purpose | 720/min | Medium | |
@cf/lykon/dreamshaper-8-lcm | Artistic, stylized | 720/min | Fast |
Vision Models
| Model | Best For | Rate Limit | |
|---|---|---|---|
@cf/meta/llama-3.2-11b-vision-instruct | Image understanding | 720/min | |
@cf/unum/uform-gen2-qwen-500m | Fast image captioning | 720/min |
Common Patterns
Pattern 1: Chat Completion with History
Pattern 2: RAG (Retrieval Augmented Generation)
Pattern 3: Structured Output with Zod
Pattern 4: Image Generation + R2 Storage
AI Gateway Integration
AI Gateway provides caching, logging, and analytics for AI requests.
Setup:
Benefits:
- ✅ Cost Tracking - Monitor neurons usage per request
- ✅ Caching - Reduce duplicate inference costs
- ✅ Logging - Debug and analyze AI requests
- ✅ Rate Limiting - Additional layer of protection
- ✅ Analytics - Request patterns and performance
Access Gateway Logs:
Rate Limits & Pricing
Rate Limits (per minute)
| Task Type | Default Limit | Notes | |
|---|---|---|---|
| Text Generation | 300/min | Some fast models: 400-1500/min | |
| Text Embeddings | 3000/min | BGE-large: 1500/min | |
| Image Generation | 720/min | All image models | |
| Vision Models | 720/min | Image understanding | |
| Translation | 720/min | M2M100, Opus MT | |
| Classification | 2000/min | Text classification | |
| Speech Recognition | 720/min | Whisper models |
Pricing (Neurons-Based)
Free Tier:
- 10,000 neurons per day
- Resets daily at 00:00 UTC
Paid Tier:
- $0.011 per 1,000 neurons
- 10,000 neurons/day included
- Unlimited usage above free allocation
Example Costs:
| Model | Input (1M tokens) | Output (1M tokens) | |
|---|---|---|---|
| Llama 3.2 1B | $0.027 | $0.201 | |
| Llama 3.1 8B | $0.088 | $0.606 | |
| BGE-base embeddings | $0.005 | N/A | |
| Flux image generation | ~$0.011/image | N/A |
Production Checklist
Before Deploying
- [ ] Enable AI Gateway for cost tracking and logging
- [ ] Implement streaming for all text generation endpoints
- [ ] Add rate limit retry with exponential backoff
- [ ] Validate input length to prevent token limit errors
- [ ] Set appropriate timeouts (Workers: 30s CPU default, 5m max)
- [ ] Monitor neurons usage in Cloudflare dashboard
- [ ] Test error handling for model unavailable, rate limits
- [ ] Add input sanitization to prevent prompt injection
- [ ] Configure CORS if using from browser
- [ ] Plan for scale - upgrade to Paid plan if needed
Error Handling
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/cloudflare-workers-ai/SKILL.md
Popularity
- Repository stars
- 12
- Repository forks
- 4
- 7-day trend score
- 13
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 31 Mar 2026, 7 months ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/jackspace/claudeskillz/cloudflare-workers-ai)