# Retry a run

Source: https://docs.coderhelm.com/api/reference/runs/retry-run

`POST /api/runs/{run_id}/retry`

Starts the run's ticket again as a new run. Only a run that is `failed`, `needs_input`, `needs_outside_change`, `cancelled` or `closed` can be retried; the old run becomes `retried`, so retrying it twice is refused with `400`. Find the new run with `GET /api/runs?q=<ticket id>`.

## Authentication

A team API key: `Authorization: Bearer chk_...`. The key needs the `runs` scope. See [Authentication](https://docs.coderhelm.com/api/authentication).

## Parameters

### Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `run_id` | string | yes | The run's id. |

## Responses

### 200

The ticket is queued again.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `status` | string | yes | `retrying` after a retry, `cancelled` after a cancel. |

Headers: `RateLimit-Limit`, `RateLimit-Remaining`, `RateLimit-Reset`.

### 400

The run is not in a state that can be retried.

### 401

The key is missing, malformed, revoked or expired, or the person who made it left the team.

### 403

The key lacks the scope this endpoint needs (`missing_scope`).

### 404

No run with this id in the team.

### 429

Over the key's rate limit (`rate_limited`), or, for endpoints that start work, over the team's monthly token limit (`token_limit_reached`).

Headers: `RateLimit-Limit`, `RateLimit-Remaining`, `RateLimit-Reset`, `Retry-After`.

### 500

Something failed on CoderHelm's side. Safe to retry reads.

## Example request

cURL:

```bash
curl -X POST 'https://api.coderhelm.com/api/runs/01JB8X6F4M2C9QZ3T7V5W1K0HA/retry' \
  -H "Authorization: Bearer $CODERHELM_API_KEY"
```

TypeScript:

```ts
const res = await fetch("https://api.coderhelm.com/api/runs/01JB8X6F4M2C9QZ3T7V5W1K0HA/retry", {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.CODERHELM_API_KEY}`,
  },
});
if (!res.ok) {
  const { error, code } = await res.json();
  throw new Error(`${res.status} ${code}: ${error}`);
}
const data = await res.json();
```

Python:

```python
import os
import requests

headers = {
    "Authorization": f"Bearer {os.environ['CODERHELM_API_KEY']}",
}
res = requests.request("POST", "https://api.coderhelm.com/api/runs/01JB8X6F4M2C9QZ3T7V5W1K0HA/retry", headers=headers)
if not res.ok:
    raise RuntimeError(f"{res.status_code}: {res.json().get('error')}")
data = res.json()
```

## Example response

```json
{
  "status": "retrying"
}
```
