> 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/deployment/monitoring-and-analytics/model-monitoring.md).

# Model Monitoring

A guide to Model Monitoring with Roboflow.

## About

Roboflow's Model Monitoring dashboard shows how your models perform, from prototyping through production. You can view high-level statistics over time, or open individual inference requests to see how your models handle edge cases.

{% hint style="info" %}
Model Monitoring will be deprecated and replaced by Vision Events. See [Vision Events documentation](/deployment/monitoring-and-analytics/vision-events.md) for additional information.
{% endhint %}

Model Monitoring records inference requests made with Roboflow's Cloud API or the Roboflow Inference Server, as long as the Inference Server has internet access. This includes edge deployments that use Roboflow's [License Server](https://blog.roboflow.com/roboflow-license-server/).

You can attach custom metadata to an inference (ex: where the image was taken, or the expected prediction) and pull Model Monitoring statistics into other systems. Both use the [HTTP API](#http-api).

You and your team can subscribe to email alerts when something goes wrong (ex: your model's confidence suddenly drops, or your Inference Server goes down and your model stops running).

{% content-ref url="/pages/HOY6XbrDDPvOqUU40vpd" %}
[Alerting](/deployment/monitoring-and-analytics/model-monitoring/alerting.md)
{% endcontent-ref %}

### Inference Images

Model Monitoring does not save inference images by default. There are two ways to save them:

* Roboflow Dataset Upload block: in a Workflow, add a "Roboflow Dataset Upload" block and connect the predictions and the prediction image.

<figure><img src="https://1583372177-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoksNmwps1HmYr8TqHDnX%2Fuploads%2Fgit-blob-2e0fe2213137512f9d235bb38ecce7c3463998ef%2Fimage%20(367).png?alt=media" alt="" width="151"><figcaption></figcaption></figure>

* Active Learning: configure [Active Learning](/deployment/monitoring-and-analytics/active-learning.md) rules in your Project to collect production inference images automatically.

<figure><img src="https://1583372177-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoksNmwps1HmYr8TqHDnX%2Fuploads%2Fgit-blob-2dd831a903dc127197efcec47e81026339de962c%2Fimage%20(327).png?alt=media" alt="" width="198"><figcaption></figcaption></figure>

{% hint style="info" %}
Images saved by Active Learning or Dataset Upload count the same as uploading an image to your project. Credit, limit or quota usage may apply according to your plan type.
{% endhint %}

## Web App

Open the "Models" dropdown in your Workspace navigation and select "Model Monitoring".

The dashboard shows total requests, average confidence, and average inference time across all models. Inference time includes image preprocessing. Each % change compares the selected time range with the period before it. The default range is the last week.

<figure><img src="https://1583372177-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoksNmwps1HmYr8TqHDnX%2Fuploads%2Fgit-blob-00a88ae4ffc0ffb5c7cc150479aec32f8dc2c12d%2Fimage%20(324).png?alt=media" alt=""><figcaption></figcaption></figure>

The Models table lists every model that has inferences. Click a model to see the same statistics for that model, plus the number of detections per class. Other tabs show recent inferences across all models and your [alerts](/deployment/monitoring-and-analytics/model-monitoring/alerting.md).

<figure><img src="https://1583372177-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoksNmwps1HmYr8TqHDnX%2Fuploads%2Fgit-blob-ecac74de3be1e2b8edb1a48dd17c3a89edf86155%2Fimage%20(326).png?alt=media" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1583372177-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoksNmwps1HmYr8TqHDnX%2Fuploads%2Fgit-blob-0baf9cb0b75c74c2b341606235b7b5cd89bd9e59%2FScreenshot%202024-05-23%20at%2020.44.57.png?alt=media" alt=""><figcaption></figcaption></figure>

Click "See All Inferences" to open the Inferences table, which also shows any custom metadata on each inference.

<figure><img src="https://1583372177-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoksNmwps1HmYr8TqHDnX%2Fuploads%2Fgit-blob-c0e48d4b2d25fea504b7eb38ecfc3a0ce664c5b5%2FScreenshot%202024-05-23%20at%2020.50.13.png?alt=media" alt=""><figcaption></figcaption></figure>

Click an inference to see its image, request details, and detections. The image appears only if you [save inference images](#inference-images). Fields you hide in the details panel stay hidden in that browser.

<figure><img src="https://1583372177-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoksNmwps1HmYr8TqHDnX%2Fuploads%2Fgit-blob-ce546fe2b1798e05122b3de07944b699094213fc%2Fimage%20(366).png?alt=media" alt=""><figcaption></figcaption></figure>

## HTTP API

### Get Inference Statistics

Get inference counts, confidence, and inference time for your Workspace's models over a time range, with the same numbers for the period of the same length before it. This is the data behind the dashboard's totals and % changes. It is available on Enterprise plans, and each API key can make 50 requests per minute.

{% openapi src="/files/E2TERp8U7OH7M6CgrOLD" path="/{workspace}/inference-stats" method="get" %}
[model-monitoring.yaml](https://1583372177-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoksNmwps1HmYr8TqHDnX%2Fuploads%2Fgit-blob-9f71481b5404c01cb2719571b4904eafff241bd9%2Fmodel-monitoring.yaml?alt=media)
{% endopenapi %}

### Attach Metadata to an Inference

Serverless and Inference Server responses include an `inference_id`. Send it with a field name and value to attach metadata you can filter and group by in the dashboard (ex: the camera location or production line). Field names are case-sensitive, so keep their spelling consistent.

{% openapi src="/files/E2TERp8U7OH7M6CgrOLD" path="/{workspace}/inference-stats/metadata" method="post" %}
[model-monitoring.yaml](https://1583372177-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoksNmwps1HmYr8TqHDnX%2Fuploads%2Fgit-blob-9f71481b5404c01cb2719571b4904eafff241bd9%2Fmodel-monitoring.yaml?alt=media)
{% endopenapi %}

This example runs an inference on Serverless and attaches a location to it:

```python
import requests
from inference_sdk import InferenceHTTPClient

api_key = "YOUR_API_KEY"
workspace = "YOUR_WORKSPACE_ID"

client = InferenceHTTPClient(api_url="https://serverless.roboflow.com", api_key=api_key)
result = client.infer("https://media.roboflow.com/inference/people-walking.jpg", model_id="coco/24")

response = requests.post(
    f"https://api.roboflow.com/{workspace}/inference-stats/metadata",
    headers={"Authorization": f"Bearer {api_key}"},
    json={
        "data": [
            {
                "inference_ids": [result["inference_id"]],
                "field_name": "camera_location",
                "field_value": "canada",
            }
        ]
    },
)
print(response.json())
```
