← Falling Leaves Generator
Your token

Falling Leaves Generator API

The leaves, the animation, the checks and every export run free in the browser and need no API. The API is for the one metered step: send a description of the scene you want and the current settings, and get back, as JSON, new settings: the leaf, its colours, the page colour, the number, size, fall speed, wind, tumble, slip, depth layers and strength. The page checks each setting (whole numbers in range, real #rrggbb colours, leaves visible on the page colour, hex codes from the description used, every leaf behind the text if the description asks for it) 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": "design".

taskWhat it doesReply
designTurns a description of a falling leaves scene into the page's settings: name, shape, colors (2-6 #rrggbb), bg, count (5-200), size (8-64 px), speed (5-100), wind (-100 to 100), tumble (0-100), slip (0-100), layers (1-3), opacity (20-100), front and up to three notes.One JSON object

Input fields

FieldTypeMeaning
taskstring"design"
briefstringThe description of the scene, for example "slow autumn maple fall over a dark hero, warm reds". The page sends at most 1,500 characters: longer text keeps its start and end and loses the middle, with a marker line.
currentstringJSON text with the settings now: shape, colors, bg, count, size, speed, wind, tumble, slip, layers, opacity, front. Send "{}" if you have none.
named_colorsstringColours found in brief, one per line: #fdf2f8 (hex code the visitor typed) or navy = #000080 (colour word). May be empty.
clipped_notestringEmpty, or a sentence saying the middle of brief was cut.

The reply

job.output.output is text holding one JSON object with the keys name, shape (maple, oak, birch, ginkgo, petal or snow), colors, bg ("" or #rrggbb), count, size, speed, wind, tumble, slip, layers, opacity, front (true or false) and notes. Paste the description into the page to see it fall, or feed the settings to the exported script yourself. 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": "design",
  "brief": "Slow autumn maple fall over the dark hero of our cafe website. Warm reds and amber, a light breeze to the right, let a couple of leaves cross the headline.",
  "current": "{\"shape\":\"maple\",\"colors\":[\"#6b0f0a\",\"#9b1c12\",\"#c2361a\",\"#de6420\",\"#d99a2b\"],\"bg\":\"#1c1917\",\"count\":40,\"size\":28,\"speed\":45,\"wind\":10,\"tumble\":55,\"slip\":50,\"layers\":3,\"opacity\":90,\"front\":true}",
  "named_colors": "",
  "clipped_note": ""
}

Reply:

{"name":"Cafe maple fall","shape":"maple","colors":["#7a1410","#a82a14","#cf4a1c","#e8782a","#e0a030"],"bg":"#1c1917","count":28,"size":28,"speed":20,"wind":15,"tumble":55,"slip":50,"layers":3,"opacity":90,"front":true,"notes":["Kept the dark hero background from your current settings."]}

On the page, this reply sets a slow maple fall in warm reds and amber over the dark hero, with a few near leaves crossing the headline.

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://falling-leaves-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":"falling-leaves-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": "design", "brief": "slow autumn maple fall over a dark hero", "current": "{}", "named_colors": "", "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="falling-leaves-generator:design:$(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: name, shape, colors, bg, ... front, 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: falling-leaves-generator:design:$(shasum -a 256 input.json | cut -c1-16):a1" --data @input.json