All insights

Using FastAPI and Machine Learning to Predict Delivery Prices in Real Time

VAF UBWENGE TECH12 March 2026

A deep dive into the AI pricing engine behind Easy GO — how we collect geospatial data, train our model, and serve predictions in under 200ms using FastAPI deployed on the cloud.

Why We Needed a Custom Pricing Model

Delivery pricing in Kigali is not linear. A 2km trip across flat terrain in the morning costs very differently from a 2km trip up a hill during peak hours. Standard rate cards could not capture this complexity, so we built our own model.

Our goal was a system that could ingest route data and return a fair, explainable price in real time — something both drivers and customers could trust because it was consistent and based on real data, not negotiation.

Data Collection: Learning from the Streets

Before writing a single line of model code, we spent weeks in the field. Our team rode with moto drivers across all three Kigali districts, recording origin, destination, distance, time, and agreed fare for hundreds of trips.

We also collected elevation data using the Google Elevation API, because Kigali is famously hilly and gradient has a real effect on fuel cost and driver effort. That data became one of our strongest predictive features.

The Model: Gradient Boosting on Route Features

We tested several algorithms — linear regression, random forest, and gradient boosting. Gradient boosting consistently outperformed the others on our validation set, achieving a mean absolute error of under 150 RWF on most routes.

Our feature set includes straight-line distance, road distance from Google Maps, elevation change, time of day, day of week, and package weight category. We retrain the model monthly as new delivery data accumulates.

Serving Predictions with FastAPI

The trained model is serialized with joblib and loaded into a FastAPI application at startup. A single POST endpoint accepts origin and destination coordinates plus weight category, calls the Google Maps Distance Matrix API, then passes all features to the model and returns a price estimate.

End-to-end latency from request to response averages under 200ms. We deployed the FastAPI app on a cloud server with auto-scaling so it handles demand spikes during busy delivery hours.

What Makes It Fair

Price prediction is only useful if users trust it. We made the pricing transparent by showing users the breakdown: base fare, distance component, and any time-of-day adjustment. No hidden fees.

Drivers also see the estimated fare before accepting a delivery, which reduced disputes significantly during our pilot. When both sides see the same number generated by the same logic, the negotiation problem disappears.

  • Engineering

Read next