HTML frames (render contract, frame check)
POST /api/html-framesFreeze frames of an animation under the render contract: the page defines window.renderAt(t). Send POST /api/html-frames with the required fields html and times and pay quoted per request from $0.02 over x402 or MPP (there is no free tier). It returns a JSON object with width, height, frameCount, frames, contactSheet and 2 more.
The tool renders the self-contained HTML document in headless Chromium with all network access refused, calls renderAt for each requested time in seconds and returns a PNG still per time (base64) plus one contact-sheet PNG of every still in a grid. For previews and frame checks of canvas, SVG or CSS animations an agent wrote itself (motion design, motion graphics, generative art). Frame check: the optional compare input holds either baseline, an array of {t, png} stills (base64 PNG, one per requested time, from an earlier call or another renderer), or baselineUrl, the public URL of a second document under the same contract, fetched through the same public-URL guard as page-speed and rendered the same way; each compared frame then carries similarity (0 to 1 from the 32x18 grid of grayscale cell means; identical stills score 1) and changedRegions (bounding boxes of the differing cells in pixels, largest first, up to 16 with changedRegionsPartial saying how many there were). A compare by baselineUrl renders two documents, so that call is quoted at twice the listed price ($0.04) in its 402; a compare by baseline stills is quoted at the listed price. The document must carry everything inline: every request it makes (fetch, images, fonts, frames, sockets, navigations) is refused and counted; data: and blob: URLs it builds itself work. A script error while loading, a missing renderAt or a renderAt that throws answers 400. Limits: html up to 512 KB, 1 to 12 times, width up to 1280 and height up to 720 (default 640x360), 5 s per renderAt and 25 s for loading and every renderAt together, 8 MB of PNG output in all; a baseline of up to 12 stills and 8 MB of PNG, each still at most 1280x720. Deterministic code, no model. Body: {"html":"<!doctype html>…","times":[0,0.5,1],"width":640?,"height":360?,"compare":{"baseline":[{"t":0,"png":"iVBORw0KGgo…"}]}?} or "compare":{"baselineUrl":"https://…"}.
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) |
height | integer | no | Viewport height in px, 16 to 720 (default 360) |
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}'
Without payment this returns HTTP 402 Payment Required with the exact price for html-frames; any x402 v2 or MPP client pays it and retries.
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"
}
}
| 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
}
}
The hosted connector at https://agent402.tools/mcp needs a payment for html-frames; the stdio package pays it from a wallet or from an AGENT402_CREDITS_KEY issued earlier. Local install: npx -y [email protected].
Errors and behavior
htmlandtimesare required. An input the tool rejects returns an HTTP 4xx whose body carrieserror,tool,expected,requiredandexample, so the caller can correct it.- A paid call that ends in any status of 400 or above is not charged over x402, MPP or a prepaid credits key: settlement runs after the tool and only on a successful response. The exception is a Tempo push credential, a transfer the buyer sent before the call: it settles before the tool runs, so if the tool then fails the payment is recorded as a refund owed to the paying wallet.
- Wallet-only: this tool reaches the network or stored state, so it has no proof-of-work tier. A prepaid card-credits key issued earlier (
Authorization: Bearer a402_...) also pays it. - Priced per request: the 402 quotes this body, between $0.02 and $0.04.
- A
GETorHEADto /api/html-frames returns the same 402 quote, so the price can be read without a body. - An
Idempotency-Keyheader makes a retried paid call replay the first 200 instead of charging again (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(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
}),
});
Related tools
Hidden text scan
POST /api/hidden-text-scanCheck an email or web page for text a person reading it would not see but an AI reading it would: HTML comments.
HTML links
POST /api/html-linksEnumerate every <a href> in an HTML string with its anchor text and rel attribute.
HTML meta (from string)
POST /api/html-metaExtract <title>, <meta description>, OpenGraph/Twitter cards, canonical URL, and JSON-LD blocks from an HTML string.
HTML select
POST /api/html-selectRun a CSS selector against an HTML string and return the matches (text, attrs, and optionally outerHTML for each).
HTML strip to text
POST /api/html-stripStrip all HTML tags and return plain text.