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

# セッションターンのキャンセル

> Forward セッションで現在実行中のターンをキャンセルします。

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

現在のターンのキャンセルを要求します。実行中のターンがない場合、このエンドポイントはキャンセルを開始せずに成功を返します。

## Headers

| Header            | Required | Description            |
| ----------------- | -------- | ---------------------- |
| `Authorization`   | Yes      | `Bearer <PAT>`         |
| `Idempotency-Key` | No       | 安全でないリクエスト向けの任意の冪等性キー。 |

## Path parameters

| Parameter    | Type   | Required | Description |
| ------------ | ------ | -------- | ----------- |
| `session_id` | string | Yes      | Session ID。 |

## Example request

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

## Example response

**HTTP 202 Accepted**

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

## Response fields

| Field    | Type   | Description               |
| -------- | ------ | ------------------------- |
| `id`     | string | Session ID。               |
| `type`   | string | 常に `session`。             |
| `status` | string | キャンセルが受理されると `canceling`。 |

## Errors

| HTTP | Type                   | Code                      | Trigger                |
| ---- | ---------------------- | ------------------------- | ---------------------- |
| 401  | `authentication_error` | `authentication_required` | PAT が無効または期限切れ。        |
| 404  | `not_found_error`      | `session_not_found`       | Session が存在しない。        |
| 409  | `conflict_error`       | `session_archived`        | Session がアーカイブ済み。      |
| 502  | `api_error`            | `runtime_unavailable`     | ランタイムセッションサービスが利用できない。 |

## Notes

* `202 Accepted` はキャンセルが要求されたことを意味します。
* `200 OK` はキャンセル対象の実行中ターンがなかったことを意味します。
* 完了は Event Stream または Session ステータスのポーリングで確認してください。

## Related

<CardGroup cols={2}>
  <Card title="セッションイベントのストリーミング" icon="radio" href="/cloud-agents/api/forward/sessions/stream-events" />

  <Card title="セッションイベントの送信" icon="paper-plane" href="/cloud-agents/api/forward/sessions/send-events" />
</CardGroup>
