# Move an agent's work to the cloud, to a paired machine, or to the best paired machine.

> A shorthand for `POST /agents/{id}/move` with only a target and the agent's own model: `"cloud"`, a node id, or `"local"` for the first paired machine (not a cloud worker) that can take it now.
> https://koi.dog/docs/api/agents/handoff-agent/

`POST /api/v1/agents/{id}/handoff` · Scope: `crews`

When an API key calls it, the timeline records who did what and the outcome. No query parameters.

## Path parameters.

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | `string` | yes | The agent'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.

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `target` | `"cloud" \| "local" \| string` | yes | `cloud`, `local` (the best paired machine for it) or a machine id. At least 5 characters. |

## Response.

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

- **409 conflict**: Refused with `409 conflict` and the reason for each machine when none can.
- **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/agents/$ID/handoff" \
    -H "Authorization: Bearer $KOIDOG_API_KEY" \
    -H "Idempotency-Key: $(uuidgen)" \
    -H "Content-Type: application/json" \
    -d '{
      "target": "local"
    }'
```

```js
const res = await fetch(`https://app.koi.dog/api/v1/agents/${process.env.ID}/handoff`, {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.KOIDOG_API_KEY}`,
    "Idempotency-Key": crypto.randomUUID(),
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    target: "local",
  }),
});
console.log(await res.json());
```

```python
import os
import uuid

import requests

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

## Response example.

```json
{
  "agent": {
    "id": "string",
    "crewId": "string",
    "taskId": "string",
    "role": "manager",
    "connectionId": "string",
    "harness": "claude-code",
    …
  },
  "move": {
    "id": "string",
    "agentId": "string",
    "crewId": "string",
    "state": "capturing",
    "reason": "string",
    "target": { … },
    …
  }
}
```
