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

# 列出文件

> 获取当前账户下的文件列表，支持分页和过滤。

`GET /api/v1/cloud/files`

获取当前账户下的文件列表。

## 请求头

| 头部              | 必选 | 说明             |
| --------------- | -- | -------------- |
| `Authorization` | 是  | `Bearer <PAT>` |

## 查询参数

| 参数          | 类型      | 必选 | 说明                                                               |
| ----------- | ------- | -- | ---------------------------------------------------------------- |
| `limit`     | integer | 否  | 每页返回的最大文件数量。默认 20，范围 1-100。超过 100 返回 `400 invalid_request_error` |
| `page`      | string  | 否  | Claude 风格的向后翻页游标，等价于 `after_id`；与 `before_id`、`after_id` 互斥      |
| `after_id`  | string  | 否  | 游标分页：返回此 ID 之后的文件。与 `page`、`before_id` 互斥                        |
| `before_id` | string  | 否  | 游标分页：返回此 ID 之前的文件。与 `page`、`after_id` 互斥                         |
| `name`      | string  | 否  | 按文件名前缀搜索，不区分大小写                                                  |
| `scope_id`  | string  | 否  | 按资源 scope 过滤，目前为 Session ID                                      |

完整分页规范详见 [分页](/zh/cloud-agents/api/conventions/pagination)。

## 示例请求

```bash theme={null}
# 基本列表
curl -X GET "https://api.qoder.com/api/v1/cloud/files" \
  -H "Authorization: Bearer $QODER_PAT"

# 按 Session scope 过滤并限制数量
curl -X GET "https://api.qoder.com/api/v1/cloud/files?scope_id=sess_019e3bb8e6c47d18&limit=10" \
  -H "Authorization: Bearer $QODER_PAT"

# 游标分页
curl -X GET "https://api.qoder.com/api/v1/cloud/files?limit=10&page=file_019e3bb8e6c47d18" \
  -H "Authorization: Bearer $QODER_PAT"
```

## 示例响应

**HTTP 200 OK**

```json theme={null}
{
  "data": [
    {
      "id": "file_019e3bb8e6c47d189212a79642136696",
      "type": "file",
      "filename": "report.txt",
      "mime_type": "text/plain",
      "size_bytes": 110,
      "downloadable": true,
      "scope": {
        "id": "sess_019e3bb8e6c47d18",
        "type": "session"
      },
      "metadata": {
        "project": "demo"
      },
      "created_at": "2026-05-18T15:33:53Z"
    }
  ],
  "next_page": null,
  "first_id": "file_019e3bb8e6c47d189212a79642136696",
  "has_more": false,
  "last_id": "file_019e3bb8e6c47d189212a79642136696"
}
```

## 响应字段

| 字段          | 类型             | 说明                                                      |
| ----------- | -------------- | ------------------------------------------------------- |
| `data`      | array          | [File 对象](/zh/cloud-agents/api/files/schemas#file-对象)数组 |
| `next_page` | string \| null | 下一页向后游标；`has_more` 为 `true` 时传给 `page`                  |
| `first_id`  | string \| null | 当前页第一个文件 ID；`data` 为空时为 `null`                          |
| `last_id`   | string \| null | 当前页最后一个文件 ID；`data` 为空时为 `null`                         |
| `has_more`  | boolean        | 是否还有更多文件                                                |

## 分页说明

结果按 `created_at` 和 `id` 排序。遍历文件列表：

1. 首次请求设置 `limit` 获取第一页
2. 如果 `has_more` 为 `true`，使用 `page=<next_page>` 获取下一页
3. 使用 `before_id=<first_id>` 可向前翻页

## 错误码

| HTTP | type                    | 触发条件                                             |
| ---- | ----------------------- | ------------------------------------------------ |
| 400  | `invalid_request_error` | `limit` 非法，或同时传入多个 `page`、`before_id`、`after_id` |
| 401  | `authentication_error`  | 缺少或无效的认证令牌                                       |

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

## 相关

<CardGroup cols={2}>
  <Card title="附加与下载文件" icon="paperclip" href="/zh/cloud-agents/files">
    上传文件为 Agent 提供上下文，并下载 Agent 产出的文件。
  </Card>
</CardGroup>
