> ## 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 CI Run

> Close the run before computing the CI gate

Marks the run `"completed"` and returns the final rating aggregate. Finalize after every result
batch has been submitted and **before** calling the [gate](/api-reference/ci-cd/get-gate) - the
gate reads whatever ratings are stored, and finalizing pins the run so nothing lands after the
verdict. This is the same endpoint as
[Finalize Run](/api-reference/custom-eval/finalize-run); see that page for the full reference.

Finalizing is idempotent, so a retried pipeline step is harmless: a second call returns the
same `"completed"` response, and a `"failed"` run stays failed (returned as
`status: "failed"`, not an error).

## Authentication

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

## Path Parameters

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

## 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 aggregate: `{ averageRating, minRating, maxRating, ratedCount, skippedCount,
      failedCount }`. A nonzero `skippedCount` in CI usually means the judge could not score
  (e.g. missing judge provider key) - the gate would then fail with "no rated results", so
  check this before gating.
</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"
  ```
</RequestExample>

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