跳转到主要内容
POST /v1/sessions/{session_id}/resources 为 Session 添加资源。支持文件和 GitHub 仓库两种类型。添加后,Agent 在处理消息时可以访问这些资源。

请求头

头部必选说明
AuthorizationBearer <PAT>
Content-Typeapplication/json

路径参数

参数类型必选说明
session_idstringSession ID(sess_ 前缀)

请求体

字段类型必选说明
resourcesarray资源对象数组,必须至少包含一个文件或 GitHub 仓库资源。
resources[].typestring"file""github_repository";省略时默认 "file"
type"file" 时:
字段类型必填说明
file_idstring文件 ID(通过 Files API 上传后获得)。文件状态必须为 ready
pathstring挂载路径,默认 /data/{file_id}。相对路径会自动加上 /data/ 前缀;归一化后必须位于 /data/ 下,最长 512 字符。
mount_pathstringpath 的别名。若同时提供 pathmount_path,两者必须一致;响应中统一返回归一化后的 path
type"github_repository" 时:
字段类型必填说明
urlstring仓库 URL
mount_pathstring克隆到容器中的路径
authorization_tokenstring访问私有仓库时使用的授权 token。提供后会保存在 Session resource 对象中。

示例请求

添加文件

curl -X POST "https://api.qoder.com/api/v1/cloud/sessions/sess_019e392c0d1e74e095d21ea4c6b41def/resources" \
  -H "Authorization: Bearer $QODER_PAT" \
  -H "Content-Type: application/json" \
  -d '{
    "resources": [
      {
        "type": "file",
        "file_id": "file_abc123def456",
        "path": "inputs/spec.md"
      }
    ]
  }'

添加 GitHub 仓库

curl -X POST "https://api.qoder.com/api/v1/cloud/sessions/sess_019e392c0d1e74e095d21ea4c6b41def/resources" \
  -H "Authorization: Bearer $QODER_PAT" \
  -H "Content-Type: application/json" \
  -d '{
    "resources": [
      {
        "type": "github_repository",
        "url": "https://github.com/your-org/your-repo"
      }
    ]
  }'

示例响应

HTTP 200 OK 返回更新后的 resources 列表,而不是完整 Session 对象。
{
  "resources": [
    {
      "type": "file",
      "file_id": "file_abc123def456",
      "path": "/data/inputs/spec.md"
    },
    {
      "type": "github_repository",
      "url": "https://github.com/your-org/your-repo"
    }
  ]
}

响应字段

字段类型说明
resourcesarray追加后的完整归一化资源列表
resources[].typestring"file""github_repository"
resources[].file_idstring文件资源存在此字段
resources[].pathstring文件资源存在此字段;归一化后的 /data/ 下挂载路径
resources[].urlstringGitHub 仓库资源存在此字段
resources[].mount_pathstringGitHub 仓库的可选挂载路径
resources[].authorization_tokenstringGitHub 仓库的可选 token,仅在请求中提供时存在

错误码

HTTPtype触发条件
400invalid_request_error请求格式错误、resources 为空、type 非法、缺少必填字段、文件路径非法,或请求内有重复资源
401authentication_errorPAT 无效或过期
404not_found_errorSession 或文件不存在
409conflict_errorSession 已归档或终止、文件未 ready,或文件 ID/path/仓库 URL 已挂载到此 Session
错误响应示例:
{
  "type": "error",
  "error": {
    "type": "invalid_request_error",
    "message": "resources[0]: field 'type' must be 'file' or 'github_repository'."
  }
}
{
  "type": "error",
  "error": {
    "type": "not_found_error",
    "message": "File 'file_fake_test_id' was not found."
  }
}
完整错误信封说明详见 错误参考

相关

启动 Session

让 Agent 在环境中以有状态对话的方式运行。