基於 Identity 和 Template 建立 Forward Session。
POST /api/v1/forward/sessions
Forward 會先編譯 Template 基準與 Identity Config 覆蓋層,再建立運行時 Session。
要求標頭
Header | 是否必填 | 說明 |
Authorization | 是 |
|
Content-Type | 是 |
|
Idempotency-Key | 否 | 有副作用請求可選的等冪鍵。 |
請求體參數
參數 | 類型 | 是否必填 | 說明 |
identity_id | string | 是 | Forward Identity ID。 |
template_id | string | 是 | Forward Template ID。 |
title | string | 否 | Session 標題。 |
incremental_streaming_enabled | boolean | 否 | 是否開啟 assistant 增量流式事件,預設 |
metadata | object | 否 | 業務中繼資料。 |
config | object | 否 | 單次 Session 配置覆蓋,只接受白名單欄位。 |
config.environment_variables | object | 否 | Session 環境變數 key-value。 |
resources | array | 否 | Session 級資源,當前用於掛載檔案。 |
resources[].type | string | 條件必填 | 資源類型,當前為 |
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 | 固定為 |
identity_id | string | Forward Identity ID。 |
template | object | Template 摘要。 |
source_type | string | Session 來源,直接 API 建立為 |
status | string |
|
incremental_streaming_enabled | boolean | 是否開啟增量流式事件。 |
錯誤
HTTP | Type | Code | 觸發條件 |
400 |
|
| 請求體不合法。 |
403 |
|
| Identity 無權使用該 Template。 |
404 |
|
| Identity 不存在或已刪除。 |
404 |
|
| Template 不存在。 |
409 |
|
| Identity 已停用。 |
422 |
|
| Effective 運行時配置不合法。 |
401 |
|
| PAT 無效或已到期。 |
注意事項
source_type由 Forward 設定,建立請求不接受該欄位。incremental_streaming_enabled建立後持久化在 Session 上,之後不能修改。resources中的檔案必須已通過 Files API 上傳。