Rana Maninder Singh
Lesson 5 of 8Choosing & Using AI Models

Running a model on your own machine vs calling an API

Lesson opener

In one line: Local means you load weights on hardware you control; API means you send bytes to someone else's hardware — pick with RAM, privacy, and who wakes up at 2 a.m.

Why it matters: A Chennai hospital that sends discharge summaries to a public API, or a startup that buys a GPU for a 20-row-a-day classifier, picked the place before the ticket.

Before this lesson: Free tiers vs paid vs API.

Before you start

ResourceLink
PreviousFree tiers vs paid vs API
NextEvaluate for your task
Prerequisitesaim4
Time~50 minutes

What you will learn

By the end of this lesson you will be able to:

  1. Contrast local load vs remote call in one sentence each.
  2. List what local needs (RAM / VRAM, engine, licence file).
  3. List what API needs (key, region, DPA, retry).
  4. Decide from constraints without naming a brand.
  5. Refuse local when VRAM is short, and refuse API when data must not leave.
  6. Stop cost: power off the GPU box, or revoke the key and stop the job.

Two places the weights live

PlaceYou sendYou runYou pay
Localnothing off-box (if the box is yours)engine + weightshardware, power, people
APIthe prompt (and maybe files)a clienttokens / requests

Local is not automatically private (a laptop can still sync a folder). API is not automatically leaky (a private region plus a DPA can be acceptable). Write the constraint, then pick.

WHY "We will just host it" without VRAM is a stalled laptop. "We will just call the API" without a region is an InfoSec reject.

WHEN After you know the job (aim1) and the pay shape (aim4).

Cost. A local GPU that stays on overnight is a power and cloud-VM bill. An API key in a cron job is a token bill. Stop: deallocate or shut the box; revoke the key and disable the cron.

This lesson does not download weights and does not call a network. The blocks decide.

Constraints that actually decide

ConstraintTips toward
Data must stay on the laptop / VPClocal (or a private-region API you have in writing)
No GPU, 8 GB RAM, 7B-class cardAPI, or a tiny local model after a fit check
2 a.m. pages nobody can restartAPI with a vendor SLA, or local with an on-call
Burst of 100k rows this weekAPI or a rented GPU, not a quiet laptop
Licence forbids hostingAPI only

Demo 1 — Place from constraints

def pick_place(ticket: dict) -> str:
    if ticket.get("must_stay_on_box"):
        if ticket.get("vram_ok"):
            return "local"
        return "refuse-local-no-vram"
    if ticket.get("no_key_allowed"):
        return "refuse-api-no-key-policy"
    return "api"

print(pick_place({"must_stay_on_box": True, "vram_ok": True}))
print(pick_place({"must_stay_on_box": True, "vram_ok": False}))
print(pick_place({"must_stay_on_box": False, "no_key_allowed": False}))
assert pick_place({"must_stay_on_box": False, "no_key_allowed": True}) == "refuse-api-no-key-policy"

Expected output:

local
refuse-local-no-vram
api

Demo 2 — Fit a 7B-class file

A rough planning rule (not a vendor spec): 16-bit weights need about 2 GB per billion parameters, plus overhead for the engine and the context. If the card says 7B at 16-bit, plan more than 14 GB VRAM. Quantised files use less; measure after load.

def vram_fit(params_b: float, bytes_per_param: float, overhead_gb: float, vram_gb: float) -> str:
    need = params_b * bytes_per_param + overhead_gb
    return "ok" if need <= vram_gb else "refuse-too-big"

print(round(7 * 2 + 2, 1))
print(vram_fit(7, 2.0, 2.0, 24.0))
print(vram_fit(70, 2.0, 4.0, 24.0))
assert vram_fit(7, 2.0, 2.0, 16.0) == "ok"

Expected output:

16.0
ok
refuse-too-big

Demo 3 — Stop each place

def stop_place(place: str) -> str:
    if place == "local":
        return "unload-and-power-off-or-deallocate"
    if place == "api":
        return "revoke-key-and-stop-job"
    return "unknown"

print(stop_place("local"))
print(stop_place("api"))
assert stop_place("local").startswith("unload")

Expected output:

unload-and-power-off-or-deallocate
revoke-key-and-stop-job

Guided practice: private data, small GPU

def pick_place(ticket: dict) -> str:
    if ticket.get("must_stay_on_box"):
        if ticket.get("vram_ok"):
            return "local"
        return "refuse-local-no-vram"
    if ticket.get("no_key_allowed"):
        return "refuse-api-no-key-policy"
    return "api"

print(pick_place({"must_stay_on_box": True, "vram_ok": False}))
assert pick_place({"must_stay_on_box": True, "vram_ok": False}) == "refuse-local-no-vram"

Expected output:

refuse-local-no-vram

The next move is not "send it to a public tab." It is a smaller local model, a quantised file, or a written private-region API.

Independent practice: 8-bit 7B on 12 GB

Deliverable: 8-bit is 1 byte per parameter. Print the fit result.

def vram_fit(params_b: float, bytes_per_param: float, overhead_gb: float, vram_gb: float) -> str:
    need = params_b * bytes_per_param + overhead_gb
    return "ok" if need <= vram_gb else "refuse-too-big"

print(vram_fit(7, 1.0, 2.0, 12.0))
assert vram_fit(7, 1.0, 2.0, 12.0) == "ok"

Expected output:

ok

Common mistake

The deliberate mistake

Symptom: the laptop fans scream, then the process is killed, then someone pastes the same prompt into a consumer tab.

Diagnosis: VRAM was never checked; the fallback ignored privacy.

Correction: fit the file first. If it does not fit, change the file or the place in writing, not in a panic paste.

Prevention: run vram_fit on the card before download. Keep customer text out of consumer tabs.

Snapshot — checked September 2026

Engines and cards move. Confirm the current install docs.

Where this connects

What you can now do:

  • Pick local vs API from constraints.
  • Fit a parameter count to VRAM.
  • Name how to stop each place.

Next lesson: Evaluate for your task. Twenty examples beat a screenshot of a leaderboard.