> ## Documentation Index
> Fetch the complete documentation index at: https://developers.agentx.so/llms.txt
> Use this file to discover all available pages before exploring further.

# Finalize Run

> Mark a run as complete and get the final rating statistics

Marks the run `"completed"` and returns the authoritative rating aggregate, recomputed from
every stored result. After finalizing, no more results are accepted (further `/results` calls
return `409`), and the run is ready for
[Analyze Run](/api-reference/custom-eval/analyze-run) or the
[CI gate](/api-reference/ci-cd/get-gate).

<Note>
  Finalizing is **idempotent**: calling it again on a completed run returns the same
  `"completed"` response. Finalizing a `"failed"` run returns `status: "failed"` (with its
  statistics) rather than flipping it to completed - and rather than an error, so retried
  finalize calls never crash a pipeline. You can finalize with partial results; use
  [Get Missing Results](/api-reference/custom-eval/missing-results) first to check coverage.
</Note>

## Authentication

<ParamField header="x-api-key" type="string" required>
  Project API key.
</ParamField>

## Path Parameters

<ParamField path="runId" type="string" required>
  Run ID.
</ParamField>

## Body

No body required.

## Response

<ResponseField name="runId" type="string">
  Run ID.
</ResponseField>

<ResponseField name="status" type="string">
  `"completed"`, or `"failed"` if the run had previously failed.
</ResponseField>

<ResponseField name="liveStatistics" type="object">
  Final rating aggregate, recomputed from every stored result:
  `{ averageRating, minRating, maxRating, ratedCount, skippedCount, failedCount }`. Same shape
  as [Submit Results](/api-reference/custom-eval/submit-results)' `liveStatistics`. Available
  without calling [Analyze Run](/api-reference/custom-eval/analyze-run); analysis only adds the
  LLM-written qualitative report on top.
</ResponseField>

## Errors

| Status | Body                           | Meaning                            |
| ------ | ------------------------------ | ---------------------------------- |
| `404`  | `{ "error": "Run not found" }` | No run with this id in the project |

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST http://localhost:4700/api/v1/custom-agent-evaluations/runs/rK7dP2qWx9TzB4mV6nJcE/finalize \
    -H "x-api-key: agtx_local_0f3c9a17d2b84e6a5c01b9f4e7d8a2c6431b5f97a0e2d4c8"
  ```

  ```python Python SDK theme={null}
  result = client.evaluations.finalize_run("rK7dP2qWx9TzB4mV6nJcE")
  print(result["liveStatistics"]["averageRating"])
  ```
</RequestExample>

<ResponseExample>
  ```json 200 OK theme={null}
  {
    "runId": "rK7dP2qWx9TzB4mV6nJcE",
    "status": "completed",
    "liveStatistics": {
      "averageRating": 7.8,
      "minRating": 5,
      "maxRating": 10,
      "ratedCount": 6,
      "skippedCount": 0,
      "failedCount": 0
    }
  }
  ```

  ```json 404 Not found theme={null}
  {
    "error": "Run not found"
  }
  ```
</ResponseExample>
