# Add a task to a running or paused crew.

> https://koi.dog/docs/api/crews/add-crew-task/

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

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.

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `title` | `string` | yes | A short name for the task, shown on the timeline and the pull request. At least 1 character. |
| `instructions` | `string` | yes | What the agent should do: the whole brief it is given for this task. At least 1 character. |
| `role` | `enum` | no | The kind of agent that does it. One of `manager`, `builder`, `tester`, `reviewer`, `researcher`, `integrator`. Default `builder`. |
| `requires` | `object` | no | What the machine must have to run it. Left out, any machine the crew may use. Default `{"tools":[]}`. |
| `requires.os` | `enum` | no | Only machines with this operating system. One of `macos`, `linux`. |
| `requires.xcode` | `boolean` | no | Only machines with Xcode installed. |
| `requires.tools` | `array` | no | Command names the machine must have (as the node reports them), such as `xcodebuild` or `docker`. Default empty. |

## Response.

201 Created: a `Task`. 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/tasks" \
    -H "Authorization: Bearer $KOIDOG_API_KEY" \
    -H "Idempotency-Key: $(uuidgen)" \
    -H "Content-Type: application/json" \
    -d '{
      "title": "Tests",
      "instructions": "Add tests for the dark mode switch."
    }'
```

```js
const res = await fetch(`https://app.koi.dog/api/v1/crews/${process.env.ID}/tasks`, {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.KOIDOG_API_KEY}`,
    "Idempotency-Key": crypto.randomUUID(),
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    title: "Tests",
    instructions: "Add tests for the dark mode switch.",
  }),
});
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']}/tasks",
    headers={
        "Authorization": f"Bearer {os.environ['KOIDOG_API_KEY']}",
        "Idempotency-Key": str(uuid.uuid4()),
    },
    json={
        "title": "Tests",
        "instructions": "Add tests for the dark mode switch.",
    },
)
r.raise_for_status()
print(r.json())
```

## Response example.

```json
{
  "id": "string",
  "crewId": "string",
  "key": "string",
  "title": "string",
  "instructions": "string",
  "acceptance": "string",
  "role": "manager",
  "requires": {
    "tools": [],
    …
  },
  "dependsOn": [],
  "owns": [],
  "state": "pending",
  "integration": "none",
  "createdAt": "string",
  …
}
```
