How to build an endpoint on Blueprint
Use endpoints in your Blueprint projects to build APIs backed by foundation models. You can build and test endpoints in the Blueprint IDE, then invoke them from anywhere.
In this tutorial, we're going to build an endpoint that uses Whisper to transcribe audio files. You'll need an API key to complete this tutorial.
Building an endpoint
Building an endpoint starts with defining a route using the
@route() decorator. Use this decorator to assign a URL to a function, like so:
You'll notice the
invoke-whisper route appear on the left sidebar and in the playground (more on that in a moment).
From there, we need to implement the actual function. Thanks to the
baseten.models package, we can use Whisper right out of the box for our endpoint. The whole function is just four lines of code:
After accessing the URL passed in the request body, our function calls Whisper and strips out the relevant text from the dictionary created by the model. The return value must be JSON-serializable, so we return a dictionary.
Invoking our new endpoint
We built this thing, let's take it for a test drive!
The fastest way to try out your endpoint is in the playground, which shows up at the bottom of your screen. Use the playground to quickly iterate as you develop your endpoints.
This endpoint will take a POST request, which you can select from the dropdown menu in the playground. To invoke this endpoint, use the following JSON:
The result of the invocation will show in the right side of the window. It should look like this:
Once you're satisfied with your endpoint, you can use it in any application. To invoke the endpoint outside of the Blueprint IDE, you'll need an API key.
PROJECT_ID for API invocation in the URL of your Blueprint project.
abcd0123 is your
Making the endpoint public
Let's say you want the whole world to be able to invoke your endpoint.
Be careful! Unsecured endpoints could receive substantial traffic or be used for malicious purposes. So be thoughtful about which endpoints you leave unsecured.
To make an endpoint public, pass
public=True to the route decorator, like so:
Then, you can invoke the endpoint in the same way, but without passing the API key.