# Run every failed agent of a crew again.

> In one step, retries every failed or stopped agent of the crew that `POST /agents/{id}/retry` would accept: either all of them are queued (and a crew that had ended is reopened once, with its time limit started again), or nothing changes.
> https://koi.dog/docs/api/crews/retry-failed-agents/

`POST /api/v1/crews/{id}/retry-failed` · Scope: `crews`

Agents it leaves are in `skipped` with the reason, in the same words the agent route refuses with (a managed crew's merge step whose task is already merged, a task a re-plan or steer dropped). Optional `guidance` has the same meaning and limits as on the agent route and is given to each agent retried. One `notice` (`data.code: agents_retried`) says who retried how many; each agent then has its own state event. Answers `409 nothing_to_retry` when there is nothing to retry (the crew was canceled, no agent has failed, or none that failed can be retried); `CrewView.canRetryFailed` says the same in advance. No query parameters.

## Path parameters.

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

## Headers.

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `Idempotency-Key` | `string` | no | Makes a retry safe: the same key with the same request returns the first answer and does nothing else. |

## Body.

Optional: leave the body out and it is read as `{}`.

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `guidance` | `string` | no | Added guidance for this attempt and every later run of this agent, in the founder's words. 1 to 4000 characters. |

## Response.

200 OK: a JSON object. The example has placeholder values.

- **422 validation_failed**: The body does not match its schema; each problem is in `details`.

## Request.

```sh
curl -X POST "https://app.koi.dog/api/v1/crews/$ID/retry-failed" \
    -H "Authorization: Bearer $KOIDOG_API_KEY" \
    -H "Idempotency-Key: $(uuidgen)"
```

```js
const res = await fetch(`https://app.koi.dog/api/v1/crews/${process.env.ID}/retry-failed`, {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.KOIDOG_API_KEY}`,
    "Idempotency-Key": crypto.randomUUID(),
  },
});
console.log(await res.json());
```

```python
import os
import uuid

import requests

r = requests.post(
    f"https://app.koi.dog/api/v1/crews/{os.environ['ID']}/retry-failed",
    headers={
        "Authorization": f"Bearer {os.environ['KOIDOG_API_KEY']}",
        "Idempotency-Key": str(uuid.uuid4()),
    },
)
r.raise_for_status()
print(r.json())
```

## Response example.

```json
{
  "crew": {
    "id": "string",
    "projectId": "string",
    "goal": "string",
    "mode": "direct",
    "requestedSize": 0,
    "maxAgents": 0,
    …
  },
  "projectName": "string",
  "agents": { … },
  "tasks": {
    "total": 0,
    "done": 0,
    "failed": 0,
    "blocked": 0
  },
  "vmsRunning": 0,
  "spentUsd": 0,
  "managerNote": "string",
  "retried": [],
  "skipped": [],
  …
}
```
