vetiver_endpoint returns the `GET` / instead of `POST` /predict even when defining correct URL/Server location
Closed this issue · 3 comments
Hello,
I've been developing a few models and have been able to deploy all of them to Posit Connect successfully. The documentation on all of this is very clear so a quick thanks to those who worked on it! :)
Having said that, I'm having trouble actually making predictions once the model has been deployed onto the server.
Essentially I deploy a model using the following methodology.
v <- vetiver_model(final_fit_to_deploy, model_name = "SOME_NAME")
model_board <- pins::board_connect(auth = "manual", server = "https://connect.COMPANY.com/", key = "API KEY", versioned = TRUE)
model_board |> vetiver_pin_write(v)
model_board |>
vetiver::vetiver_write_plumber("USER.NAME/SOME_NAME")
vetiver_deploy_rsconnect(
model_board, "USER.NAME/SOME_NAME"
)
Once deployed the vetiver page on Posit Connect generates correctly and I can easily test my api POST (predict).
The issue occurs whenever I attempt to use the vetiver_endpoint()
function. For some reason whenever I try to do this it detects the correct URL (supposedly)
endpoint<- vetiver_endpoint("https://connect.COMPANY.com/PAGENAME/predict")
This returns the text: A model API endpoint for prediction:
as well as the url you input above.
When I use the predict function on this endpoint I receive the following error.
Error: lexical error: invalid char in json text.
<!DOCTYPE html> <html lang="en-
(right here) ------^
After lots of digging around trying to understand what was going on and where this was coming from, I realised that this response was actually the default /
response as stated in the vetiver page where the api is deployed.
This documentation states:
This endpoint was added to automatically redirect visitors to the API documentation by default
This endpoint was added to automatically redirect visitors to the API documentation by default. Define a base handler (i.e.: "GET /"), to prevent the addition of this redirect endpoint.
So overall I have two question:
- Why is it directing me towards this url even when I've defined that I want the
/predict
using the server URL. - If needed, how do I define a base handler to prevent the redirect endpoint?
Thanks!
Hansel
You are creating your endpoint correctly so there is no issue with that. ✅
Why is it directing me towards this url even when I've defined that I want the
/predict
using the server URL
I am guessing that what is happening here is that you need to send authentication details to call this API. On Posit Connect, you can set the API's access to "Anyone" so that no authentication is needed, but sometimes you want the API to require authentication. In that case, you need to pass those in, as shown in these docs.
That was exactly right! Thanks for the assist.
When I added my api key it returned the classification as expected.
I spent ages and couldn't find this anywhere, do you think it's worth adding both use cases (Anyone vs. Authorised) to the actual Vetiver docs pages instead of Posit Connect? I'm sure I'm not the only one that has faced this problem!
Either way, thanks for your support on this and amazing package!
Oh, that sounds super frustrating @HanselPalencia! That's a great idea to surface this information in the vetiver docs itself, rather than only the Connect docs. I added some details in #244 that will show up on this page.