Testing Smart Nutrition API


Introduction
A smart nutrition API that fetches the nutritional information from pictures of labelled products. As we will see next, the API returns somewhat close nutritional metrics compared to the actual labels at around 3.0% error rate.
The technical details are mentioned in the GitHub documentation and with the docker image and instructions present in the DockerHub. There is also a comprehensive and experimental guide to setup Kubernetes cluster and deploy the API container in a pod.
Following are minimalistic examples of development.yaml
and service.yaml
for K8s deployment:
# development.yaml - fill the following required API keys as env variable.
apiVersion: apps/v1
kind: Deployment
metadata:
name: nutrition-api
spec:
replicas: 1
selector:
matchLabels:
app: nutrition-api
template:
metadata:
labels:
app: nutrition-api
spec:
containers:
- name: nutrition-api
image: tkdutta/smart-nutrition-api:v1
ports:
- containerPort: 5000
env:
- name: GOOGLE_API_KEY
value: ""
- name: GROQ_API_KEY
value: ""
# service.yaml
apiVersion: v1
kind: Service
metadata:
name: nutrition-api-service
spec:
type: NodePort
selector:
app: nutrition-api
ports:
- protocol: TCP
port: 80
targetPort: 8000
nodePort: 30007
Short description of the endpoints
Here is a simple refresher of the endpoints of the API (with more details is the baove mentioned documentations):
/product-name
: Extract product name from an uploaded image.Payload: Form-data with key “product” as the image file.
Returns:
json
file with the extracted product name.
/nutrition
: Get nutritional information for a given product name. Returns ajson
file.Payload: Value from the
/product-name
output.Returns:
json
file with it’s nutritional values.
Using the API
Passing the following image in the
/product-name
endpoint.We get the following
json
output based on the above image provided:{ "name": "dairymilk silk oreo" }
Passing the above product name in the
/nutrition
endpoint to get the following output:{ "data": { "Nutritional Content": { "Added Sugars": "40.5 g", "Carbohydrates": "56.5 g", "Cholesterol": "13.7 mg", "Energy": "559 kcal", "Protein": "6.1 g", "Saturated Fat": "21.15 g", "Sodium": "212 mg", "Total Fat": "34.85 g", "Total Sugars": "48.6 g", "Trans Fat": "0.15 g" } }, "heading": "Nutritional Content of Cadbury Dairy Milk Silk Oreo per 100g" }
Validating the output
Let’s validate the output with the actual label in the product:
Nutritional contents | API output (per 100 g) | Label (per 100 g) | Error % |
Energy | 559.0 kcal | 563.0 kcal | 0.7 % |
Carbohydrates | 56.5 g | 56.9 g | 0.7 % |
Protien | 6.1 g | 6.0 g | -1.67 % |
Sugars | 48.6 g | 48.9 g | 0.6 % |
Total Fat | 34.85 g | 34.8 g | -0.14 % |
Saturated Fat | 21.15 g | 22.3 g | 0.67 % |
Sodium | 212.0 mg | 207.0 mg | -2.42 % |
Cholesterol | 13.7 mg | 17.4 mg | 21.26 % |
Therefore, the Mean Absolute Percentage Error (MAPE) of the above is ~3.8%
Performing the same analysis for multiple products across various brands give an average error rate of ~3.0%
Governance, Trust & Disclaimer
Nutrition data is approximate and may differ from actual food content. Use as guidance, not as medical advice.
Not a medical-grade app. For general use only and is not to be considered as ultimate source of truth without proper research.
Data is extracted through general internet scraping.
To be treated like a navigation app - great for guidance, but not a substitute for a doctor’s prescription or lab-tested food assay.
Future Prospects
Develop a mobile UI app (Android) wrapped around the API.
Enable users to scan product labels in real time (e.g., in supermarkets or malls).
Provide instant nutritional information fetched via the API.
Allow side-by-side comparison of nutritional values across multiple products.
Make nutrition tracking more accessible and practical for everyday choices.
Subscribe to my newsletter
Read articles from Tuhin Kumar Dutta directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Tuhin Kumar Dutta
Tuhin Kumar Dutta
I decode data, craft AI solutions, and write about everything from algorithms to analytics. Here to share what I learn and learn from what I share. 🚀 Data Scientist | AI Enthusiast | Building intelligent systems & simplifying complexity through code and curiosity. Sharing insights, projects, and deep dives in ML, data, and innovation.