> ## Documentation Index
> Fetch the complete documentation index at: https://docs.lusor.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Stop a session

> Stop a session that has started, or withdraw a turn or message that is still waiting.

Which call you use depends on whether the work has started.

| Situation | Call |
| - | - |
| The session is working, or waiting for your answer | `POST /v1/sessions/{id}/stop` |
| A turn is waiting for the agent's phone | `POST /v1/agents/{id}/turns/{sessionId}/cancel` |
| A turn or follow-up message is waiting behind another session | `DELETE /v1/sessions/{id}/queue/{invocationId}` |

## Stop a session that has started

```bash cURL theme={null}
curl -X POST https://api.lusor.ai/v1/sessions/<session id>/stop \
  -H "X-Api-Key: $LUSOR_API_KEY"
```

```python Python theme={null}
import os, requests

r = requests.post(
    "https://api.lusor.ai/v1/sessions/<session id>/stop",
    headers={"X-Api-Key": os.environ["LUSOR_API_KEY"]},
)
print(r.json())
```

```javascript Node.js theme={null}
const res = await fetch("https://api.lusor.ai/v1/sessions/<session id>/stop", {
  method: "POST",
  headers: { "X-Api-Key": process.env.LUSOR_API_KEY },
});
console.log(await res.json());
```

```json Response theme={null}
{ "ok": true, "status": "stopping", "sessionId": "mobile_use_9c2e…" }
```

The agent stops and the session ends with status `cancelled`. Stopping is safe to repeat: once the session has stopped, further calls return `status: "noop"`. A session paused at `awaiting_human` can be stopped the same way.

A stopped session can still take a [follow-up message](https://docs.lusor.ai/agents/follow-up-messages.md).

## Withdraw a waiting turn

A turn sent while the agent's phone is busy waits for the phone (`queued: true`). To withdraw it before it starts:

```bash theme={null}
curl -X POST https://api.lusor.ai/v1/agents/<agent id>/turns/<session id>/cancel \
  -H "X-Api-Key: $LUSOR_API_KEY"
```

| Response | Meaning |
| - | - |
| `200`, `cancelled: true` | The turn was withdrawn. It never starts. |
| `200`, `cancelled: false` | The turn had already finished. Nothing changed. |
| `400` | The turn has already started. Stop its session with `POST /v1/sessions/{id}/stop` instead. |
| `409` | The cancel is still settling. Try again in a moment. |

## Withdraw a waiting message

A [follow-up message](https://docs.lusor.ai/agents/follow-up-messages.md) sent while its session is still working waits behind it, and its response has `queued: true` and an `invocationId`. A waiting turn's response carries an `invocationId` too. To withdraw either before it starts:

```bash theme={null}
curl -X DELETE https://api.lusor.ai/v1/sessions/<session id>/queue/<invocation id> \
  -H "X-Api-Key: $LUSOR_API_KEY"
```

The call is safe to repeat: withdrawing an entry that was already withdrawn returns `alreadyCancelled: true`. An unknown `invocationId` returns `404`.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.