Skip to content

HTML frames (render contract, frame check)

quoted per request from $0.02USDC via x402POST /api/html-frames

Freeze frames of an animation under the render contract: the page defines window.renderAt(t).

Category: Web & documentsTags: browser html render frames animation png canvas contact-sheetAlso found as: render-contract renderat renderat-frames contact-sheet frame-check motion-design-frame-check

Try in playground →

Details

The tool renders the self-contained HTML in headless Chromium, calls renderAt for each requested time and returns a base64 PNG still per time plus one contact-sheet PNG. The document's network requests are refused; data: and blob: URLs work. Optional compare (baseline stills, or baselineUrl, a second public document) adds similarity (0 to 1) and changedRegions per frame; a baselineUrl compare is quoted at twice the listed price ($0.04). A load error or a failing renderAt answers 400. Limits: html 512 KB, 1 to 12 times, 1280x720 (default 640x360), 5 s per renderAt, 25 s in all, 8 MB of PNG. Deterministic code, no model. Body: {"html":"<!doctype html>…","times":[0,0.5,1],"width":640?,"height":360?,"compare":{"baseline":[{"t":0,"png":"iVBORw0KGgo…"}]}?}.

Parameters

NameTypeRequiredDescription
htmlstringyesA self-contained HTML document (max 512 KB) that defines window.renderAt(t); it may return a promise Also accepted as content, body, markup, text, source.
timesarray of numberyes1 to 12 times in seconds (0 to 3600), one still each
widthintegernoViewport width in px, 16 to 1280 (default 640) The example sends 320.
heightintegernoViewport height in px, 16 to 720 (default 360) The example sends 180.
compareobjectnoOptional frame check: exactly one of baseline or baselineUrl. Adds similarity (0 to 1) and changedRegions to each compared frame. A baselineUrl renders a second document and is quoted at twice the listed price ($0.04)

Example request

curl -i -X POST https://agent402.tools/api/html-frames \
  -H "Content-Type: application/json" \
  -d '{"html":"<body style=margin:0><canvas id=c width=320 height=180></canvas><script>x=c.getContext('\''2d'\'');x.fillStyle='\''#4cc38a'\'';renderAt=t=>{x.clearRect(0,0,320,180);x.fillRect(20+t*100,70,40,40)}</script>","times":[0,1,2],"width":320,"height":180}'

Watch a call get paid

RequestPOST /api/html-frames
402from $0.02 USDC
SignPAYMENT-SIGNATURE
Settleon 14 chains
Answer200 OK
ReceiptAgent402-ReceiptEd25519

Example response

{
  "width": 320,
  "height": 180,
  "frameCount": 3,
  "frames": [
    {
      "t": 0,
      "bytes": 641,
      "pngBase64": "iVBORw0KGgo…"
    },
    {
      "t": 1,
      "bytes": 641,
      "pngBase64": "iVBORw0KGgo…"
    },
    {
      "t": 2,
      "bytes": 640,
      "pngBase64": "iVBORw0KGgo…"
    }
  ],
  "contactSheet": {
    "columns": 2,
    "rows": 2,
    "width": 664,
    "height": 420,
    "bytes": 3246,
    "pngBase64": "iVBORw0KGgo…"
  },
  "totalBytes": 5168,
  "network": {
    "blockedRequests": 0,
    "policy": "all network access refused; only inline script and style, and data: or blob: URLs the document builds itself"
  }
}
FieldTypeAlways presentIn the example
widthnumberyes320
heightnumberyes180
frameCountnumberyes3
framesarray of objectsyes3 items in the example
contactSheetobjectyes6 fields: columns, rows, width, height, bytes, pngBase64
totalBytesnumberyes5168
networkobjectyes2 fields: blockedRequests, policy

From an MCP client

catalog.call {
  "slug": "html-frames",
  "params": {
    "html": "<body style=margin:0><canvas id=c width=320 height=180></canvas><script>x=c.getContext('2d');x.fillStyle='#4cc38a';renderAt=t=>{x.clearRect(0,0,320,180);x.fillRect(20+t*100,70,40,40)}</script>",
    "times": [
      0,
      1,
      2
    ],
    "width": 320,
    "height": 180
  }
}

Hosted connector (https://agent402.tools/mcp): paid in the call. Stdio package (npx -y agent402-mcp@0.18.0): pays from a wallet or AGENT402_CREDITS_KEY.

Errors and behavior

Paid call (JavaScript agent)

import { wrapFetchWithPayment } from "@x402/fetch";
import { x402Client } from "@x402/core/client";
import { registerExactEvmScheme } from "@x402/evm/exact/client";
import { privateKeyToAccount } from "viem/accounts";

const client = new x402Client();
client.setSpendControls?.({ maxAmountPerPayment: "$0.04" }); // refuse any quote above this tool's price
registerExactEvmScheme(client, { signer: privateKeyToAccount(process.env.AGENT_KEY) });
const payFetch = wrapFetchWithPayment(fetch, client);

const res = await payFetch("https://agent402.tools/api/html-frames", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    "html": "<body style=margin:0><canvas id=c width=320 height=180></canvas><script>x=c.getContext('2d');x.fillStyle='#4cc38a';renderAt=t=>{x.clearRect(0,0,320,180);x.fillRect(20+t*100,70,40,40)}</script>",
    "times": [
      0,
      1,
      2
    ],
    "width": 320,
    "height": 180
  }),
});

Get a wallet or run npx -y agent402-mcp@0.18.0 wallet new.

The quote (Python)

import base64, json, urllib.error, urllib.request

req = urllib.request.Request("https://agent402.tools/api/html-frames", method="POST", data="{\"html\":\"<body style=margin:0><canvas id=c width=320 height=180></canvas><script>x=c.getContext('2d');x.fillStyle='#4cc38a';renderAt=t=>{x.clearRect(0,0,320,180);x.fillRect(20+t*100,70,40,40)}</script>\",\"times\":[0,1,2],\"width\":320,\"height\":180}".encode(), headers={"Content-Type": "application/json"})
try:
    urllib.request.urlopen(req)
except urllib.error.HTTPError as e:
    quote = json.loads(base64.b64decode(e.headers["PAYMENT-REQUIRED"]))
    print(e.code, [(a["network"], a["amount"]) for a in quote["accepts"]])  # the price, per chain, in base units

Related tools