Use Vision Transformer (ViT) classification models trained on Roboflow through the Serverless Cloud API.
ViT API
1
Get your API Key
Create a Roboflow account, find your key on the Roboflow API settings page and make it available to your shell:
export ROBOFLOW_API_KEY="your-key-here"2
Install the dependencies
This package calls the model:
pip install -U inference-sdk supervision3
Run the model
Call your trained ViT classifier by its {workspace}/{model-slug} ID (see Versions, Trainings, and Models).
import os
import supervision as sv
from inference_sdk import InferenceHTTPClient
image = sv.load_image_from_url("https://media.roboflow.com/notebooks/examples/dog.jpeg")
client = InferenceHTTPClient(
api_url="https://serverless.roboflow.com",
api_key=os.environ["ROBOFLOW_API_KEY"],
)
# No pretrained aliases: train your own model and replace "your-project/1" with your model ID.
results = client.infer(image, model_id="your-project/1")
print(results)Set api_url to match your deployment target:
https://serverless.roboflow.comfor the Serverless Cloud API.http://localhost:9001for a local Inference server.- Your Dedicated Deployment URL for a private endpoint.
For self-hosted deployment and additional details, see the Inference documentation.