Hosted API (Remote Server)
Leverage your custom trained model for cloud-hosted inference.

Overview

Each model trained with Roboflow Train is deployed as a custom API you can use to make predictions from any device that has an internet connection. Inference is done on the server so you don't need to worry about the edge device's hardware capabilities.
We automatically scale this API up and down and do load balancing for you so that you can rest assured that your application will be able to handle sudden spikes in traffic without having to pay for GPU time you're not using. Our hosted prediction API has been battle-hardened to handle even the most demanding production applications (including concurrently surviving through the famous Hacker News and Reddit "hugs of death" without so much as batting an eye).

The Example Web App

The easiest way to familiarize yourself with the inference endpoint is to visit the Example Web App. To use the Web App, simply input your model , version and api_key. These will be pre-filled for you after training completes if you click through via the web UI under your versions "Training Results" section.
Then select an image via Choose File. After you have chosen the settings you want, click Run Inference.
On the left side of the screen, you will see example JavaScript code for posting a base64-encoded image to the inference endpoint. Within the form portion of the Web App, you can experiment with changing different API parameters when posting to the API.
post
https://classify.roboflow.com
/:datasetSlug/:versionNumber
Using the Inference API

Code Snippets

For your convenience, we've provided code snippets for calling this endpoint in various programming languages. If you need help integrating the inference API into your project don't hesitate to reach out.
All examples upload to an example dataset with a model-endpoint of your-dataset-slug/your-version. You can easily find your dataset's identifier by looking at the curl command shown in the Roboflow web interface after your model has finished training.
Python
Javascript

Uploading a Local Image

To install dependencies, pip install requests pillow
1
import requests
2
import base64
3
import io
4
from PIL import Image
5
6
# Load Image with PIL
7
image = Image.open("YOUR_IMAGE.jpg").convert("RGB")
8
9
# Convert to JPEG Buffer
10
buffered = io.BytesIO()
11
image.save(buffered, quality=90, format="JPEG")
12
13
# Base 64 Encode
14
img_str = base64.b64encode(buffered.getvalue())
15
img_str = img_str.decode("ascii")
16
17
# Construct the URL
18
upload_url = "".join([
19
"https://classify.roboflow.com/your-model/42",
20
"?api_key=YOUR_KEY",
21
"&name=YOUR_IMAGE.jpg"
22
])
23
24
# POST to the API
25
r = requests.post(upload_url, data=img_str, headers={
26
"Content-Type": "application/x-www-form-urlencoded"
27
})
28
29
# Output result
30
print(r.json())
Copied!

Node.js

We're using axios to perform the POST request in this example so first run npm install axios to install the dependency.

Inferring on a Local Image

1
const axios = require("axios");
2
const fs = require("fs");
3
4
const image = fs.readFileSync("YOUR_IMAGE.jpg", {
5
encoding: "base64"
6
});
7
8
axios({
9
method: "POST",
10
url: "https://classify.roboflow.com/your-model/42",
11
params: {
12
api_key: "YOUR_KEY"
13
},
14
data: image,
15
headers: {
16
"Content-Type": "application/x-www-form-urlencoded"
17
}
18
})
19
.then(function(response) {
20
console.log(response.data);
21
})
22
.catch(function(error) {
23
console.log(error.message);
24
});
Copied!
Last modified 3mo ago