HTML frames (render contract, frame check)
POST /api/html-framesFreeze frames of an animation under the render contract: the page defines window.renderAt(t).
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
| Name | Type | Required | Description |
|---|---|---|---|
html | string | yes | A 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. |
times | array of number | yes | 1 to 12 times in seconds (0 to 3600), one still each |
width | integer | no | Viewport width in px, 16 to 1280 (default 640) The example sends 320. |
height | integer | no | Viewport height in px, 16 to 720 (default 360) The example sends 180. |
compare | object | no | Optional 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
POST /api/html-framesfrom $0.02 USDCPAYMENT-SIGNATUREon 14 chains200 OKAgent402-ReceiptEd25519Example 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"
}
}| Field | Type | Always present | In the example |
|---|---|---|---|
width | number | yes | 320 |
height | number | yes | 180 |
frameCount | number | yes | 3 |
frames | array of objects | yes | 3 items in the example |
contactSheet | object | yes | 6 fields: columns, rows, width, height, bytes, pngBase64 |
totalBytes | number | yes | 5168 |
network | object | yes | 2 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
- Pay per request ($0.02 to $0.04, quoted from this body) over x402 or MPP. Wallet-only: this tool reaches the network or stored state, so it has no proof-of-work tier. A prepaid card-credits key (
Authorization: Bearer a402_...) also pays it. - Required:
htmlandtimes; a rejected input answers 4xx witherror,tool,expected,requiredandexample. - On this route, a call ending in any status of 400 or above is not charged over x402, MPP or a credits key. A Tempo push credential pays before the call; a failure is a refund owed.
- A bodyless
GETorHEADreturns the same 402 quote. - An
Idempotency-Keyreplays the first 200 uncharged (an answer larger than 1 MB is not replayed).
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