> ## 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 に user または system イベントを送信します。

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

1 つ以上の受理可能なイベントを Session に送信します。`user.message` は非同期に Agent の処理をトリガーします。Agent の出力は list または stream エンドポイントで読み取ってください。

## パスパラメータ

| パラメータ        | 型      | 説明                            |
| ------------ | ------ | ----------------------------- |
| `session_id` | string | `sess_` プレフィックス付きの Session ID |

## ヘッダー

| ヘッダー            | 必須 | 説明                  |
| --------------- | -- | ------------------- |
| `Authorization` | はい | `Bearer $QODER_PAT` |
| `Content-Type`  | はい | `application/json`  |

## リクエストボディ

| フィールド    | 型     | 必須 | 説明                |
| -------- | ----- | -- | ----------------- |
| `events` | array | はい | 空でないイベントオブジェクトの配列 |

## サポートされるイベントタイプ

| タイプ                       | 必須フィールド                | 備考                                                                                                                                                                                                                           |
| ------------------------- | ---------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `user.message`            | `content`              | `content` は空でない content block の配列でなければなりません                                                                                                                                                                                  |
| `user.interrupt`          | なし                     | `session_thread_id` は任意です                                                                                                                                                                                                    |
| `user.tool_confirmation`  | `tool_use_id`、`result` | `result` は `allow` または `deny` でなければなりません。`deny_message` は任意で、`result = "deny"` の場合にのみ指定できます                                                                                                                                  |
| `user.tool_result`        | `tool_use_id`          | 組み込みツールの結果を返すために使用します。`content` と `is_error` は任意です                                                                                                                                                                           |
| `user.custom_tool_result` | `custom_tool_use_id`   | クライアント側カスタムツールの結果を返すために使用します。`content` と `is_error` は任意です                                                                                                                                                                    |
| `user.define_outcome`     | `description`、`rubric` | `rubric` はオブジェクトで、`{"type":"text","content":"..."}` または `{"type":"file","file_id":"file_..."}` のいずれかです。未知のフィールドは拒否されます。`max_iterations` は任意で、1 から 20 の整数でなければなりません。`outcome_id`（`outc_` プレフィックス）はサーバーが割り当てるため、クライアントは指定できません |
| `system.message`          | `content`              | `content` は空でない text content block の配列でなければなりません。1 リクエストにつき `system.message` は最大 1 つで、batch の最後のイベントとして、`user.message`、`user.tool_result`、または `user.custom_tool_result` の直後に置く必要があります                                        |

`user.message` および `system.message` では文字列形式の `content` はサポートされません。

## リクエスト例

```bash theme={null}
curl -X POST https://api.qoder.com/api/v1/cloud/sessions/sess_019e392c0d1e74e095d21ea4c6b41def/events \
  -H "Authorization: Bearer $QODER_PAT" \
  -H "Content-Type: application/json" \
  -d '{
    "events": [
      {
        "type": "user.message",
        "content": [
          {"type": "text", "text": "Help me analyze the performance of this code."}
        ]
      }
    ]
  }'
```

## レスポンス例

**HTTP 200 OK**

```json theme={null}
{
  "data": [
    {
      "id": "evt_019e3bb2c153764da54e4d3acbef52b6",
      "type": "user.message",
      "content": [
        {"type": "text", "text": "Help me analyze the performance of this code."}
      ],
      "processed_at": "2026-05-18T15:27:11.187413896Z"
    }
  ]
}
```

## Human-in-the-loop レスポンス

ストリームが確認を必要とする `agent.tool_use` を発行したら、`user.tool_confirmation` で応答します。

```json theme={null}
{
  "events": [
    {
      "type": "user.tool_confirmation",
      "tool_use_id": "evt_01JZ6Q3FB6SG8F7J1M2N",
      "result": "deny",
      "deny_message": "Do not delete files in this directory."
    }
  ]
}
```

ストリームが `agent.custom_tool_use` を発行したら、クライアント側でツールを実行し、`user.custom_tool_result` で応答します。

```json theme={null}
{
  "events": [
    {
      "type": "user.custom_tool_result",
      "custom_tool_use_id": "evt_01JZ6R1V9Z8K2M3N4P5Q",
      "content": [{"type": "text", "text": "Order status: shipped"}]
    }
  ]
}
```

## エラー

| HTTP | タイプ                     | トリガー条件                                                                                                  |
| ---- | ----------------------- | ------------------------------------------------------------------------------------------------------- |
| 400  | `invalid_request_error` | `events` が空、サポートされないイベントタイプ、必須フィールドの欠落、不正な content block、またはサポートされないレガシーフィールド                           |
| 401  | `authentication_error`  | PAT が無効または期限切れ                                                                                          |
| 404  | `not_found_error`       | Session または保留中のアクションが存在しない                                                                              |
| 409  | `invalid_request_error` | Session が現在ターンを処理中、またはその他の Session 状態の競合（注意: `type` は `conflict_error` ではなく `invalid_request_error` です） |

### 例: 400 不正な `content`

`user.message` に content block の配列ではなくプレーンな文字列を送信した場合:

```json theme={null}
{
  "error": {
    "message": "Field 'content' must be a non-empty array of content blocks.",
    "type": "invalid_request_error"
  },
  "request_id": "2c9d3d8a-dd0f-4c27-b2ad-24c8719c97e1",
  "type": "error"
}
```

### 例: 404 Session が見つからない

```json theme={null}
{
  "error": {
    "message": "Session 'sess_doesnotexist_xxxxxxxxxxxxxxxxxxxxxxxx' was not found.",
    "type": "not_found_error"
  },
  "request_id": "590c2a0c-1656-42d3-ba0c-32c755d22e77",
  "type": "error"
}
```

### 例: 409 Session が実行中

Session がすでにターンを処理しているときに `user.message` を送信した場合:

```json theme={null}
{
  "error": {
    "message": "Session is currently processing a turn. Cancel the current turn or wait for completion.",
    "type": "invalid_request_error"
  },
  "request_id": "ba018d2f-d6b0-4bbe-a53c-2241baca34fe",
  "type": "error"
}
```

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

## 関連項目

<CardGroup cols={2}>
  <Card title="Session イベントストリーム" icon="wave-pulse" href="/ja/cloud-agents/events-stream">
    Agent の思考、メッセージ、ツール呼び出し、ステータスを SSE でストリーミングします。
  </Card>
</CardGroup>
