Complete guide to deploying Billy Bullshit to Cloudflare Workers.
-
Cloudflare Account
- Sign up at https://dash.cloudflare.com/sign-up
- Free tier is sufficient
-
Node.js & npm
node --version # Should be 18+ npm --version -
Wrangler CLI
npm install -g wrangler wrangler --version
cd billy-bullshit
npm installwrangler loginThis will open a browser for authentication.
wrangler whoamiCopy your Account ID and update wrangler.toml:
account_id = "your-account-id-here"# Production namespace
wrangler kv:namespace create "CONVERSATIONS"
# Preview namespace (for development)
wrangler kv:namespace create "CONVERSATIONS" --previewYou'll get IDs like:
✨ Success!
Add the following to your wrangler.toml:
{ binding = "CONVERSATIONS", id = "abc123..." }
Update wrangler.toml with these IDs:
[[kv_namespaces]]
binding = "CONVERSATIONS"
id = "your-production-id"
preview_id = "your-preview-id"For better AI responses, add API keys:
# Anthropic Claude (recommended)
wrangler secret put ANTHROPIC_API_KEY
# Enter your key when prompted
# OpenAI (fallback)
wrangler secret put OPENAI_API_KEY
# Enter your key when promptedNote: Without API keys, Billy uses Cloudflare Workers AI (free, but less sophisticated).
# Development deployment
npm run dev
# Production deployment
npm run deploy
# Or specific environment
wrangler deploy --env production# Get your worker URL from deployment output
curl https://billy-bullshit.your-subdomain.workers.dev
# Should return Billy's API infoAdd your domain (e.g., billy.chitty.cc) to Cloudflare
[env.production]
routes = [
{ pattern = "billy.chitty.cc", custom_domain = true }
]wrangler deploy --env productionYour agent will be available at https://billy.chitty.cc
[env.development]
name = "billy-bullshit-dev"
vars = { ENVIRONMENT = "development" }wrangler dev[env.staging]
name = "billy-bullshit-staging"
routes = [{ pattern = "billy-staging.chitty.cc", custom_domain = true }]wrangler deploy --env staging[env.production]
name = "billy-bullshit-prod"
routes = [{ pattern = "billy.chitty.cc", custom_domain = true }]wrangler deploy --env production# Real-time logs
wrangler tail
# Environment-specific
wrangler tail --env productionView in Cloudflare Dashboard:
- Go to Workers & Pages
- Select "billy-bullshit"
- Click "Metrics" tab
Error: KV namespace not found
Solution: Make sure KV namespace IDs in wrangler.toml match your created namespaces:
wrangler kv:namespace listError: AI binding not available
Solution: Ensure your Cloudflare account has Workers AI enabled (free on all plans).
Error: Authentication required
Solution:
wrangler logout
wrangler loginPossible causes:
- Worker crashed - check logs:
wrangler tail - Exceeded CPU limits - optimize code
- Network timeout - reduce request complexity
# Make changes
git add .
git commit -m "Update Billy"
# Deploy
npm run deploynpm update
npm run deploy# List deployments
wrangler deployments list
# Rollback to previous
wrangler rollbackBilly uses KV for conversation history with 7-day expiration:
await kv.put(key, value, {
expirationTtl: 86400 * 7 // 7 days
});Faster models = lower latency:
[vars]
# Llama 3.1 8B (fast, good quality)
DEFAULT_MODEL = "@cf/meta/llama-3.1-8b-instruct"
# Or smaller/faster:
# DEFAULT_MODEL = "@cf/meta/llama-2-7b-chat-int8"Use /stream endpoint for better UX:
curl -N -X POST https://billy.chitty.cc/stream \
-d '{"message":"Tell me about AI"}'Add rate limiting in worker:
// Check rate limit
const key = `rate:${ip}`;
const count = await env.RATE_LIMIT.get(key);
if (count && parseInt(count) > 100) {
return c.json({ error: 'Rate limited' }, 429);
}Store sensitive keys as secrets:
wrangler secret put MY_SECRET_KEYNever commit secrets to git!
Currently allows all origins. For production, restrict:
cors({
origin: ['https://yourapp.com'],
allowMethods: ['POST'],
})- 100,000 requests/day
- 10ms CPU time per request
- 128MB memory
- Cost: $0
- $5/month for 10M requests
- Additional requests: $0.50 per million
- KV operations included
Billy runs perfectly on free tier for most use cases.
- ✅ Deploy Billy
- Test all endpoints
- Set up custom domain
- Monitor usage
- Add to your apps!
- Docs: This file
- Cloudflare Workers Docs: https://developers.cloudflare.com/workers/
- Issues: Create an issue if Billy's broken
Remember: Billy doesn't break. Your code does. 🔥