Deploy a Model as a REST API
Part of the Machine Learning Roadmap
In short
Take a model you trained and put it on the internet with a real URL, input checks, a health check and a Docker image. Recruiters love seeing a link that actually works.
Take a trained model all the way to a live REST API: save the pipeline, serve it with FastAPI, package it in Docker and deploy it to a cloud host. This project proves you can ship ML, not just train it.

Think of it like this
Opening your own chai stall
A good recipe at home isn't a business. You need a stall, a fixed menu, set hours and a way to handle the customer who orders something you don't make. Deploying a model is opening the stall: a clear menu (API), opening hours (uptime) and polite refusals (validation).
Watch it happen
Build plan
1/6Train a model, save it with joblib and record the library versions you used.
The big ideas
What you need to know
Strict input checks
Reject impossible inputs, like a 5 sq ft flat, before they reach the model.
Return the version
Include the model version in every response so you know which model gave which answer.
Health and docs
A /health route for the host, and the auto /docs page so anyone can try your API.
A good README
Show a sample curl request, the response and the live URL. This is what reviewers read first.
See it in code
Walk through the code
1from fastapi import FastAPI2from pydantic import BaseModel, Field3import joblib4 5app = FastAPI()6model = joblib.load("house_price.joblib")7 8class House(BaseModel):9 area_sqft: float = Field(gt=100, lt=20000)10 bedrooms: int = Field(ge=0, le=10)11 city_tier: int = Field(ge=1, le=3)12 13@app.post("/predict")14def predict(h: House):15 price = model.predict([[h.area_sqft, h.bedrooms, h.city_tier]])[0]16 return {"price_lakh": round(float(price), 2), "model_version": "v1"}1/3Each field has sensible limits. FastAPI rejects anything outside them automatically.
The trickiest bit is honest validation. Field limits turn nonsense inputs into a clear 422 error instead of a silly price.
Save yourself the pain
Common mistakes
Oops
Feeding features to predict in a different order from training.
Do this instead
Keep one list of feature names and build the input from it, in both training and serving.
Oops
Deploying with no tests and finding the bug from a user.
Do this instead
Add two or three request tests with FastAPI's TestClient and run them before every deploy.
Your mission
First milestone: a working local API
Quick check
A request sends area_sqft = -20. With the code above, what happens?
Go deeper
- 1Deploy to a free or low-cost host such as Render, Railway or a cloud free tier.
- 2Add a /health endpoint and simple request logging.
- 3Document example requests and responses in the README.
Stuck on this topic? Ask an Insider
Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.