Get startedGet started for free

Health-check API for model loading

After loading the model at server startup, you need to develop a testing endpoint to build a monitoring system that can detect if the model is ready to analyze user comments.

In this exercise, you'll create a health check endpoint that allows you to verify your API's status and trigger alerts if the sentiment_model isn't available.

Note: sentiment_model is already pre-loaded for you.

This exercise is part of the course

Deploying AI into Production with FastAPI

View Course

Exercise instructions

  • Create a GET endpoint using the /health route.
  • Check if the sentiment_model is loaded by verifying the model variable against None.
  • Mark status as healthy and model_loaded as True in the response when the model is successfully loaded otherwise, mark status as unhealthy and model_loaded as False.
  • Open a terminal and start the server by running main.py using the command python3 main.py.
  • Open another terminal from the top right corner of the terminal to test the health endpoint using the curl command: curl -X GET "http://localhost:8080/health" -H "accept: application/json"

Hands-on interactive exercise

Turn theory into action with one of our interactive exercises

Start Exercise