# Rating

> Score a media or text item on a numeric scale, optionally against a reference.

Rating tasks ask annotators to score one media or text subject on a predefined scale, like the classic Likert-style 1-to-5 or 1-to-7 question. You can also show one non-selectable media reference when the score depends on fidelity to an original.

## When to use it

- Scoring a model output on perceived quality
- Checking whether an edit preserves the identity or features of a reference image
- Likert-scale surveys (agreement, satisfaction, confidence)
- Jobs where you want the full distribution of scores, not just a winner

## Datapoint shape

```json
{
  "media": {
    "reference": [{ "url": "dp://e7d921ab3c45/shoe1.png", "type": "image" }],
    "subject": [{ "url": "dp://e7d921ab3c45/shoe2.png", "type": "image" }]
  }
}
```

<ParamTable
  title="media.subject"
  params={[
    { name: "url", type: "string", required: true, description: "A dp:// reference returned by POST /media, or a public https URL." },
    { name: "type", type: '"video" | "image" | "audio"', required: false, description: "Determines which player the annotator sees. Inferred from the uploaded media, or from the URL's file extension — only required when a public URL has no extension to infer from." }
  ]}
/>

<ParamTable
  title="media.reference"
  params={[
    { name: "url", type: "string", required: true, description: "A dp:// reference returned by POST /media, or a public https URL." },
    { name: "type", type: '"video" | "image" | "audio"', required: false, description: "Determines how the non-selectable reference is displayed. Inferred when possible." }
  ]}
/>

Each datapoint can have at most one media `subject` and one optional `reference`. The reference is context only: annotators always score the subject, and the submitted answer remains a single numeric rating. The two media roles may use different supported media types. When there is no media subject, a reference is valid if the datapoint has non-empty `context` containing the text to rate.

Omit `subject` for a [text rating](#text-rating), retaining `reference` only when the text is being judged against that media.

### Text rating

For rating an abstract question with no specific media subject, send an empty media object — `"media": {}` — with no `subject` array. The annotator sees the prompt and scale only.

<DocCallout type="warning" title="Send an empty object, not nothing">
Rating is the only task type that accepts an empty `media` object. You must still include the `media` key with a value of `{}` — omitting it entirely or sending `"media": null` is rejected with a `422`. Every datapoint in a rating job has to carry a `media` value.
</DocCallout>

```json
{
  "task_type": "rating",
  "instruction": "How likely are you to recommend this product to a friend?",
  "response_options": { "scale": [1, 2, 3, 4, 5] },
  "datapoints": [{ "media": {} }]
}
```

When you have several text passages to rate against the same question, put each passage in the datapoint's `context`, reference it with `{context}` in the job-level `instruction`, and submit one datapoint per passage:

```json
{
  "instruction": "Rate how much you agree: {context}",
  "datapoints": [
    { "media": {}, "context": "Climate change is human-caused." },
    { "media": {}, "context": "Lemurs are reptiles." }
  ]
}
```

The `{context}` placeholder is substituted per datapoint at delivery time. Without it, `context` is stored on the datapoint but never shown to annotators; they would only see the bare `instruction`.

To rate a description against an image, keep the text in `context` and send the image under `media.reference`. The annotator sees the rendered question, the non-selectable reference image, and the rating scale; no media subject card is created.

```json
{
  "task_type": "rating",
  "instruction": "How accurately does this description match the reference image?\n\nDescription: {context}",
  "response_options": {
    "scale": [1, 2, 3, 4, 5],
    "labels": { "1": "Not accurate", "5": "Fully accurate" }
  },
  "datapoints": [
    {
      "media": {
        "reference": [
          { "url": "dp://e7d921ab3c45/shoe1.png", "type": "image" }
        ]
      },
      "context": "A red shoe with white laces."
    }
  ]
}
```

## Scale configuration

Rating jobs require a `response_options` object on the job body:

```json
{
  "task_type": "rating",
  "response_options": {
    "scale": [1, 2, 3, 4, 5],
    "labels": {
      "1": "Very poor",
      "5": "Excellent"
    }
  },
  ...
}
```

<ParamTable
  title="response_options"
  params={[
    { name: "scale", type: "array of numbers", required: true, description: "Allowed rating values (at least 2). Any numeric array works; [1,2,3,4,5] is canonical but you can use [0,1] for binary or [1..10] for finer grain." },
    { name: "labels", type: "{ [value: string]: string }", description: "Optional human-readable labels for scale endpoints or intermediate values. Keys are string-stringified scale values." }
  ]}
/>

## Result shape

```json
{
  "datapoint_index": 0,
  "mean": 4.0,
  "median": 4,
  "distribution": { "3": 2, "4": 6, "5": 2 },
  "total_responses": 10,
  "weighted_mean": 4.059,
  "weighted_distribution": { "3": 1.4, "4": 5.2, "5": 1.9 },
  "media": [
    {
      "media_id": "e7d921ab-3c45-4a2f-9b71-0d1e2f3a4b5c",
      "type": "video",
      "role": "subject",
      "label": null,
      "url": "/media/v2/e7d921ab-3c45-4a2f-9b71-0d1e2f3a4b5c?cid=...&exp=...&sig=...",
      "thumbnail_url": "/media/v2/e7d921ab-3c45-4a2f-9b71-0d1e2f3a4b5c?cid=...&exp=...&sig=...&preview=1"
    }
  ]
}
```

<ParamTable
  params={[
    { name: "mean", type: "float | null", description: "Arithmetic mean, rounded to 3 decimals. null if no responses yet." },
    { name: "median", type: "float | null", description: "Median across responses. For even N, the average of the two middle values." },
    { name: "distribution", type: "{ [value: string]: count }", description: "Frequency count per rating value. Keys are stringified scale values." },
    { name: "total_responses", type: "int", description: "Valid numeric responses counted." },
    { name: "weighted_mean", type: "float | null", description: "Mean where each response is weighted by a platform-computed reliability score instead of counted equally. Rounded to 3 decimals, or null when there are no eligible responses. (There is no weighted median.)" },
    { name: "weighted_distribution", type: "{ [value: string]: float }", description: "The weighted counterpart of `distribution` (see `weighted_mean`). Rounded to 3 decimals." },
    { name: "media", type: "array", description: "The datapoint's media subject and optional reference, so you can tie each result row back to its assets. A text rating with a reference contains only that reference; an unreferenced text rating is empty. See the fields below." }
  ]}
/>

Each entry in the `media` array describes one media item on the datapoint:

<ParamTable
  title="media[]"
  params={[
    { name: "media_id", type: "string", description: "Stable identifier for the media item." },
    { name: "type", type: '"video" | "image" | "audio" | null', description: "The media item's type." },
    { name: "role", type: '"subject" | "reference"', description: "Whether the item is scored (`subject`) or shown as non-selectable context (`reference`)." },
    { name: "label", type: "string | null", description: "The value key this item maps to; null for rating, whose media is the scored subject rather than a vote key." },
    { name: "url", type: "string", description: "Signed, relative proxy URL for the media; valid for roughly one hour." },
    { name: "thumbnail_url", type: "string", description: "Signed, relative preview URL; valid for roughly one hour." }
  ]}
/>

<DocCallout type="note" title="Reading result fields">
Results may include additional fields beyond those listed here, and any field can be `null` before a datapoint has received responses. Read fields by name rather than assuming a fixed shape.
</DocCallout>

## Example

<CodeTabs>
  <CodeTab lang="curl" label="curl">
```bash
curl -X POST https://api.trydatapoint.com/data-labelling/v1/jobs \
  -H "X-API-Key: $DATAPOINT_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "edit-identity-preservation-v1",
    "instruction": "Do people, animals, or objects maintain their original identity and features after the edit?",
    "task_type": "rating",
    "response_options": {
      "scale": [1, 2, 3, 4, 5],
      "labels": { "1": "Not preserved", "3": "Partially preserved", "5": "Fully preserved" }
    },
    "max_responses_per_datapoint": 10,
    "datapoints": [
      {
        "media": {
          "reference": [
            { "url": "dp://e7d921ab3c45/shoe1.png", "type": "image" }
          ],
          "subject": [
            { "url": "dp://e7d921ab3c45/shoe2.png", "type": "image" }
          ]
        }
      }
    ]
  }'
```
  </CodeTab>
  <CodeTab lang="python" label="Python">
```python
requests.post(
    "https://api.trydatapoint.com/data-labelling/v1/jobs",
    headers={"X-API-Key": key},
    json={
        "name": "edit-identity-preservation-v1",
        "instruction": "Do people, animals, or objects maintain their original identity and features after the edit?",
        "task_type": "rating",
        "response_options": {
            "scale": [1, 2, 3, 4, 5],
            "labels": {"1": "Not preserved", "3": "Partially preserved", "5": "Fully preserved"},
        },
        "max_responses_per_datapoint": 10,
        "datapoints": [
            {
                "media": {
                    "reference": [
                        {"url": "dp://e7d921ab3c45/shoe1.png", "type": "image"}
                    ],
                    "subject": [
                        {"url": "dp://e7d921ab3c45/shoe2.png", "type": "image"}
                    ]
                }
            }
        ],
    },
)
```
  </CodeTab>
</CodeTabs>

## Common errors

| Status | Cause |
|---|---|
| `400` | Missing `response_options.scale`. |
| `400` | `scale` has fewer than 2 values. |
| `400` | `media.subject` has 2+ items (0 is allowed for text-only rating). |
| `400` | `media.reference` has 2+ items, or a reference is sent without either a media subject or non-empty text `context`. |
| `400` | A text rating with reference media has an instruction or dimension that does not contain `{context}`. |
| `422` | Datapoint sent without a `media` value (send `"media": {}` for text-only rating). |

## Next

- [Comparison](/docs/task-types/comparison): head-to-head preference
- [Multiple choice](/docs/task-types/multiple-choice): categorical labels
