← Responsive Image Generator
Your token

Responsive Image Generator API

Opening the image, making the copies, the code and every download run free in the browser and need no API; the image never leaves it. The API is for the one metered step: send a plain-words description of where an image sits in a page layout, and get back, as JSON, one numeric rule per screen range and a placement id. The page builds this input for you, checks every number against the description and writes the sizes attribute from the rules.

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

taskWhat it doesReply
sizesReads a layout description into rules per screen range (columns, gap, padding, maximum width or a fixed width) and where on the page the image sits.One JSON object

Input fields

Every field is a string; page_facts holds JSON text. All three are required.

FieldMeaning
task"sizes"
descriptionThe visitor's own words, up to 800 characters: columns, gaps, padding, a maximum width, and the screen widths where the layout changes.
page_facts{image_width, image_height, placement_now, widths_now}, for context only.

The reply

job.output.output is text holding one JSON object: rules (1 to 6 objects, each {from, columns, gap, padding, container, fixed} in px; exactly one has from: 0), placement (hero, below or unsure) and reasons (ids such as breakpoints_from_description, columns_from_description, spacing_from_description, container_from_description, rem_converted, framework_breakpoints, hero_said, below_said). In a rule, the image is fixed px wide, or (min(screen, container) - 2 x padding - (columns - 1) x gap) / columns. The page turns the rules into the sizes attribute, largest from first: a capped container becomes a px value from the cap up and a calc() below it. Before using a rule, check it as the page does: every number must be written in the description (rem counted at 16 px, Tailwind or Bootstrap defaults only when the description names the framework). If the balance ran low, truncated is true and the object may stop early.

Worked example

Input (input.json), from the page's "Product grid" example:

{
  "task": "sizes",
  "description": "Product photos in the shop grid further down the page: 2 columns with a 16px gap on phones, 3 columns from 768px and 4 columns from 1200px. The grid sits in a 1200px container with 24px padding on each side.",
  "page_facts": "{\"image_width\":1400,\"image_height\":1096,\"placement_now\":\"below\",\"widths_now\":[400,800,1200]}"
}

Reply:

{"rules":[{"from":0,"columns":2,"gap":16,"padding":24,"container":1200,"fixed":0},{"from":768,"columns":3,"gap":16,"padding":24,"container":1200,"fixed":0},{"from":1200,"columns":4,"gap":16,"padding":24,"container":1200,"fixed":0}],"placement":"below","reasons":["breakpoints_from_description","columns_from_description","spacing_from_description","container_from_description","below_said"]}

The page writes from it: sizes="(min-width: 1200px) 276px, (min-width: 768px) calc((100vw - 80px) / 3), calc((100vw - 64px) / 2)"

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, or a required field is missing or empty.
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://responsive-image-generator.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":"responsive-image-generator"}' | 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": "sizes", "description": "Product photos in the shop grid further down the page: 2 columns with a 16px gap on phones, 3 columns from 768px and 4 columns from 1200px. The grid sits in a 1200px container with 24px padding on each side.", "page_facts": "{...}"}
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="responsive-image-generator:sizes:$(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: rules, placement, reasons
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: responsive-image-generator:sizes:$(shasum -a 256 input.json | cut -c1-16):a1" --data @input.json