> For the complete documentation index, see [llms.txt](https://docs.roboflow.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.roboflow.com/models/supported-models/yolov5.md).

# YOLOv5

We support YOLOv5 object detection and instance segmentation inferencing via our [Serverless Cloud API](https://docs.roboflow.com/deployment/roboflow-cloud/serverless-api) and self-hosted [Inference](https://docs.roboflow.com/deployment/self-hosted/self-hosted). Training YOLOv5 is not supported on Roboflow, but you can [upload pretrained weights](/models/model-weights/upload-custom-weights.md) (`model_type="yolov5"`) for an existing Project and serve them through any deployment target. For a Roboflow-trained detector, see [RF-DETR](/models/supported-models/rf-detr.md), [YOLO26](/models/supported-models/yolo26.md), or [YOLO11](/models/supported-models/yolo11.md).

YOLOv5 input size is set when you train your model outside Roboflow (typical values: 640x640 or 1280x1280).

## YOLOv5 API

{% stepper %}
{% step %}

### Get your API Key

Create a Roboflow account, find your key on the [Roboflow API settings page](https://app.roboflow.com/settings/api) and make it available to your shell:

```bash
export ROBOFLOW_API_KEY="your-key-here"
```

{% endstep %}

{% step %}

### Install the dependencies

Install the SDK and [supervision](https://supervision.roboflow.com/) for decoding and annotation:

```bash
pip install -U inference-sdk supervision
```

{% endstep %}

{% step %}

### Run the model

Swap in the `{workspace}/{model-slug}` ID of your uploaded YOLOv5 model (see [Versions, Trainings, and Models](/models/versions-trainings-and-models.md)).

```python
import os
import cv2
import supervision as sv
from inference_sdk import InferenceHTTPClient

image = sv.load_image_from_url("https://media.roboflow.com/quickstart/traffic.jpg")

client = InferenceHTTPClient(
    api_url="https://serverless.roboflow.com",
    api_key=os.environ["ROBOFLOW_API_KEY"],
)
result = client.infer(image, model_id="your-workspace/your-model-slug")

detections = sv.Detections.from_inference(result)

annotated = sv.BoxAnnotator().annotate(image.copy(), detections)
annotated = sv.LabelAnnotator().annotate(annotated, detections)

cv2.imwrite("annotated.png", annotated)
```

{% endstep %}
{% endstepper %}

{% hint style="info" %}
Set `api_url` to match your deployment target:

* `https://serverless.roboflow.com` for the Serverless Cloud API.
* `http://localhost:9001` for a local [Inference](https://docs.roboflow.com/deployment/self-hosted/self-hosted) server.
* Your [Dedicated Deployment](https://docs.roboflow.com/deployment/roboflow-cloud/dedicated-deployments) URL for a private endpoint.
  {% endhint %}
