跳到主要内容

接口参考:任务

Base URL:https://open.keydatas.com。所有接口需要 Authorization: Bearer <API Key>。

POST /api/v2/tasks/drafts​

生成任务草稿,不落任务。草稿 30 分钟内有效。

scope:task:write

请求头​

头必填说明
Idempotency-Key是建议 UUID;草稿幂等寿命 30 分钟

请求体​

字段类型必填默认说明
urlstring是-列表页或详情页 URL;http/https
fieldHintsstring[]否-期望字段名提示
intentstring否-自然语言需求,最长 800 字
typestring否list_detaillist_detail / detail / list
renderboolean否自动true 强制渲染;false 不渲染
schedulestring否-Quartz cron,如 0 0 3 * * ?

响应 data​

字段类型说明
draftIdstring32 位 hex
urlstring回显
typestring回显
fieldsFieldMeta[]name/type/description/required/format/sample/inferred/multiValue
samplesobject[]1 条样例
confidencenumber0~1
warningsstring[]降级说明;可能不存在
missingFieldsstring[]意图要求但未抽到的字段
trialSamplesinteger0~2
pageCntinteger当前固定 1
estimatedRecordsinteger预估记录数
estimatedTokensinteger预估 token
expiresAtinteger草稿过期时间,Unix 毫秒

错误​

HTTPcode场景
400invalid_paramurl 缺失、type 非法、缺少 Idempotency-Key
401unauthorizedKey 无效
422invalid_url内网 / 回环 / 非 http(s)
429rate_limited限流
503service_unavailable依赖不可用

示例​

curl -X POST https://open.keydatas.com/api/v2/tasks/drafts \
-H "Authorization: Bearer $KEYDATAS_API_KEY" \
-H "Idempotency-Key: $(uuidgen)" \
-H "Content-Type: application/json" \
-d '{
"url": "https://example.com/news",
"type": "list_detail",
"intent": "标题、链接、发布时间、正文"
}'

GET /api/v2/tasks​

列出当前用户任务。

scope:data:read

查询参数​

参数类型默认说明
pageinteger1页码,从 1 开始
pageSizeinteger201~100
statusstringallall / running / paused / stopped / error
keywordstring-只按任务名过滤
dbTypeinteger00 / 2 / 4
includestring-system 时包含系统托管任务

响应 data​

{
"items": [
{"id": 738590, "name": "新闻列表每日采集", "type": "list_detail",
"dbType": 0, "system": false, "status": "running",
"createdAt": 1760000000000, "updatedAt": 1760003600000}
],
"page": 1,
"pageSize": 20,
"total": 12
}

错误​

HTTPcode场景
400invalid_paramstatus/dbType 非法
401unauthorizedKey 无效
429rate_limited限流

POST /api/v2/tasks​

用草稿确认创建任务。

scope:task:write

请求头​

头必填说明
Idempotency-Key是重试复用同一个值

请求体​

字段类型必填说明
draftIdstring是草稿 ID
confirmboolean是必须为 true
namestring否最大 100;超出截断
schedulestring否只有 null 才沿用草稿;"" 表示手动任务

响应 data​

返回 Task 对象(id/name/type/dbType/system/status/createdAt/updatedAt)。 传入 cron 时,创建响应会回显 schedule。

错误​

HTTPcode场景
400invalid_param缺少字段、缺少 Idempotency-Key
403forbidden套餐并发/定时限制
409conflict草稿不存在/过期/已使用;幂等键不同请求体
422unprocessableconfirm 不为 true
500internal_error创建结果未知;用同一幂等键重试或查任务列表

示例​

curl -X POST https://open.keydatas.com/api/v2/tasks \
-H "Authorization: Bearer $KEYDATAS_API_KEY" \
-H "Idempotency-Key: $(uuidgen)" \
-H "Content-Type: application/json" \
-d '{"draftId":"b3f1...","confirm":true,"name":"新闻列表每日采集"}'

GET /api/v2/tasks/{taskId}​

任务详情与状态。

scope:data:read

路径参数​

参数类型说明
taskIdinteger任务 ID,≥1

响应 data​

Task 对象。schedule 与 lastRun 当前不返回。

错误​

HTTPcode场景
404not_found任务不存在或不属于当前账号

POST /api/v2/tasks/{taskId}/actions​

启动 / 暂停 / 继续 / 停止。

scope:task:run

请求头​

头必填说明
Idempotency-Key是重试复用同一个值

请求体​

字段类型必填说明
actionstring是start / pause / resume / stop(大小写不敏感)

响应 data​

{"taskId": 738590, "action": "start", "accepted": true, "status": "running"}

错误​

HTTPcode场景
400invalid_paramaction 非法、缺少 Idempotency-Key
403forbidden套餐并发限制
404not_found任务不存在
409conflict当前状态不允许该动作
422system_task_immutable对系统默认任务执行动作

示例​

curl -X POST https://open.keydatas.com/api/v2/tasks/738590/actions \
-H "Authorization: Bearer $KEYDATAS_API_KEY" \
-H "Idempotency-Key: $(uuidgen)" \
-H "Content-Type: application/json" \
-d '{"action":"start"}'

相关​