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

# Cancel a session

> Request cancellation of current Session work.

`POST /api/v1/cloud/sessions/{session_id}/cancel`

Requests cancellation of the current turn in a Session. Cancel on a running Session returns **HTTP 202 Accepted** and the Session transitions through `canceling` back to `idle`. Cancel on an idle Session is a safe no-op and returns **HTTP 200 OK**.

## Path parameters

| Parameter    | Type   | Description                        |
| ------------ | ------ | ---------------------------------- |
| `session_id` | string | Session ID with the `sess_` prefix |

## Headers

| Header          | Required | Description         |
| --------------- | -------- | ------------------- |
| `Authorization` | Yes      | `Bearer $QODER_PAT` |

## Example request

```bash theme={null}
curl -X POST https://api.qoder.com/api/v1/cloud/sessions/sess_019ef30a4f0275678965d496ab542ef0/cancel \
  -H "Authorization: Bearer $QODER_PAT"
```

## Example response

**HTTP 200 OK** (no-op) or **HTTP 202 Accepted** (cancellation applied)

```json theme={null}
{
  "id": "sess_019ef30a4f0275678965d496ab542ef0",
  "type": "session",
  "status": "canceling"
}
```

The `status` field is `"canceling"` in both cases. After the turn aborts, the Session returns to `idle`.

## Errors

| HTTP | Type                   | Trigger                                     |
| ---- | ---------------------- | ------------------------------------------- |
| 401  | `authentication_error` | PAT invalid or expired                      |
| 404  | `not_found_error`      | Session does not exist or has been archived |

> **Note:** Calling cancel on an already-idle Session is a safe no-op and returns HTTP 200. The response always uses the same lightweight format regardless of whether cancellation was applied (202) or was a no-op (200).

**HTTP 404 Not Found**

```json theme={null}
{
  "type": "error",
  "request_id": "cb80235f-76a2-4ff3-9e28-5aa2da12dc14",
  "error": {
    "type": "not_found_error",
    "message": "Session 'sess_does_not_exist_0000000000000000000000000000' was not found."
  }
}
```

See [Errors](/cloud-agents/api/conventions/errors) for the full error envelope.

## Related

<CardGroup cols={2}>
  <Card title="Start a session" icon="play" href="/cloud-agents/sessions">
    Run an agent against an environment as a stateful conversation.
  </Card>
</CardGroup>
