← Back to blog
What I Learned Building with Cloudflare and OpenRouter

What I Learned Building with Cloudflare and OpenRouter

·8 min read·13 views

What I Learned Building with Cloudflare and OpenRouter

Alright, back with another piece. Or actually, I'm dictating this one out, talking to you. Today I'm sharing what I learned building with Cloudflare and OpenRouter.

What I Was Using Before

Before we get into it, let me tell you the old setup. I was playing around with OpenAI and Anthropic directly, using their API keys to inference their models. I'd also lean on Vercel for some pieces, and a bit of Fal.AI for talking to various models. Hosting was either Vercel or DigitalOcean (their VPS), and I played around with hosting on a Raspberry Pi too.

I still have a few apps running on the Pi because that's the cheapest option around. A 16GB RAM Raspberry Pi with some extra storage is honestly the move.

Why I Switched

About a month ago, I noticed Cloudflare was improving Workers and making some really nice changes. Around the same time I'd moved a couple of my larger projects — including a vitamin K tracker app — and then Vercel got hacked, with private keys and stuff exposed. So I thought, "You know what? Maybe it's a good time to try Cloudflare."

Since I was trying something new anyway, I figured I'd look into other AI inference options too. I checked out Cloudflare's Agent AI SDK and their models, but I didn't really care for it. What I liked was OpenRouter — one API key, multiple providers, multiple models you can swap between whenever you want. They also have a free mode that gives you about 50 calls a day, which is useful for prototyping, and you get 1,000 a day if you load up $10. The cost was low, especially since you can use free models for a good bit without paying anything.

For inferencing I also use Ollama, since their SDK supports the bring-your-own-key model.

Another reason I liked OpenRouter: if I'm making a simple prototype I don't want to monetize — just something someone needs access to — OpenRouter has OAuth built into their SDK. Users can sign up with their own OpenRouter accounts and manage and pay for their own usage.

The Stack

Here's what I'm running on now.

Cloudflare Workers

Workers are basically serverless compute. They run your code across around 300 edge locations, and support JavaScript and TypeScript. Similar to AWS Lambda, but a little faster, with a generous free tier — about 100K requests per day. Upgrading to the $5 plan bumps that to 10 million requests a day. This replaced me having to SSH into a VPS and manage servers myself.

D1

D1 is Cloudflare's serverless SQL database, built on SQLite. You query it through Workers — no DB server, no connection pooling, no VPC config. Just define your schema, write your SQL, in and out. It's basically SQLite in the cloud, so if you're familiar with SQL you don't have to learn anything new.

The free plan gives you 5GB plus 5 million reads a day. The $5 paid plan jumps to 25GB and 25 billion reads. That's plenty of space for the projects I'm running. This replaced me using PostgreSQL on a VPS or the Pi, managing connections and running migrations by hand. D1 handles all of that, and you can easily wire your projects together.

Cloudflare Pages

For static pages, Pages is great. Static hosting, serverless functions, deploy from Git (I'm pretty sure Workers can deploy from Git too). Every PR gets a preview URL, similar to what I got with Vercel — but a lot cheaper. This replaced Vercel, Netlify, and a bunch of other things.

How It All Works Together

Pages serves the front end. Workers handle the API. D1 stores anything long-term — users, sessions, persistent data. There's caching via KV, and analytics built in.

A lot of this was being charged piece by piece on Vercel. My bill went from around $30+ a month to $5.01 right now — and that one cent is only because I accidentally borked a script with Ollama and the Pi, and it kept spamming while I went to walk Alibaba. Came back and realized it hadn't worked the way I wanted.

It lets me build data-heavy apps without managing servers — way lighter and freer. They've also got a lot of skills you can hook into to use alongside your AI.

Honestly, I'm not even going past the free tier limits on most things. It's affordable, everything works together, and this was the first time I tried their ecosystem beyond just using Cloudflare for domains. Connecting projects to a new subdomain domain was simple. Everything's generous.

What I'm Using It For

I've got a bunch of projects running on it. My Fed Firehose app. One that tracks the US Treasury so I can see what's going on there. Another that pulls from the government API to grab all the bills, senators, and that whole mess, then stores it so you can query it. Costs basically nothing — when there's a lot of active traffic, I can cache the popular stuff and barely touch the limits. I'm also using it for a Magic Link package I setup for handling my own authentication.

Why OpenRouter Over Cloudflare's AI

I considered Cloudflare's AI offering, but OpenRouter felt better. They've made real progress in their SDK and tooling, and I wanted access to multiple models, not just one provider.

They support bring-your-own-key, so individuals can pay for their own usage if you want to set it up that way. I can use OAuth and the API key directly from OpenRouter to verify usage on my application. They've got guardrails, plug-ins, and image generation support. I can do a lot with just one API, and I can get people started for free using the free tier. That part was even better.

Building Skills Along the Way

The culmination of all this was a small AI harness I built that ended up evolving into its own thing. As I kept working on these projects, I wanted something consistent across them. My bill has been $5.01 — way cheaper than what I was spending before.

I also built a lot of skills and tools to help me build more. The biggest pain point early on was just not knowing all the tools Cloudflare and OpenRouter provided. As I read through the docs and learned what did what, it got easier to turn the documentation — and some of the inconsistencies and errors I ran into — into reusable skills.

Making your own skills for things you do over and over is really worth it. One example: making sure code is reviewed and bug-free. I ended up tweaking some test-driven development skills and built a whole suite I can now reference. It just makes everything easier. Being able to push code, forget it, and have it automatically connect to my DNS and be protected was great.

Deployment

Deployment is really easy. You just type wrangler deploy. Cloudflare has their own CLI tool (Vercel has one too, I know). You get decent build compute — nothing wild, but it supports Next.js and Vite, so if you're familiar with those you're set. PRs get their own deployments so you can test things out. Set up auto-deploy and you barely have to think about anything.

If your app scales and gets real traffic, Workers autoscale. The $5 plan is so generous that you don't really have to worry about accidentally racking up a huge bill — which I know people were memeing about back in the day with Vercel. Cloudflare seems to be trying hard to keep users right now. They've been making a lot of tools for individuals interested in AI, and I'm on board.

What I'd Tell a Solo Dev

I'm going to keep using Cloudflare. I'm going to keep using OpenRouter. And I'm going to keep using Ollama — I love Ollama. They need a tool that makes it easier to use Ollama in the browser. Maybe I'll build that myself. You never know.

If you're new to development, or you're on the fence, my take is this: go ahead and use Cloudflare. It's easy. You don't need a DevOps team to ship to production. The free tier is usable and generous. You can definitely build a portfolio page — say you're a beginner dev who needs to show off your skills, buy a domain(they give you a generic one for a project), put it on Cloudflare, and you'll be good for a long time. Unless you build something wild and need to scale, and even then it's only $5 to upgrade.

What I'd Do Differently

I should have looked into Cloudflare earlier.

And when it came to building the AI assistant that helps me build these tools, I should have started by building a project and the agent together, iterating on both sides at the same time. Before that, I was trying to build the agent first and then plug it in. It worked out a lot better once I made the Scholar app (also a Cloudflare app — it's an AI agent that lets you talk to and study the Bible). Getting that together taught me more about OpenRouter, and the pieces fell into place.

If you're spinning up servers and worrying about costs — stop. Try this stack. Ship faster, sleep better.

Have a good night, or have a good morning.

The agent: https://origen.moikapy.dev

How did this post make you feel?

2 shares

Related Posts