← Mobile-Friendly Test
Your token

Mobile-Friendly Test API

The check itself (the phone screen, the measurements, the HTML and CSS checks and the plain fixes) runs free in the browser and needs no API. The API is for the one metered step: send the findings the check made, the class and id names in the page and its CSS rules, and get back, as JSON, a short summary and, for every finding, a priority (1 fix first, 2 fix soon, 3 when convenient), one sentence on why it matters on a phone, and a fix in CSS or HTML fitted to your CSS. The page checks every fix and refuses any that styles a class or id the page does not have, loads anything, hides content or turns zoom off.

Base URL: https://api.skillsafe.ai/v1/app-api. Every response is {"data": ...} or {"error": {"code", "message"}}; read error.code and error.message rather than the HTTP status alone.

The task field

This app has one task. Always send "task": "fix".

taskWhat it doesReply
fixPuts every finding in order, says why each matters on a phone and writes a CSS or HTML fix for it, only from what you sent.One JSON object

Input fields

All values are strings. task and findings are required.

FieldMeaning
task"fix"
widthThe phone width the page was checked at, in CSS pixels: "360", "390", "412" or "768".
pageThe page's title.
findingsJSON text: [{id, level, code, what, sel, where}], ids f1, f2 and so on, worst first; level is bad, warn or info; code names the kind of finding (viewport-missing, fixed-width, small-text, field-zoom, hover-only, m-overflow, m-tap-close and others); sel and where are optional. At most 30.
namesJSON text: every class and id in the page, as [".name", "#name"]. At most 300.
cssThe page's CSS rules, one per line, the rules a finding names first; at most 6,000 characters of whole rules.
noteEmpty, or a sentence saying what was cut.

The reply

job.output.output is text holding one JSON object with two keys: summary (20-400 characters) and fixes, one {id, priority, why, css, html} per finding sent: priority 1, 2 or 3, why 10-240 characters, css empty or valid CSS of at most 1,500 characters, html empty or at most 600 characters and only for viewport, form field keyboard, table, first image, plugin, hidden content, pop-up and mobile page findings. Before using it, check that every id is one you sent, that every class and id the CSS styles is in your page, that the CSS has no url(), @import or display: none, and that no reason quotes a number the check did not find; the page does all of this and lists what it refused. If the balance ran low, truncated is true and the object may stop early; the page keeps every fix that arrived whole.

Worked example

Input (input.json), the blog post sample on the page:

{
  "task": "fix",
  "width": "390",
  "page": "How we cut our build time in half",
  "findings": "[{\"id\":\"f1\",\"level\":\"bad\",\"code\":\"m-overflow\",\"what\":\"Measured: the page is 21 px wider than the 390 px screen and scrolls sideways. Widest: p (395 px), table (388 px).\",\"sel\":\"p, table\"},{\"id\":\"f2\",\"level\":\"info\",\"code\":\"viewport-scale\",\"what\":\"Add initial-scale=1 to the viewport tag so the page opens at its real size after the phone is turned.\",\"where\":\"line 5\"},{\"id\":\"f3\",\"level\":\"info\",\"code\":\"table-scroll\",\"what\":\"1 table and no scroll box. A table with several columns is wider than a phone; wrap it so it scrolls on its own and the page does not.\",\"where\":\"line 23\"},{\"id\":\"f4\",\"level\":\"info\",\"code\":\"lazy-first\",\"what\":\"The first image (<img>) is lazy-loaded. If it is at the top of the page, that delays the largest thing a phone draws; load it normally.\",\"where\":\"line 21\"},{\"id\":\"f5\",\"level\":\"info\",\"code\":\"no-media\",\"what\":\"No media queries in the CSS read, so the layout is the same at every width.\"}]",
  "names": "[\".byline\"]",
  "css": "table { border-collapse: collapse }\nbody { font: 17px/1.6 Georgia, serif; margin: 0; padding: 0 16px; color: #1d1d1f }\narticle { max-width: 680px; margin: 0 auto }\nimg { max-width: 100%; height: auto }\npre { background: #f5f5f7; padding: 12px; overflow-x: auto; font-size: 14px }\ntd, th { border: 1px solid #ddd; padding: 6px 10px }\n.byline { color: #666; font-size: 15px }",
  "note": ""
}

Reply:

{"summary":"On a phone this page scrolls sideways because a paragraph and a table are wider than the 390 px screen. Fix that first, then the small viewport and image-loading tweaks.","fixes":[{"id":"f1","priority":1,"why":"Readers have to drag the page left and right to follow the text, because a long unbroken string in a paragraph and the table push past the screen edge.","css":"p, table { max-width: 100%; overflow-wrap: anywhere; }\ntable { display: block; overflow-x: auto; }","html":""},{"id":"f2","priority":3,"why":"Without it, some phones open the page zoomed in or at the wrong size after you turn them sideways and back.","css":"","html":"<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">"},{"id":"f3","priority":3,"why":"A wide table that cannot scroll by itself drags the whole page sideways, and the scroll rule on the table in the first fix already lets it scroll alone.","css":"","html":""},{"id":"f4","priority":3,"why":"A lazy-loaded picture at the top of the page shows up late, so people on a slow connection see a blank gap where it belongs.","css":"","html":"<!-- remove loading=\"lazy\" from the first image -->\n<img src=\"...\" alt=\"...\" width=\"...\" height=\"...\">"},{"id":"f5","priority":3,"why":"Every phone gets the same layout as a desktop screen, so spacing and sizes are never tuned for a narrow display.","css":"","html":""}]}

On the page, every fix checks out: the fixes view and the fixed page use these rules, and each finding shows its reason.

Errors

HTTPWhat to do
401The token is missing, expired or a guest token on a run. Get a personal token on the token page.
402The balance is below what the run reserves. Top up at skillsafe.ai/account/billing.
400The body is not a JSON object of the fields above.
429Wait and retry with the same Idempotency-Key.

Step 1 — a tiny client helper

One function that sends JSON and unwraps the {data, error} envelope.

BASE="https://api.skillsafe.ai/v1/app-api"
TOKEN="paste-your-token-here"   # from https://mobile-friendly-test.skillsafe.ai/tokens.html
api() { # api METHOD PATH [JSON-BODY]
  curl -s -X "$1" "$BASE$2" -H "Content-Type: application/json" \
    ${TOKEN:+-H "Authorization: Bearer $TOKEN"} ${3:+--data "$3"}
}

Step 2 — a token

A guest token is enough for /me and /estimate. A run is metered, so it needs your personal token: sign in on the token page and copy it.

# a guest token (enough for /me and /estimate); a run needs your personal token from /tokens.html
TOKEN=$(curl -s -X POST "$BASE/guest" -H "Content-Type: application/json" -d '{"slug":"mobile-friendly-test"}' | jq -r '.data.token')

Step 3 — who am I, and my balance

subject_type is guest or user; credits is the balance (1 credit = $0.0001).

api GET /me | jq '.data | {subject_type, credits}' 

Step 4 — price a run for free

/estimate charges nothing and starts no job. hold_credits is the amount reserved while a run is in flight, not the price; the run is charged what it uses.

# input.json: the run input object - {"task": "fix", "width": "390", "page": "My page", "findings": "[...]", "names": "[...]", "css": "...", "note": ""}
api POST /estimate "$(cat input.json)" | jq '.data | {hold_credits, min_credits, model, model_alias, markup_bps, warnings}' 

Step 5 — run it and wait for the job

Send an Idempotency-Key derived from the input: a retry with the same key is never billed twice.

KEY="mobile-friendly-test:fix:$(shasum -a 256 input.json | cut -c1-16):a1"
JOB=$(curl -s -X POST "$BASE/run" -H "Content-Type: application/json" -H "Authorization: Bearer $TOKEN" \
  -H "Idempotency-Key: $KEY" --data @input.json | jq -r '.data.job_id')
while :; do
  J=$(api GET "/jobs/$JOB"); S=$(echo "$J" | jq -r '.data.status')
  case "$S" in succeeded|failed|cancelled) break;; esac; sleep 2
done
echo "$J" | jq -r '.data.output.output' > reply.json   # one JSON object: summary, fixes
echo "$J" | jq '.data | {charged_credits, truncated}' 

Step 6 — or stream it

/run-stream sends Server-Sent Events while the job runs and the finished job at the end.

# Server-Sent Events: tick/delta events while the job runs, then a final event with the job
curl -N -s -X POST "$BASE/run-stream" -H "Content-Type: application/json" -H "Authorization: Bearer $TOKEN" \
  -H "Idempotency-Key: mobile-friendly-test:fix:$(shasum -a 256 input.json | cut -c1-16):a1" --data @input.json