Accessing Request Headers From Predict
Introduction
This guide shows how to access request headers from the predict method of a custom model. This is useful if you want to pass additional information to your model at inference time. For example, you may want to JWT tokens into your prediction in order to authenticate secondary processes.
This feature is entirely optional; you can continue defining predict()
methods without including the headers
parameter.
This feature requires the 2023_07
release of the Verta platform.
Prerequisites
Before you can use the model schema feature, you must meet the following prerequisites:
Verta Python library (version 0.24.0 or higher):
pip install "verta>=0.24.0"
.
Getting Started
To access request headers from the predict method, follow these steps:
Import the necessary libraries:
Create a Model class that subclasses Verta's
VertaModelBase
and defines thepredict()
method with the newheaders
parameter:In the
predict()
method, you should replace the example code with your own prediction logic that uses your trained model to make predictions on the input data.Create a new model version and deploy it to an endpoint:
In this step, you should replace "My Model" with the name of your registered model, "my-model" with the name of the endpoint you want to deploy the model to, and customize the requirements parameter of the Python environment to fit your model's needs.
Make prediction cURLs. Here is an example with the
Grpc-Metadata-Bearer-Access-Token
header:In this step, you should replace
<ACCESS_TOKEN>
with your Verta access token,<VERTA_DOMAIN>
with your Verta domain,<INPUT_BODY>
with your input request body, and<JTW_TOKEN>
with your JWT token. Add additional headers as needed.
At this time, headers can be passed into the predict method via cURLs but not via the Verta client.
Last updated