Hugging Face has democratized access to state-of-the-art ML models. When you need to interact with these models via an API, a robust client is essential.
Enter Bruno, a modern, open-source API client that simplifies this interaction. In this post, we’ll walk through how Bruno makes hitting Hugging Face Inference Endpoints easy.
Let’s dive in!
These two make a great team:
Together, Hugging Face provides the powerful models, and Bruno offers an efficient way to interact with them via their APIs, streamlining your ML workflow.
To follow along with this guide, you'll need a couple of things:
For this tutorial, we'll use a popular sentiment analysis model: distilbert-base-uncased-finetuned-sst-2-english
. This model takes text as input and tells us whether it's positive or negative.
First, let's organize our requests in Bruno:
Hugging Face API Interactions
It's best practice never to hardcode API keys directly into your requests. Bruno's environments are perfect for this.
Hugging Face Dev
.HUGGING_FACE_API_TOKEN
Now, let's create the request to call our sentiment analysis model:
Hugging Face API Interactions
collection in the sidebar.Sentiment Analysis - DistilBERT
.POST
as the method.https://api-inference.huggingface.co/models/distilbert/distilbert-base-uncased-finetuned-sst-2-englishhttps://api-inference.huggingface.co/models/distilbert-base-uncased-finetuned-sst-2-english
We need two headers for this request: one for authentication and one to specify the content type.
Name: Authorization
Value: Bearer
Name: Content-Type
Value: application/json
The Hugging Face Inference API expects a JSON payload.
JSON
radio button.{
"inputs": "Hugging Face and Bruno make an amazing team for machine learning workflows!"
}
You're all set!
Hugging Face Dev
environment is selected from the dropdown (usually in the top right or bottom left corner of the request editor).Bruno will send the request to Hugging Face, and you'll see the model's response appear in the response pane:
[
[
{
"label": "POSITIVE",
"score": 0.999862790107727
},
{
"label": "NEGATIVE",
"score": 0.00013718708942178637
}
]
]
Success! The model correctly identified our input sentence as "POSITIVE" with a very high confidence score.
We’ve published the full working collection on GitHub. You can either clone this, or simply click the Fetch in Bruno button below!
Hugging Face has transformed how we access and use state-of-the-art AI. By pairing it with Bruno, you gain an efficient, organized, and Git-friendly way to interact with those models via their APIs.
Whether you're a data scientist testing a new model, a developer integrating AI into an application, or an ML engineer debugging a deployed service, this powerful combination will undoubtedly boost your productivity.
Ready to try it yourself?
Happy API calling! 🚀