Use with Python SDK

Use Roboflow's Serverless Hosted API with Python SDK

If you are working in Python, the most convenient way to interact with the Serverless API is to use the Inference Python SDK.

To use the Inference SDKarrow-up-right, first install it:

pip install inference-sdk

To make a request to the Serverless Hosted API, use the following code:

from inference_sdk import InferenceHTTPClient

CLIENT = InferenceHTTPClient(
    api_url="https://serverless.roboflow.com",
    api_key="API_KEY"
)

result = CLIENT.infer("image.jpg", model_id="model-id/1")
print(result)

Above, specify your model IDarrow-up-right and API keyarrow-up-right. This code will run your model and return the results.

Roboflow Instant Model

Serverless API also supports running Roboflow Instant Model. You can run Instant Model just like any other model, just note that the confidence threshold can be sensitive for Instant Models.

circle-info

An optimal confidence depends on the number of images the model has been trained on. Optimal confidence thresholds usually range from 0.85 to 0.99.

configuration = InferenceConfiguration(
    confidence_threshold=0.95
)
CLIENT.configure(configuration)

result = CLIENT.infer("image.jpg", model_id="roboflow-instant-model-id/1")

Last updated

Was this helpful?