POST /v1/sessions/{session_id}/resources
为 Session 添加资源。支持文件和 GitHub 仓库两种类型。添加后,Agent 在处理消息时可以访问这些资源。
请求头
| 头部 | 必选 | 说明 |
|---|---|---|
Authorization | 是 | Bearer <PAT> |
Content-Type | 是 | application/json |
路径参数
| 参数 | 类型 | 必选 | 说明 |
|---|---|---|---|
session_id | string | 是 | Session ID(sess_ 前缀) |
请求体
| 字段 | 类型 | 必选 | 说明 |
|---|---|---|---|
resources | array | 是 | 资源对象数组,必须至少包含一个文件或 GitHub 仓库资源。 |
resources[].type | string | 否 | "file" 或 "github_repository";省略时默认 "file"。 |
type 为 "file" 时:
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
file_id | string | 是 | 文件 ID(通过 Files API 上传后获得)。文件状态必须为 ready。 |
path | string | 否 | 挂载路径,默认 /data/{file_id}。相对路径会自动加上 /data/ 前缀;归一化后必须位于 /data/ 下,最长 512 字符。 |
mount_path | string | 否 | path 的别名。若同时提供 path 和 mount_path,两者必须一致;响应中统一返回归一化后的 path。 |
type 为 "github_repository" 时:
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
url | string | 是 | 仓库 URL |
mount_path | string | 否 | 克隆到容器中的路径 |
authorization_token | string | 否 | 访问私有仓库时使用的授权 token。提供后会保存在 Session resource 对象中。 |
示例请求
添加文件
添加 GitHub 仓库
示例响应
HTTP 200 OK 返回更新后的resources 列表,而不是完整 Session 对象。
响应字段
| 字段 | 类型 | 说明 |
|---|---|---|
resources | array | 追加后的完整归一化资源列表 |
resources[].type | string | "file" 或 "github_repository" |
resources[].file_id | string | 文件资源存在此字段 |
resources[].path | string | 文件资源存在此字段;归一化后的 /data/ 下挂载路径 |
resources[].url | string | GitHub 仓库资源存在此字段 |
resources[].mount_path | string | GitHub 仓库的可选挂载路径 |
resources[].authorization_token | string | GitHub 仓库的可选 token,仅在请求中提供时存在 |
错误码
| HTTP | type | 触发条件 |
|---|---|---|
| 400 | invalid_request_error | 请求格式错误、resources 为空、type 非法、缺少必填字段、文件路径非法,或请求内有重复资源 |
| 401 | authentication_error | PAT 无效或过期 |
| 404 | not_found_error | Session 或文件不存在 |
| 409 | conflict_error | Session 已归档或终止、文件未 ready,或文件 ID/path/仓库 URL 已挂载到此 Session |
相关
启动 Session
让 Agent 在环境中以有状态对话的方式运行。