Contents
Model Deployment and AI APIs
What Is Model Deployment?
Model deployment is the process of making a trained AI model available for use by an application or end user.
For example, a company may train a model to predict house prices and expose it through an API. A website can then send property details to the API and receive a prediction.
Common deployment options include:
- REST APIs: Allow applications to communicate with a model over HTTP.
- Cloud services: Host models on managed infrastructure.
- Edge deployment: Run models on devices such as phones, cameras, or embedded systems.
- Batch inference: Generate predictions for large collections of records at scheduled intervals.
- Local inference: Run models on a developer's computer or an organization's own server.
The right deployment method depends on latency, cost, privacy, scalability, and infrastructure requirements.
Building a Simple Prediction API
FastAPI is a Python framework for creating APIs. It can expose a trained machine learning model through an HTTP endpoint.
Install the required packages:
pip install fastapi uvicorn scikit-learn
Create a file named app.py:
from fastapi import FastAPI
from pydantic import BaseModel
from sklearn.datasets import load_iris
from sklearn.ensemble import RandomForestClassifier
app = FastAPI()
# Train a simple demonstration model
data = load_iris()
model = RandomForestClassifier(random_state=42)
model.fit(data.data, data.target)
class FlowerInput(BaseModel):
sepal_length: float
sepal_width: float
petal_length: float
petal_width: float
@app.post("/predict")
def predict(flower: FlowerInput):
features = [[
flower.sepal_length,
flower.sepal_width,
flower.petal_length,
flower.petal_width
]]
prediction = int(model.predict(features)[0])
return {
"predicted_class": data.target_names[prediction]
}
Run the application:
uvicorn app:app --reloadOpen http://127.0.0.1:8000/docs in your browser to test the API interactively.
Understanding the Workflow
- FastAPI creates an HTTP endpoint.
- The application receives numerical input through a request.
- The model generates a prediction.
- The API returns the result as JSON.
This example trains the model when the application starts. For production systems, models are commonly trained separately, saved as versioned artifacts, and loaded during startup.
A production API should also include suitable validation, error handling, authentication where required, logging, and resource limits.
Artificial Intelligence Tutorial
Vishalini A








