> ## 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.

# 取消当前 Turn

> 取消 Forward Session 当前正在处理的 Turn。

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

请求取消当前 Turn；如果当前没有正在运行的 Turn，也会返回成功。

## 请求头

| Header          | 是否必填 | 说明             |
| --------------- | ---- | -------------- |
| Authorization   | 是    | `Bearer <PAT>` |
| Idempotency-Key | 否    | 有副作用请求可选的幂等键。  |

## 路径参数

| 参数          | 类型     | 是否必填 | 说明          |
| ----------- | ------ | ---- | ----------- |
| session\_id | string | 是    | Session ID。 |

## 示例请求

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

## 示例响应

**HTTP 200 OK**

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

## 响应字段

| 字段     | 类型     | 说明                   |
| ------ | ------ | -------------------- |
| id     | string | Session ID。          |
| type   | string | 固定为 `session`。       |
| status | string | 接受取消时返回 `canceling`。 |

## 错误

| HTTP | Type                   | Code                      | 触发条件               |
| ---- | ---------------------- | ------------------------- | ------------------ |
| 404  | `not_found_error`      | `session_not_found`       | Session 不存在。       |
| 409  | `conflict_error`       | `session_archived`        | Session 已归档。       |
| 502  | `api_error`            | `runtime_unavailable`     | 运行时 Session 服务不可用。 |
| 401  | `authentication_error` | `authentication_required` | PAT 无效或已过期。        |

## 注意事项

* `202 Accepted` 表示已发起取消。
* `200 OK` 表示当前没有正在处理的 Turn。
* 取消完成状态可通过 Event Stream 或 Session 详情确认。

## 相关

<CardGroup cols={2}>
  <Card title="订阅 Session Events" icon="radio" href="/cloud-agents/api/forward/sessions/stream-events" />

  <Card title="发送 Session Events" icon="paper-plane" href="/cloud-agents/api/forward/sessions/send-events" />
</CardGroup>
