Custom HTTP Status Codes

It's possible to return a custom HTTP status from the predict function. Note that, only 4xx and 5xx statuses are supported.

To use the feature, you have to raise a QwakHTTPException inside the predict function. The exception accepts two parameters:

  • HTTP status code (as a number)
  • the message to be returned (string or a dictionary)

If the message is a string, it will be returned as a JSON object in this format: {"message": "YOUR_MESSAGE"}. If it's a dictionary, the Qwak platform will return the entire dictionary as a JSON object.

If an unsupported HTTP status is used, it will be replaced with the status 500 and a qwak_backend_message will be added to the response body with a message: "Invalid status code. Given value: {status_code}. Supported: 4xx, 5xx".

An example server-side code:

def predict(self, df):
    if cant_handle_the_request:
        raise QwakHTTPException(500, "Not implemented")

In case of a 4xx or 5xx response from the deployed model, the RealTimeClient will raise a QwakHTTPException with the status code and the returned message.

An example of the client code:

client = RealTimeClient(model_id="YOUR_MODEL")
except QwakHTTPException as e:

Qwak Analytics and custom HTTP statuses

If the model raises a QwakHTTPException (and the API analytics feature is enabled), the exception details will be logged in Qwak Analytics as columns: interence_exception_status_code and inference_exception_message.