Somewhere in almost every conversation about self-hosted AI, someone frames it as a cost optimization: “if we run our own model, we stop paying per token.” That’s the wrong starting point, and building a whole architecture on it tends to produce a worse outcome than just picking a cheaper cloud model would have. This lesson works through the actual cost math, then lays out the three reasons self-hosting genuinely does make sense, so the rest of this course is something you reach for deliberately, not by accident.
Course 5’s PHP AI Client SDK foundation, so you have a baseline for what calling a cloud provider actually costs and involves. No new WordPress APIs are introduced in this lesson, it’s entirely about the decision that precedes writing any code.
Step 1: Do the cost math before you do anything else
A GPU capable of running a genuinely useful open-weight model at reasonable speed is not a small purchase, and it doesn’t stop costing money once you own it: it draws power continuously if you keep a model loaded and ready to answer requests, it needs a machine around it, and someone has to keep the drivers, the inference server, and the underlying OS patched. None of that shows up on an API invoice for a cloud provider, where the listed per-token price already has all of that folded in and amortized across every other customer sharing the same infrastructure.
# File: terminal - a rough, illustrative comparison, not a quote
# Cloud API: pay only for tokens actually used, no idle cost, no hardware to own.
# Self-hosted: pay for the GPU whether it answers 10 requests today or 10,000,
# plus power, plus whoever's time it takes to keep the box running.
echo "Before committing to self-hosting, estimate: (GPU cost + power + maintenance time)"
echo "over your project's real timeline, and compare that number to what the same"
echo "traffic would actually cost against a cloud provider's current per-token pricing."
For most WordPress projects, at most traffic volumes, that comparison favors the cloud API, sometimes by a wide margin. Specific GPU prices and specific per-token prices both change constantly, so treat the exercise above as a method to run yourself with current numbers, not a fixed conclusion to quote later.
A cloud API charges nothing while nobody is using your feature. A GPU you own or rent keeps costing money whether it’s answering requests or sitting idle, unless you’re disciplined about spinning it down between uses, which then reintroduces cold-start latency you didn’t have with a cloud API in the first place.
Step 2: The three real reasons to self-host
If cost isn’t the case, what is? Three reasons hold up under real scrutiny, and they’re the reasons this course actually exists for.
Every one of these is a real, defensible engineering reason. None of them is “it will be cheaper.” If your actual driver is one of these three, the rest of this course is worth the investment. If it isn’t, say so honestly before writing any code.
Step 3: When self-hosting is clearly not worth it
The inverse case matters just as much. A low-traffic admin tool that runs a handful of AI requests a day, on a small team with no regulatory constraint and no contractual restriction on where data goes, gains nothing from self-hosting and takes on real, ongoing operational cost: someone has to run the inference server, keep the model updated, monitor it, and handle its downtime, work a cloud provider was doing for you.
Every reliability, availability, and maintenance concern that used to be a cloud provider’s job becomes your team’s job the moment you self-host. That’s a legitimate trade for the three reasons in Step 2. It’s a bad trade if none of those three reasons actually apply to your project.
Step 4: A decision checklist for a real project
Before starting Lesson 2, run an actual project through this list:
If none of the first three are genuinely true, stop here and use Course 5’s provider fallback patterns with a cloud model instead. If at least one is true and the fourth is also true, continue to Lesson 2.
Test it: write down your own project’s answer
Before moving on, write a single sentence naming which of privacy, regulatory requirement, or vendor lock-in avoidance is the actual reason you’re considering self-hosting for a specific project. If you can’t complete that sentence honestly, that’s useful information too.
Recap
Self-hosting an LLM is very rarely a cost optimization once GPU hardware and its ongoing upkeep are counted honestly against per-token cloud pricing. The real reasons it makes sense are privacy, regulatory or liability requirements around data residency, and avoiding dependence on a single AI vendor. Where none of those apply, a cheaper model in a Course 5 preference list is almost always the better engineering decision. Where one or more genuinely does apply, the rest of this course builds the real infrastructure for it.
Resources & further reading
- Ollama, ollama.com
- vLLM repository, GitHub
- llama.cpp repository, GitHub
- PHP AI Client SDK repository, GitHub