全部產品
Search
文件中心

Qoder CN 系列:建立 Session

更新時間:Jul 16, 2026

基於 Identity 和 Template 建立 Forward Session。

POST /api/v1/forward/sessions

Forward 會先編譯 Template 基準與 Identity Config 覆蓋層,再建立運行時 Session。

要求標頭

Header

是否必填

說明

Authorization

Bearer <PAT>

Content-Type

application/json

Idempotency-Key

有副作用請求可選的等冪鍵。

請求體參數

參數

類型

是否必填

說明

identity_id

string

Forward Identity ID。

template_id

string

Forward Template ID。

title

string

Session 標題。

incremental_streaming_enabled

boolean

是否開啟 assistant 增量流式事件,預設 false

metadata

object

業務中繼資料。

config

object

單次 Session 配置覆蓋,只接受白名單欄位。

config.environment_variables

object

Session 環境變數 key-value。

resources

array

Session 級資源,當前用於掛載檔案。

resources[].type

string

條件必填

資源類型,當前為 file

resources[].file_id

string

條件必填

Files API 返回的 File ID。

resources[].mount_path

string

Agent 容器內掛載路徑;省略時由 Forward 根據檔案名稱產生。

樣本請求

curl -s -X POST 'https://api.qoder.com.cn/api/v1/forward/sessions' \
  -H "Authorization: Bearer $QODER_PAT" \
  -H "Content-Type: application/json" \
  -d '{
  "identity_id": "idn_xxx",
  "template_id": "tmpl_support",
  "title": "Customer support session",
  "incremental_streaming_enabled": true,
  "metadata": {
    "source": "web",
    "biz_id": "ticket_123"
  },
  "config": {
    "environment_variables": {
      "API_KEY": "sk-xxx",
      "REGION": "cn-hangzhou"
    }
  },
  "resources": [
    {
      "type": "file",
      "file_id": "file_019e6a18dc09abcd",
      "mount_path": "/data/input.py"
    }
  ]
}'

樣本響應

HTTP 200 OK

{
  "id": "sess_xxx",
  "type": "session",
  "identity_id": "idn_xxx",
  "template": {
    "id": "tmpl_support",
    "type": "template",
    "name": "Support assistant",
    "model": "ultimate",
    "version": 3
  },
  "source_type": "api",
  "status": "idle",
  "title": "Customer support session",
  "incremental_streaming_enabled": true,
  "metadata": {
    "source": "web"
  },
  "config": {
    "environment_variables": {
      "API_KEY": "sk-xxx"
    }
  },
  "stats": {
    "active_seconds": 0,
    "duration_seconds": 0
  },
  "created_at": "2026-06-22T10:00:00Z",
  "updated_at": "2026-06-22T10:00:00Z"
}

響應欄位

欄位

類型

說明

id

string

Session ID。

type

string

固定為 session

identity_id

string

Forward Identity ID。

template

object

Template 摘要。

source_type

string

Session 來源,直接 API 建立為 api

status

string

idlerunningreschedulingcancelingterminated

incremental_streaming_enabled

boolean

是否開啟增量流式事件。

錯誤

HTTP

Type

Code

觸發條件

400

invalid_request_error

invalid_request_body

請求體不合法。

403

permission_error

template_access_denied

Identity 無權使用該 Template。

404

not_found_error

identity_not_found

Identity 不存在或已刪除。

404

not_found_error

template_not_found

Template 不存在。

409

conflict_error

identity_disabled

Identity 已停用。

422

invalid_request_error

runtime_config_invalid

Effective 運行時配置不合法。

401

authentication_error

authentication_required

PAT 無效或已到期。

注意事項

  • source_type 由 Forward 設定,建立請求不接受該欄位。

  • incremental_streaming_enabled 建立後持久化在 Session 上,之後不能修改。

  • resources 中的檔案必須已通過 Files API 上傳。