接口参考:任务
Base URL:https://open.keydatas.com。所有接口需要 Authorization: Bearer <API Key>。
POST /api/v2/tasks/drafts
生成任务草稿,不落任务。草稿 30 分钟内有效。
scope:task:write
请求头
| 头 | 必填 | 说明 |
|---|---|---|
Idempotency-Key | 是 | 建议 UUID;草稿幂等寿命 30 分钟 |
请求体
| 字段 | 类型 | 必填 | 默认 | 说明 |
|---|---|---|---|---|
url | string | 是 | - | 列表页或详情页 URL;http/https |
fieldHints | string[] | 否 | - | 期望字段名提示 |
intent | string | 否 | - | 自然语言需求,最长 800 字 |
type | string | 否 | list_detail | list_detail / detail / list |
render | boolean | 否 | 自动 | true 强制渲染;false 不渲染 |
schedule | string | 否 | - | Quartz cron,如 0 0 3 * * ? |
响应 data
| 字段 | 类型 | 说明 |
|---|---|---|
draftId | string | 32 位 hex |
url | string | 回显 |
type | string | 回显 |
fields | FieldMeta[] | name/type/description/required/format/sample/inferred/multiValue |
samples | object[] | 1 条样例 |
confidence | number | 0~1 |
warnings | string[] | 降级说明;可能不存在 |
missingFields | string[] | 意图要求但未抽到的字段 |
trialSamples | integer | 0~2 |
pageCnt | integer | 当前固定 1 |
estimatedRecords | integer | 预估记录数 |
estimatedTokens | integer | 预估 token |
expiresAt | integer | 草稿过期时间,Unix 毫秒 |
错误
| HTTP | code | 场景 |
|---|---|---|
| 400 | invalid_param | url 缺失、type 非法、缺少 Idempotency-Key |
| 401 | unauthorized | Key 无效 |
| 422 | invalid_url | 内网 / 回环 / 非 http(s) |
| 429 | rate_limited | 限流 |
| 503 | service_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
查询参数
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
page | integer | 1 | 页码,从 1 开始 |
pageSize | integer | 20 | 1~100 |
status | string | all | all / running / paused / stopped / error |
keyword | string | - | 只按任务名过滤 |
dbType | integer | 0 | 0 / 2 / 4 |
include | string | - | 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
}
错误
| HTTP | code | 场景 |
|---|---|---|
| 400 | invalid_param | status/dbType 非法 |
| 401 | unauthorized | Key 无效 |
| 429 | rate_limited | 限流 |
POST /api/v2/tasks
用草稿确认创建任务。
scope:task:write
请求头
| 头 | 必填 | 说明 |
|---|---|---|
Idempotency-Key | 是 | 重试复用同一个值 |
请求体
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
draftId | string | 是 | 草稿 ID |
confirm | boolean | 是 | 必须为 true |
name | string | 否 | 最大 100;超出截断 |
schedule | string | 否 | 只有 null 才沿用草稿;"" 表示手动任务 |
响应 data
返回 Task 对象(id/name/type/dbType/system/status/createdAt/updatedAt)。
传入 cron 时,创建响应会回显 schedule。
错误
| HTTP | code | 场景 |
|---|---|---|
| 400 | invalid_param | 缺少字段、缺少 Idempotency-Key |
| 403 | forbidden | 套餐并发/定时限制 |
| 409 | conflict | 草稿不存在/过期/已使用;幂等键不同请求体 |
| 422 | unprocessable | confirm 不为 true |
| 500 | internal_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
路径参数
| 参数 | 类型 | 说明 |
|---|---|---|
taskId | integer | 任务 ID,≥1 |
响应 data
Task 对象。schedule 与 lastRun 当前不返回。
错误
| HTTP | code | 场景 |
|---|---|---|
| 404 | not_found | 任务不存在或不属于当前账号 |
POST /api/v2/tasks/{taskId}/actions
启动 / 暂停 / 继续 / 停止。
scope:task:run
请求头
| 头 | 必填 | 说明 |
|---|---|---|
Idempotency-Key | 是 | 重试复用同一个值 |
请求体
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
action | string | 是 | start / pause / resume / stop(大小写不敏感) |
响应 data
{"taskId": 738590, "action": "start", "accepted": true, "status": "running"}
错误
| HTTP | code | 场景 |
|---|---|---|
| 400 | invalid_param | action 非法、缺少 Idempotency-Key |
| 403 | forbidden | 套餐并发限制 |
| 404 | not_found | 任务不存在 |
| 409 | conflict | 当前状态不允许该动作 |
| 422 | system_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"}'