Submit a task

Submits one AI task. The input is the underlying task path, media URLs, tool parameters, and context. The output is either a synchronous result or a task_id for an asynchronous task that you poll.

Request

FieldValue
MethodPOST
HostThe host of url in the AI policy
Pathpush_path from the AI policy, such as ai/task_push
Content-Typeapplication/json
AuthSDK-HMAC-SHA256. See Signing

Request body

{
  "task": "/v1/eraser_watermark_v2_async",
  "task_type": "mtlab",
  "params": "{\"parameter\":{\"rsp_media_type\":\"url\"}}",
  "init_images": [{ "url": "https://<bucket>.oss-<region>.aliyuncs.com/path/to/xxx" }],
  "context": "<from consume response>",
  "sync_timeout": 10
}
FieldRequiredDescription
taskYesUnderlying task path, read from algorithm.invoke[material_id].task in /skill/config.json. This is not the material_id
task_typeYesTask type: mtlab / speedup / workflow / inference
paramsYesStringified JSON (a JSON string, not an object). Its structure is defined by the tool. Deep-merge the defaults from algorithm.invoke[material_id].params
init_imagesNoMedia list, such as [{"url": "..."}]. Generation tasks without reference images send []
contextNoThe context string returned by the quota API, unchanged
sync_timeoutNoSeconds to wait synchronously, read from sync_timeout in the AI policy

task_type values

ValueDescriptionTypical tools
mtlabGeneral tool tasks (including async)SKM0004 image quality enhancement, SKM0006 image watermark removal
speedupAccelerated channel for heavy video tasksSKM0001 video quality enhancement, SKM0002 video subtitle removal
workflowOrchestrated workflowsSKM0005 video smart removal (Pro model of video smart removal), SKM0007 video watermark removal
inferenceInference tasks (txt2img / img2img)Custom tasks

Response

Completed synchronously

{
  "data": {
    "status": 10,
    "result": { "...": "..." }
  }
}

Read data.result directly.

Accepted asynchronously

{
  "data": {
    "status": 9,
    "result": { "id": "<task_id>" }
  }
}

Continue with Poll task status.

Failed

{
  "data": {
    "status": 2,
    "msg": "..."
  }
}

See Errors and troubleshooting.

cURL example

Continuing from the config, ai, media_url, and consume variables on the previous pages. First build the submission URL:

base=$(jq -er '.url' <<< "$ai")
[[ "$base" == https://* ]] || base="https://$base"
push=$(jq -er '.push_path' <<< "$ai")

Then read the default parameters for SKM0006 from the config, serialize params as a JSON string, and submit:

body=$(jq -cn --argjson config "$config" --argjson ai "$ai" --argjson consume "$consume" --arg url "$media_url" '
  $config.response.algorithm.invoke.SKM0006 as $t |
  {task:$t.task, task_type:($t.task_type // "mtlab"),
   params:(($t.params | .parameter.rsp_media_type = "url") | tojson),
   init_images:[({url:$url} + (if $t.profile then {profile:$t.profile} else {} end))],
   context:($consume.response.context // ""), sync_timeout:$ai.sync_timeout}')
submitted=$(api POST "${base%/}/${push#/}" "$body")
echo "$submitted" | jq '.data'

If data.status is 10, read data.result. If it is 9, query it as in Poll task status. If the submission times out, check the original request first so you are not charged twice.

Notes

  • Serialize the merged parameter object as a JSON string and put it in the params field of the body.
  • The Host header must match the URL and be signed. Strip the scheme when you extract the host from the AI policy's url.
  • Send context only when the quota API returns one. Do not make up a value when there is no quota context.

Next steps