HTTP API quick start

The Vmake Labs HTTP API lets your server fetch config, upload media, consume quota, submit tasks, and query results. Every request is signed with SDK-HMAC-SHA256. This page gets you from API keys to a finished task with cURL. To use Python instead, see the Python SDK quick start.

Set up your environment

You need Bash, cURL 7.55 or later, jq, and Python 3. Create an Access Key and Secret Key in the Vmake Labs developer center, then set MT_AK and MT_SK in your terminal. Paste the commands below into Bash. They save the signing script as vmake-sign.py in the current directory and define the api function, which generates the signature headers for each request and sends the exact signed body with cURL.

cat > vmake-sign.py <<'PY'
import hashlib, hmac, base64, datetime
from urllib.parse import urlparse, parse_qs, urlencode

ALGO = "SDK-HMAC-SHA256"

def _canonical_uri(path):
    if not path or not path.endswith("/"):
        path = (path or "") + "/"
    return path

def _canonical_query(query):
    pairs = sorted(parse_qs(query).items())
    return urlencode(pairs, doseq=True)

def sign(ak, sk, method, url, headers, body=""):
    headers = {k: v for k, v in headers.items()}
    if "X-Sdk-Date" not in headers:
        headers["X-Sdk-Date"] = datetime.datetime.now(datetime.timezone.utc).strftime("%Y%m%dT%H%M%SZ")

    low = {k.lower(): v.strip() for k, v in headers.items()}
    signed = sorted(low.keys())
    canonical_headers = "\n".join(f"{k}:{low[k]}" for k in signed)
    signed_str = ";".join(signed)

    u = urlparse(url)
    payload_hash = headers.get("X-Sdk-Content-Sha256") or hashlib.sha256(body.encode()).hexdigest()
    canonical = f"{method}\n{_canonical_uri(u.path)}\n{_canonical_query(u.query)}\n{canonical_headers}\n{signed_str}\n{payload_hash}"
    string_to_sign = f"{ALGO}\n{headers['X-Sdk-Date']}\n{hashlib.sha256(canonical.encode()).hexdigest()}"

    signature = hmac.new(sk.encode(), string_to_sign.encode(), hashlib.sha256).hexdigest()
    header_value = f"{ALGO} Access={ak}, SignedHeaders={signed_str}, Signature={signature}"
    headers["Authorization"] = "Bearer " + base64.b64encode(header_value.encode()).decode()
    return headers

if __name__ == "__main__":
    import os
    import sys

    method, url = sys.argv[1:]
    body = sys.stdin.buffer.read().decode("utf-8")
    headers = {"Host": urlparse(url).netloc}
    if method == "POST":
        headers["Content-Type"] = "application/json"
    for name, value in sign(os.environ["MT_AK"], os.environ["MT_SK"],
                            method, url, headers, body).items():
        print(f"{name}: {value}")
PY

api() {
  local method="$1" url="$2" body="${3-}" headers
  local args=()
  headers=$(printf '%s' "$body" | python3 vmake-sign.py "$method" "$url") || return 1
  if [[ "$method" == POST ]]; then
    args=(--data-binary "$body")
  fi
  curl --silent --show-error --fail -X "$method" "$url" \
    -H @- "${args[@]}" <<< "$headers"
}

platform="https://${WAPI_ENDPOINT:-wapi-skill.vmake.ai}"

# vmake_run <tool_id> [params_json] [media_url ...]
# Gets the config, consumes quota, submits the task, and polls until it finishes.
vmake_run() {
  local tool="$1" overrides="${2:-}" config tool_cfg region policy ai base consume body submitted status task_id query_path
  shift 2 2>/dev/null || shift $#
  [[ -n "$overrides" ]] || overrides='{}'
  local urls
  urls=$(jq -cn '$ARGS.positional' --args "$@") || return 1

  config=$(api POST "$platform/skill/config.json" '{"gid":"","version":"v2.0.3","supported_schemas":["v2"]}') || return 1
  tool_cfg=$(jq -ec --arg id "$tool" '.response.algorithm.invoke[$id]' <<< "$config") \
    || { echo "Tool $tool is not in your catalog." >&2; return 1; }

  region=$(jq -er '.response.algorithm.regions | to_entries[0].value' <<< "$config")
  [[ "$region" == https://* ]] || region="https://$region"
  policy=$(api GET "${region%/}/ai/token_policy?type=$(jq -r '(.response.algorithm | .token_policy_types.ai // .token_policy_type // "mtai") | @uri' <<< "$config")") || return 1
  ai=$(jq -ec '.data.mtai.api | .[.order[0]]' <<< "$policy")
  base=$(jq -er '.url' <<< "$ai"); [[ "$base" == https://* ]] || base="https://$base"

  consume=$(api POST "$platform/skill/consume.json" "$(jq -cn --argjson config "$config" --arg id "$tool" \
    --argjson tool "$tool_cfg" --argjson o "$overrides" --argjson urls "$urls" '
    {gid:$config.response.gid, task:$id, urls:$urls}
    + (if ($urls|length) > 0 then {url:$urls[0]} else {} end)
    + (if $tool.params_schema then {params:$o} else {} end)')") || return 1
  [[ $(jq -r '.meta.code' <<< "$consume") == 0 ]] || { jq '.meta' <<< "$consume" >&2; return 1; }

  body=$(jq -cn --argjson tool "$tool_cfg" --argjson ai "$ai" --argjson consume "$consume" \
    --argjson o "$overrides" --argjson urls "$urls" '
    def merge(a; b): reduce (b|keys_unsorted[]) as $k (a;
      .[$k] = (if (a[$k]|type) == "object" and (b[$k]|type) == "object" then merge(a[$k]; b[$k]) else b[$k] end));
    {task:$tool.task, task_type:($tool.task_type // "mtlab"),
     params:(merge($tool.params // {}; $o) | tojson),
     init_images:([$urls[] | {url:.}] | if $tool.profile and length > 0 then .[0].profile = $tool.profile else . end),
     context:($consume.response.context // ""), sync_timeout:$ai.sync_timeout}')
  submitted=$(api POST "${base%/}/$(jq -r '.push_path | ltrimstr("/")' <<< "$ai")" "$body") || return 1

  status=$(jq -r '.data.status' <<< "$submitted")
  if [[ "$status" != 9 ]]; then jq '.data' <<< "$submitted"; return; fi
  task_id=$(jq -er '.data.result.id | tostring' <<< "$submitted")
  echo "task_id: $task_id" >&2
  query_path=$(jq -r '.status_query.path | ltrimstr("/")' <<< "$ai")
  local delays=($(jq -r '.status_query.durations | split(",")[]' <<< "$ai")) i=0 result deadline=$((SECONDS + 3600))
  while (( SECONDS < deadline )); do
    sleep "$(awk "BEGIN{print ${delays[$(( i < ${#delays[@]} ? i : ${#delays[@]} - 1 ))]}/1000}")"
    i=$((i + 1))
    result=$(api GET "${base%/}/$query_path?task_id=$(jq -rn --arg v "$task_id" '$v|@uri')") || continue
    status=$(jq -r '.data.status' <<< "$result")
    case "$status" in 10|2|20) jq '.data' <<< "$result"; return ;; esac
  done
  echo "Still running after 60 minutes. Resume with the status query on /api-task-status using task_id $task_id." >&2
  return 1
}

Run your first task

In the same Bash session, run image watermark removal (SKM0006) on an image you are authorized to edit. The image must be readable at a public HTTPS URL. To use a local file, upload it to OSS first.

This command consumes quota.

vmake_run SKM0006 '{"parameter":{"rsp_media_type":"url"}}' 'https://example.com/your-image.jpg'

vmake_run prints data from the final response. When data.status is 10, the result URL is in data.result. When it is 2 or 20, read data.msg and see Errors and troubleshooting. For a 401, check your signer against the fixed-input test and your system clock.

Each tool page has a vmake_run example. Generation tools such as Seedance video generation take a prompt instead of media.

The function requests catalog version v2.0.3, which includes the generation tools. To see what each step sends, run the cURL examples on the pages below in order.

Integration steps

Sign every business request with the signing algorithm. Click a node to open its page. Dashed lines are optional steps: skip the upload when your media already has a public URL. When a submission or query returns 2 or 20, read data.msg and see Errors and troubleshooting.

Local media

Status 10

Status 9

Status 10

Get config

Get token policy

Upload media to OSS

Consume quota

Submit task

Read result

Poll task status

Local media

Status 10

Status 9

Status 10

Get config

Get token policy

Upload media to OSS

Consume quota

Submit task

Read result

Poll task status

Hosts

PurposeHostNotes
Config / quotawapi-skill.vmake.aiCan be overridden with the WAPI_ENDPOINT environment variable
Token policyalgorithm.regions[region]Returned by the config API
Task submission / status queryurl in the AI policyAppend push_path or status_query.path from the policy
Media uploadOSS endpoint returned by the token policyTemporary credentials use Aliyun OSS's own signing

Credentials

  • Create an Access Key (AK) and Secret Key (SK) on the API keys page of the Vmake Labs developer center. They are used to sign requests.
  • Vmake Labs business requests sign a canonical request with HMAC-SHA256. The signature header is Authorization: Bearer <base64>.
  • For details, see Signing.

Versions and config

  • Fetch /skill/config.json each time your process starts to get the latest endpoints and tool list.
  • The schema field in the response identifies the catalog version (currently "v2"). If you do not recognize the schema, fail closed. Do not guess its structure.
  • response.need_update == true or notices[].code == "skill_upgrade_available" means a new version is available.
  • Send response.gid in later quota requests. Usually you cache it locally and reuse it.

Next steps