This is part of the original four-sample CPU sequence, separate from the redesigned nine-week track. Sample numbers are not week numbers.
The model stays where it is.
Imagine putting a small interface in front of your model: a button, a text box, and an answer. Does the computer showing that interface need PyTorch? Does every user need a copy of the weights? No. The client needs to speak HTTP. The server owns the computation.
curl ────────┐
Python ──────┼── JSON over HTTP ──→ FastAPI ──→ loaded model
JavaScript ──┘ │
←──── JSON response ─────┘Start with one computer and multiple terminals. Keep lesson 2’s server running on 127.0.0.1:8000. If it stopped, use lesson 2’s startup command. Work from the downloaded lab folder with its Python environment activated. The JavaScript example uses Node.js 24 with built-in fetch.
Run each client.
source .venv/bin/activate
export MODEL_SERVER_URL="http://127.0.0.1:8000"
bash lessons/03-clients-and-lan/clients/curl_client.sh
python lessons/03-clients-and-lan/clients/python_client.py
node lessons/03-clients-and-lan/clients/javascript_client.mjsRun them one at a time and wait for each response. Each program sends a prompt and asks for up to 50 new tokens. You should see three JSON responses and three completed POST requests in the server terminal.
Open the Python and JavaScript files side by side. Both read the destination from MODEL_SERVER_URL, send JSON, check the HTTP response, parse its body, and print it. Different languages, same agreement with the server.
response = requests.post(
f"{base_url}/generate",
json={"prompt": "Give me three names for a coffee shop.",
"max_new_tokens": 50},
timeout=60,
)
response.raise_for_status()
data = response.json()response.json() turns the response body into a Python value. Pretty-printing adds indentation for you to read; it doesn’t change the answer. A 60-second timeout limits the client’s wait. It does not guarantee that a request already running on the server stops computing.
Where would you install Transformers on a second client computer?
Check your reasoning
You wouldn’t need it there. The Python client needs Requests; the JavaScript client needs Node with fetch. Only the server needs the model and its inference dependencies. The saved shell client uses Python 3 just to format JSON.
Don’t just watch the answers. Count the work.
curl --silent --show-error --connect-timeout 5 --max-time 5 http://127.0.0.1:8000/metricsThe server exposes measurements at /metrics. They belong to the running process and reset when it restarts. Take a baseline, make three requests, and compare the totals.
python lessons/03-clients-and-lan/show_generation_metrics.py
bash lessons/03-clients-and-lan/clients/curl_client.sh
python lessons/03-clients-and-lan/clients/python_client.py
node lessons/03-clients-and-lan/clients/javascript_client.mjs
python lessons/03-clients-and-lan/show_generation_metrics.pyWith no other generation traffic and all three calls succeeding, each displayed counter should increase by three: accepted generation attempts, successful generations, and completed HTTP 200 responses for POST /generate. Starting at zero isn’t important; the difference is.
Why three counters? They measure different events. A malformed request can produce an HTTP response without entering generation. A generation attempt can fail. Counting every HTTP request as a successful inference would hide those distinctions.
Try the missing-prompt request from lesson 2, then inspect /metrics. You should get an HTTP 422 count without another generation attempt. Scraping metrics itself doesn’t run the model or increment application traffic counters in this lab. The separate timing around model.generate excludes prompt formatting and decoding; HTTP timing includes more of the request path.
Optional: put the client on another computer.
Use two computers on the same trusted Wi-Fi. The first remains the server. Stop its current Uvicorn process with Control-C and restart it with this binding:
python -m uvicorn server:app --app-dir lessons/02-simple-server --host 0.0.0.0 --port 80000.0.0.0 means listen on all IPv4 interfaces, subject to firewall and network rules. It is not the address you give a remote client. Find the server’s Wi-Fi IPv4 address in macOS System Settings → Wi-Fi → Details → TCP/IP.
export MODEL_SERVER_URL="http://192.168.1.25:8000"
curl --connect-timeout 5 --max-time 5 "$MODEL_SERVER_URL/health"
curl --connect-timeout 5 --max-time 60 \
"$MODEL_SERVER_URL/generate" -H "Content-Type: application/json" \
-d '{"prompt":"Hello from another computer.","max_new_tokens":30}'The client needs no model download. For the saved clients, copy the lab source to it; install Requests for Python or Node for JavaScript. Set the URL in the same terminal where you run the client. Leaving it at 127.0.0.1 would ask the client computer to call itself.
python3.13 -m venv .venv
source .venv/bin/activate
python -m pip install requests==2.34.2
python lessons/03-clients-and-lan/clients/python_client.pyKeep this unauthenticated experiment on your intended trusted network. Don’t forward a router port or expose it publicly. If it fails, check the destination, server startup, binding, firewall, and local-network permission in that order. The download includes a troubleshooting guide. Don’t disable the firewall wholesale to make a request work.
You restart the server and the counters shrink. Did requests disappear?
Check your reasoning
The counters lived in the old process’s memory. Restarting creates a new baseline. Historical storage and dashboards are separate work; these raw measurements aren’t a persistent monitoring system.
What happens when you leave home Wi-Fi?
The server’s home-network address usually stops being reachable. The model is still running; the client has lost the path to it. That gives us two questions for lesson 4: how do we reach the server privately across networks, and which requests should it accept?