0Pricing
MLOps Academy · Lesson

Your First /predict Endpoint

Load a model and return a prediction over HTTP.

Your First /predict Endpoint is a free MLOps Academy lesson on CoddyKit. This is lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the MLOps Academy learning path, and your progress syncs across the web and the CoddyKit app. The MLOps Academy course includes 4 lessons in total.

From Notebook to API

A model in a notebook helps only you. To serve real users, you wrap it in an API that anyone can call over the network. 🚀

Why FastAPI

FastAPI is a modern Python web framework that is fast to write, validates input for you, and auto-generates interactive docs.

Install It

You need two pieces: FastAPI itself and a server to run it. Install both with pip in one line.

pip install fastapi uvicorn

Create the App

Everything starts from one app object. You create a FastAPI instance and attach routes to it.

from fastapi import FastAPI

app = FastAPI()

What an Endpoint Is

An endpoint is a URL your app responds to, like /predict. Each one runs a Python function when someone calls it.

Load Your Model First

Before predicting, you load the trained model from disk. Here joblib reads a saved scikit-learn model into memory.

import joblib

model = joblib.load("model.joblib")

Declare the Route

You mark a function as a POST endpoint with a decorator. POST fits prediction because you send data in the request body.

@app.post("/predict")
def predict(features: list[float]):
    ...

Run the Prediction

Inside the function you call the model. predict expects a 2D input, so you wrap the row in a list before passing it.

pred = model.predict([features])
result = pred[0]

Return JSON

Whatever your function returns, FastAPI serializes to JSON automatically. Return a plain dict and the client gets clean JSON.

return {"prediction": result}

Start the Server

You launch the app with uvicorn, pointing it at the module and the app object. The reload flag restarts on code changes.

uvicorn main:app --reload

Try the Auto Docs

Visit /docs in your browser and FastAPI shows an interactive page where you can test /predict without writing any client code. 🎉

Quick Check

You want clients to send feature data to your model. Which HTTP method fits a /predict endpoint?

Recap

You wrapped a model in FastAPI: create the app, load the model, expose a POST /predict that returns JSON, and run it with uvicorn. That is a live API! 🙌

Frequently Asked Questions

Is the “Your First /predict Endpoint” lesson free?

Yes — the full text of “Your First /predict Endpoint” is free to read here on the web. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the MLOps Academy course, upgrade to CoddyKit PRO. The MLOps Academy course includes 4 lessons in total.

What will I learn in “Your First /predict Endpoint”?

Load a model and return a prediction over HTTP. You practise MLOps Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start MLOps Academy?

No prior experience is required. MLOps Academy on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 1 of 4.

How long does the “Your First /predict Endpoint” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this MLOps Academy lesson?

Yes. Every MLOps Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Your First /predict Endpoint
  2. Validate Requests with Pydantic
  3. Load the Model Once at Startup
  4. Add a /health Readiness Check
← Back to MLOps Academy