全部產品
Search
文件中心

Qoder CN 系列:建立 Schedule

更新時間:Jul 15, 2026

建立可重複觸發或手動觸發的 Template 執行配置。

POST /api/v1/forward/schedules

Schedule 綁定一個 Identity、一個 Template、初始事件、觸發策略和執行策略。每次觸發都會產生獨立 Schedule Run。

要求標頭

Header

是否必填

說明

Authorization

Bearer <PAT>

Content-Type

application/json

Idempotency-Key

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

請求體參數

參數

類型

是否必填

說明

identity_id

string

Schedule 所屬 Forward Identity ID。

template_id

string

要執行的 Forward Template ID。

name

string

Schedule 名稱。

description

string

Schedule 描述。

initial_events

array

每次執行注入的初始事件,當前支援 user.message

execution

object

執行策略;省略時使用服務端預設值。

trigger_policy

object|null

觸發策略;省略或 null 時按 manual 處理。

environment_id

string

執行環境。

metadata

object

業務中繼資料,僅用於標籤或透傳。

觸發策略

trigger_policy 是按 type 分發的對象。建立和更新要求只接收配置欄位:typeexpressiontimezoneupcoming_runs_atlast_run_at 是服務端計算出的響應欄位。

欄位

類型

是否必填

說明

type

string

crononceintervalmanual

expression

string

條件必填

觸發運算式;crononceinterval 必填,manual 不需要。

timezone

string

條件必填

IANA timezone,例如 Asia/Shanghaicron 必填,once 在運算式不帶時區時必填,intervalmanual 可省略。

upcoming_runs_at

array

響應返回

後續觸發時間,UTC ISO 8601。當前實現返回 [] 或最多一個下一次計劃觸發時間。

last_run_at

string|null

響應返回

最近一次觸發時間。

type

建立/更新入參

說明

cron

typeexpressiontimezone

使用 5 欄位 cron 運算式按指定 IANA timezone 重複觸發。

once

typeexpression、可選 timezone

按 ISO 8601 時間觸發一次;運算式不帶 offset 時必須提供 timezone

interval

typeexpression

按 ISO 8601 duration 重複觸發,例如 PT15M

manual

type

不自動觸發,只能通過 Run Schedule 介面手動執行。

type

expression 格式

樣本

說明

cron

標準 5 欄位 cron

0 9 * * *

分鐘級日曆規則;不支援秒欄位和 6 欄位 cron。

once

ISO 8601 絕對時間

2026-06-23T09:00:002026-06-23T01:00:00Z

目標時間必須至少晚於服務端目前時間 1 分鐘。

interval

ISO 8601 duration

PT15MPT1HP1D

固定間隔觸發,最小粒度 1 分鐘。

manual

省略或Null 字元串

-

不產生計劃觸發時間。

執行策略

欄位

類型

預設值

說明

session_mode

string

new_session

Session 使用方式,取值 new_sessionreuse_session

max_concurrent_runs

integer

1

同一個 Schedule 最大並發 Run 數。

max_attempts

integer

1

預留欄位;當前實現只記錄、校正和回顯,單個 Run 仍只執行一次。

timeout_ms

integer

300000

單次嘗試逾時時間。

session_mode

說明

new_session

每次觸發都建立新的執行 Session,不延續歷史上下文。

reuse_session

Forward 為該 Schedule 管理一個固定執行 Session,並在多次觸發間持續使用;調用方不能指定任意已有 session_id

樣本請求

curl -s -X POST 'https://api.qoder.com.cn/api/v1/forward/schedules' \
  -H "Authorization: Bearer $QODER_PAT" \
  -H "Content-Type: application/json" \
  -d '{
  "identity_id": "idn_019eabc123",
  "template_id": "tmpl_support",
  "name": "Daily tech brief",
  "description": "Generate a daily technology news summary",
  "initial_events": [
    {
      "type": "user.message",
      "content": "Summarize current technology news in five bullet points."
    }
  ],
  "trigger_policy": {
    "type": "cron",
    "expression": "0 9 * * *",
    "timezone": "Asia/Shanghai"
  },
  "execution": {
    "session_mode": "new_session",
    "max_concurrent_runs": 1,
    "max_attempts": 1,
    "timeout_ms": 300000
  },
  "environment_id": "env_019e64e01a137caf953ac2ac7b42ec5c"
}'

樣本響應

HTTP 200 OK

{
  "id": "sched_019f00112233445566778899aabbccdd",
  "identity_id": "idn_019eabc123",
  "template_id": "tmpl_support",
  "name": "Daily tech brief",
  "description": "Generate a daily technology news summary",
  "status": "active",
  "initial_events": [
    {
      "type": "user.message",
      "content": "Summarize current technology news in five bullet points."
    }
  ],
  "execution": {
    "session_mode": "new_session",
    "max_concurrent_runs": 1,
    "max_attempts": 1,
    "timeout_ms": 300000
  },
  "trigger_policy": {
    "type": "cron",
    "expression": "0 9 * * *",
    "timezone": "Asia/Shanghai",
    "upcoming_runs_at": [
      "2026-06-23T01:00:00Z"
    ]
  },
  "environment_id": "env_019e64e01a137caf953ac2ac7b42ec5c",
  "sinks": [],
  "metadata": {},
  "created_at": "2026-06-22T10:00:00Z",
  "updated_at": "2026-06-22T10:00:00Z"
}

響應欄位

欄位

類型

說明

傳回值

object

建立後的完整 Schedule 對象。

錯誤

HTTP

Type

Code

觸發條件

400

invalid_request_error

invalid_trigger_policy

觸發策略類型或運算式不合法。

400

invalid_request_error

trigger_policy_too_frequent

觸發粒度小於 1 分鐘。

400

invalid_request_error

trigger_policy_time_too_soon

once 目標時間過近。

400

invalid_request_error

unsupported_sinks_input

HTTP 建立請求不支援傳入 sinks

404

not_found_error

identity_not_found

Identity 不存在。

404

not_found_error

template_not_found

Template 不存在。

401

authentication_error

authentication_required

PAT 無效或已到期。

備忘

  • HTTP 建立請求不接受 sinks;直接 API 建立的 Schedule 返回 sinks: []

  • manual Schedule 只能通過 Run Schedule 介面觸發。

  • once Schedule 的首次計劃 Run 進入終態後會自動歸檔。

相關