> 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/deploy/supported-models/yolov9.md).

# YOLOv9

We support YOLOv9 object detection inferencing via our [Serverless Hosted API](/deploy/serverless-hosted-api-v2.md). Training YOLOv9 is not supported on Roboflow, but you can [upload pretrained weights](/deploy/upload-custom-weights.md) for an existing Project and serve them through the Serverless Hosted API.

For self-hosted deployment, see [Roboflow Inference](https://inference.roboflow.com/).

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

## Code sample

{% 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 inference-sdk supervision
```

{% endstep %}

{% step %}

### Run the model

This example runs Roboflow's public YOLOv9 model trained on [COCO](https://universe.roboflow.com/microsoft/coco) (`coco/18`), so it works as-is. To serve your own weights, swap in your `{workspace}/{model-slug}` ID (see [Versions, Trainings, and Models](/train/versions-trainings-and-models.md)).

```python
import os
import cv2
import numpy as np
import requests
import supervision as sv
from inference_sdk import InferenceHTTPClient

content = requests.get("https://media.roboflow.com/quickstart/traffic.jpg").content
image = cv2.imdecode(np.frombuffer(content, np.uint8), cv2.IMREAD_COLOR)

client = InferenceHTTPClient(
    api_url="https://serverless.roboflow.com",
    api_key=os.environ["ROBOFLOW_API_KEY"],
)
result = client.infer(image, model_id="coco/18")

detections = sv.Detections.from_inference(result)

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

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

<figure><img src="/files/M548Ad7NmsqTwg9G50LZ" alt=""><figcaption></figcaption></figure>
{% endstep %}
{% endstepper %}

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

* `https://serverless.roboflow.com` for the Serverless Hosted API.
* `http://localhost:9001` for a local [Inference](https://inference.roboflow.com/) server.
* Your [Dedicated Deployment](/deploy/dedicated-deployments.md) URL for a private endpoint.
  {% endhint %}
