> For the complete documentation index, see [llms.txt](https://docs.umbraco.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.umbraco.com/ai-in-umbraco/19.latest/testing-and-evaluation/api/compare.md).

# Compare

Compare test runs and variations for regression detection.

Two endpoints support comparison: one for comparing individual runs and one for comparing variation groups within an execution.

## Compare Test Runs

Compares two test runs and detects regressions at the grader level.

### Request

```http
POST /umbraco/ai/management/api/v1/test-runs/compare
```

### Request Body

{% code title="Request" %}

```json
{
    "baselineTestRunId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
    "comparisonTestRunId": "c3d4e5f6-a7b8-9012-cdef-123456789012"
}
```

{% endcode %}

### Request Properties

| Property              | Type | Required | Description           |
| --------------------- | ---- | -------- | --------------------- |
| `baselineTestRunId`   | guid | Yes      | The baseline run ID   |
| `comparisonTestRunId` | guid | Yes      | The comparison run ID |

### Response

{% code title="200 OK" %}

```json
{
    "baselineRun": {
        "id": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
        "testId": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
        "status": "Passed",
        "durationMs": 1250,
        ...
    },
    "comparisonRun": {
        "id": "c3d4e5f6-a7b8-9012-cdef-123456789012",
        "testId": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
        "status": "Failed",
        "durationMs": 1480,
        ...
    },
    "isRegression": true,
    "isImprovement": false,
    "durationChangeMs": 230,
    "graderComparisons": [
        {
            "graderId": "a1b2c3d4-0000-0000-0000-000000000001",
            "graderName": "Has bullet points",
            "baselineResult": {
                "graderId": "a1b2c3d4-0000-0000-0000-000000000001",
                "passed": true,
                "score": 1.0,
                "severity": "Error"
            },
            "comparisonResult": {
                "graderId": "a1b2c3d4-0000-0000-0000-000000000001",
                "passed": false,
                "score": 0.0,
                "failureMessage": "Expected output to contain '- ' but it was not found",
                "severity": "Error"
            },
            "changed": true,
            "scoreChange": -1.0
        }
    ]
}
```

{% endcode %}

### Response Properties

| Property            | Type   | Description                                     |
| ------------------- | ------ | ----------------------------------------------- |
| `baselineRun`       | object | Full baseline run details                       |
| `comparisonRun`     | object | Full comparison run details                     |
| `isRegression`      | bool   | True if comparison failed where baseline passed |
| `isImprovement`     | bool   | True if comparison passed where baseline failed |
| `durationChangeMs`  | long   | Duration change (positive = slower)             |
| `graderComparisons` | array  | Per-grader comparison results                   |

### Grader Comparison Properties

| Property           | Type   | Description                               |
| ------------------ | ------ | ----------------------------------------- |
| `graderId`         | guid   | The grader ID                             |
| `graderName`       | string | The grader display name                   |
| `baselineResult`   | object | Grader result from the baseline run       |
| `comparisonResult` | object | Grader result from the comparison run     |
| `changed`          | bool   | Whether the grader result changed         |
| `scoreChange`      | double | Score difference (positive = improvement) |

### Error Responses

{% code title="400 Bad Request" %}

```json
{
    "type": "https://tools.ietf.org/html/rfc7231#section-6.5.1",
    "title": "Bad request",
    "status": 400,
    "detail": "Baseline run {id} not found"
}
```

{% endcode %}

Returned when either the baseline or comparison run ID does not exist.

## Compare Variations

Compares two variation groups within the same execution for pairwise drill-down.

### Request

```http
POST /umbraco/ai/management/api/v1/test-runs/compare-variations
```

### Request Body

{% code title="Request" %}

```json
{
    "executionId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
    "sourceVariationId": null,
    "comparisonVariationId": "var-1-guid"
}
```

{% endcode %}

### Request Properties

| Property                | Type | Required | Description                              |
| ----------------------- | ---- | -------- | ---------------------------------------- |
| `executionId`           | guid | Yes      | Execution containing both variations     |
| `sourceVariationId`     | guid | No       | Source variation (null = default config) |
| `comparisonVariationId` | guid | Yes      | Variation to compare against             |

### Response

{% code title="200 OK" %}

```json
{
    "sourceVariationName": "Default",
    "sourceMetrics": {
        "testId": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
        "totalRuns": 3,
        "passedRuns": 3,
        "passAtK": 1.0,
        "passToTheK": 1.0,
        "runIds": ["run-1", "run-2", "run-3"]
    },
    "comparisonVariationName": "Claude Sonnet",
    "comparisonMetrics": {
        "testId": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
        "totalRuns": 3,
        "passedRuns": 2,
        "passAtK": 0.67,
        "passToTheK": 0.0,
        "runIds": ["run-4", "run-5", "run-6"]
    },
    "passRateDelta": -0.33,
    "averageDurationDeltaMs": 150.0,
    "isRegression": true,
    "isImprovement": false
}
```

{% endcode %}

### Response Properties

| Property                  | Type   | Description                                        |
| ------------------------- | ------ | -------------------------------------------------- |
| `sourceVariationName`     | string | Source variation name ("Default" or name)          |
| `sourceMetrics`           | object | Metrics for the source variation                   |
| `comparisonVariationName` | string | Comparison variation name                          |
| `comparisonMetrics`       | object | Metrics for the comparison variation               |
| `passRateDelta`           | double | Difference in pass rate (comparison - source)      |
| `averageDurationDeltaMs`  | double | Difference in average duration (positive = slower) |
| `isRegression`            | bool   | Whether the comparison is a regression             |
| `isImprovement`           | bool   | Whether the comparison is an improvement           |

## Examples

### Compare Against Baseline

{% code title="cURL" %}

```bash
curl -X POST "https://your-site.com/umbraco/ai/management/api/v1/test-runs/compare" \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "baselineTestRunId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
    "comparisonTestRunId": "c3d4e5f6-a7b8-9012-cdef-123456789012"
  }'
```

{% endcode %}

### Compare Default vs Variation

{% code title="cURL" %}

```bash
curl -X POST "https://your-site.com/umbraco/ai/management/api/v1/test-runs/compare-variations" \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "executionId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
    "sourceVariationId": null,
    "comparisonVariationId": "var-1-guid"
  }'
```

{% endcode %}

## Related

* [Run Test](/ai-in-umbraco/19.latest/testing-and-evaluation/api/run.md) - Execute a test
* [List Test Runs](/ai-in-umbraco/19.latest/testing-and-evaluation/api/runs.md) - Query runs
* [Variations](/ai-in-umbraco/19.latest/testing-and-evaluation/variations.md) - A/B testing concepts


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.umbraco.com/ai-in-umbraco/19.latest/testing-and-evaluation/api/compare.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
