← Custom 404 Page Generator
Your token

Custom 404 Page Generator API

The 404.html file, its look, the checks, the server rules and every export run free in the browser and need no API. The API is for the one metered step: send a site's address, the pages it may link to and some text about the site, and get back, as JSON, the headline, the message and two to six links for the 404 page. The page checks each suggestion (only the site's own pages, no web address or emoji in the text, no figure that was not in the input) and uses the ones that pass.

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": "write".

taskWhat it doesReply
writeWrites a 404 page's headline (at most 60 characters) and message (at most 220) in the chosen tone, and picks 2 to 6 links back into the site, home first, every one taken from pages. Adds up to two notes. It never links to a page that is not in pages and never adds a figure that is not in the input.One JSON object

Input fields

FieldTypeMeaning
taskstring"write"
urlstringThe site's home address, for example https://example.com/.
site_namestringThe site's name.
aboutstringOptional: what the site is, its menu, a list of its pages or its sitemap.xml. May be empty. The page sends at most 4,000 characters: longer text keeps its start and end and loses the middle, with a marker line.
pagesstringThe paths the reply may link to, one per line, root-relative, starting with /. The page builds it from the links already on the 404 page and the site's own addresses found in about (at most 60).
tonestringfriendly, plain or playful.
currentstringJSON text with the headline, message and links (each {label, href}) already on the page. Send "{}" if you have none.
clipped_notestringEmpty, or a sentence saying the middle of about was cut.

The reply

job.output.output is text holding one JSON object: headline, message, links (an array of {"label", "href"}, home first) and notes (0 to 2 strings). Put them into your own 404 page, or paste them into the page. If the balance ran low, truncated is true and the object may stop early; the page keeps every part that arrived whole.

Worked example

Input (input.json):

{
  "task": "write",
  "url": "https://harbourlanedental.co.uk/",
  "site_name": "Harbour Lane Dental",
  "about": "Harbour Lane Dental is a family dental practice in Bristol. We see NHS and private patients.\nMain menu: Home (/), Treatments (/treatments), Emergency appointments (/emergency), Prices (/prices), Meet the team (/team), Book online (/book), Contact (/contact), Privacy notice (/privacy), Cookie policy (/cookies).\nOpen Monday to Friday, 8am to 6pm.",
  "pages": "/\n/treatments\n/emergency\n/prices\n/team\n/book\n/contact\n/privacy\n/cookies",
  "tone": "friendly",
  "current": "{\"headline\":\"Page not found\",\"message\":\"Sorry, we can't find that page. It may have moved, or the link may have a typo.\",\"links\":[{\"label\":\"Home\",\"href\":\"/\"}]}",
  "clipped_note": ""
}

Reply:

{"headline":"We can't find that page","message":"It may have moved, or the link may have a typo. Try one of these instead, or head to Book online to arrange a visit.","links":[{"label":"Home","href":"/"},{"label":"Treatments","href":"/treatments"},{"label":"Emergency","href":"/emergency"},{"label":"Prices","href":"/prices"},{"label":"Book online","href":"/book"},{"label":"Contact us","href":"/contact"}],"notes":[]}

On the page, this reply sets the headline and message and six links, and every link is one of the site's own pages.

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://custom-404-page.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":"custom-404-page"}' | 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": "write", "url": "https://example.com/", "site_name": "Example", "about": "...", "pages": "/\n/blog", "tone": "friendly", "current": "{}", "clipped_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="custom-404-page:write:$(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: headline, message, links, notes
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: custom-404-page:write:$(shasum -a 256 input.json | cut -c1-16):a1" --data @input.json