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

# Session のキャンセル

> 現在の Session 作業のキャンセルを要求します。

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

Session の現在のターンのキャンセルを要求します。実行中の Session への cancel は **HTTP 202 Accepted** を返し、Session は `canceling` を経て `idle` に戻ります。アイドル状態の Session への cancel は安全な no-op で、**HTTP 200 OK** を返します。

## パスパラメータ

| パラメータ        | 型      | 説明                            |
| ------------ | ------ | ----------------------------- |
| `session_id` | string | `sess_` プレフィックスを持つ Session ID |

## ヘッダー

| ヘッダー            | 必須 | 説明                  |
| --------------- | -- | ------------------- |
| `Authorization` | はい | `Bearer $QODER_PAT` |

## リクエスト例

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

## レスポンス例

**HTTP 200 OK**(no-op)または **HTTP 202 Accepted**(キャンセル適用)

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

`status` フィールドはどちらの場合も `"canceling"` です。ターンが中断された後、Session は `idle` に戻ります。

## エラー

| HTTP | Type                   | 発生条件                    |
| ---- | ---------------------- | ----------------------- |
| 401  | `authentication_error` | PAT が無効または期限切れ          |
| 404  | `not_found_error`      | Session が存在しないか、アーカイブ済み |

> **注意:** すでにアイドル状態の Session に対する cancel は安全な no-op で、HTTP 200 を返します。レスポンスは、キャンセルが適用された場合(202)か 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."
  }
}
```

完全なエラーエンベロープについては [Errors](/ja/cloud-agents/api/conventions/errors) を参照してください。

## 関連項目

<CardGroup cols={2}>
  <Card title="Session の起動" icon="play" href="/ja/cloud-agents/sessions">
    Agent を環境で実行し、ステートフルな対話を行う。
  </Card>
</CardGroup>
