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

> 归档 managed-agent Session 中的子线程。

`POST /api/v1/cloud/sessions/{session_id}/threads/{thread_id}/archive`

归档子线程。当前 CAS 对协调器主线程归档返回 `409`。

## 路径参数

| 参数           | 类型     | 说明                        |
| ------------ | ------ | ------------------------- |
| `session_id` | string | 以 `sess_` 为前缀的 Session ID |
| `thread_id`  | string | 以 `sthr_` 为前缀的 Thread ID  |

## 请求头

| 头部              | 必选 | 说明                  |
| --------------- | -- | ------------------- |
| `Authorization` | 是  | `Bearer $QODER_PAT` |

## 示例请求

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

## 示例响应

**HTTP 200 OK**

返回归档后的 [Session Thread 对象](/zh/cloud-agents/api/sessions/schemas#session-thread-对象)。

```json theme={null}
{
  "id": "sthr_019ef2a07a06704fb899908c29eed779",
  "type": "session_thread",
  "session_id": "sess_019ef2a07a0670b3b68a84f0f3c5c98e",
  "parent_thread_id": "sthr_019ef2a07a06704fb899908c29eed778",
  "agent": {
    "id": "agent_019e390add9f7bac9b6cc806db46fcbd",
    "type": "agent",
    "version": 2,
    "name": "doc-test-agent",
    "description": "",
    "model": {"id": "ultimate", "effective_context_window": 200000},
    "system": "You are an expert software engineer.",
    "tools": [{"enabled_tools": ["Bash", "Read", "Write", "Edit", "Glob", "Grep"], "type": "agent_toolset_20260401"}],
    "skills": [],
    "mcp_servers": []
  },
  "status": "terminated",
  "stats": null,
  "archived_at": "2026-06-23T06:00:00.000Z",
  "created_at": "2026-06-23T05:53:19.774840Z",
  "updated_at": "2026-06-23T06:00:00.000Z"
}
```

## 错误码

| HTTP | 类型                      | 触发条件                                 |
| ---- | ----------------------- | ------------------------------------ |
| 401  | `authentication_error`  | PAT 无效或过期                            |
| 404  | `not_found_error`       | Session 或 thread 不存在                 |
| 409  | `invalid_request_error` | 协调器主线程不可归档、线程不在 `idle` 状态，或其它版本/状态冲突 |

**HTTP 404 Not Found**

```json theme={null}
{
  "type": "error",
  "request_id": "cb80235f-76a2-4ff3-9e28-5aa2da12dc14",
  "error": {
    "type": "not_found_error",
    "message": "Session thread 'sthr_fakefakefake_xxxxxxxxxxxxxxxx' was not found."
  },
  "request_id": "b5822072-f264-48da-9d61-6d48ffb07551"
}
```

**HTTP 409 Conflict**

```json theme={null}
{
  "type": "error",
  "request_id": "cb80235f-76a2-4ff3-9e28-5aa2da12dc14",
  "error": {
    "type": "invalid_request_error",
    "message": "Version or state conflict."
  }
}
```

无论冲突来自协调器角色、线程非 `idle` 状态还是其它并发冲突，409 响应都使用统一的 `"Version or state conflict."` 文案。需要进一步定位时，请通过 `GET /api/v1/cloud/sessions/{session_id}/threads/{thread_id}` 查看线程状态。

完整错误信封格式见 [错误参考](/zh/cloud-agents/api/conventions/errors)。

## 相关

<CardGroup cols={2}>
  <Card title="Managed Agents" icon="user-gear" href="/zh/cloud-agents/managed-agents">
    了解 coordinator 与 child 线程的协作模型。
  </Card>

  <Card title="列出 Session Threads" icon="list" href="/zh/cloud-agents/api/sessions/list-threads">
    查看 Session 中的所有线程及其状态。
  </Card>

  <Card title="Session Thread 对象" icon="layer-group" href="/zh/cloud-agents/api/sessions/schemas#session-thread-对象">
    Session Thread 对象的完整字段参考。
  </Card>
</CardGroup>
