← Recipe Scaler
Your token

Recipe Scaler API

Reading a recipe, scaling it, converting units and temperatures, the swap table, the shopping list and every download run free in the browser and need no API. The API is for the one metered step: send the ingredient lines the page works out (each with its food groups and the ids of its swaps in the table) and a note in the visitor's words, and get back, as JSON ids, which food groups to leave out, which lines the visitor does not have and one swap for every line that has to change. The page builds this input for you and checks every id before showing it.

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

taskWhat it doesReply
adaptReads a note such as "dairy-free" or "out of eggs" against a recipe's ingredient lines and picks one swap from the table for every line that has to change.One JSON object

Input fields

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

FieldMeaning
task"adapt"
factsJSON object: baking (true for a baked or leavened recipe), lines (each {id, text, tags, options}: L1, L2...; tags from dairy, egg, gluten, meat, fish, alcohol, sugar, nuts; options are swap ids S1 to S40) and options (each swap id named in a line: {for, use, ratio, context, tags}, context baking, sauce, marinade or any).
needUp to 300 characters, the visitor's own words.

The reply

job.output.output is text holding one JSON object: avoid (group ids the note asks to leave out; "vegan" means dairy, egg, meat and fish, "vegetarian" meat and fish, "pescatarian" meat), missing (line ids the note says the visitor does not have) and swaps, one {line, use} for every line that is missing or contains an avoided group, where use is one of that line's own option ids or "none". Before using it, check it as the page does: every avoided group is asked for in the note, every missing line is named in it, each swap is that line's own option and contains no avoided group, and a baking swap is used in a cooked dish only when nothing else fits. If the balance ran low, truncated is true and the object may stop early; the page keeps what arrived whole.

Worked example

Input (input.json), from the page's pancakes example doubled to 8, with the note "We are out of buttermilk and eggs":

{
  "task": "adapt",
  "facts": "{\"baking\":true,\"lines\":[{\"id\":\"L1\",\"text\":\"4 cups all-purpose flour\",\"tags\":[\"gluten\"],\"options\":[\"S25\",\"S26\"]},{\"id\":\"L2\",\"text\":\"4 tbsp sugar\",\"tags\":[\"sugar\"],\"options\":[\"S17\"]},{\"id\":\"L3\",\"text\":\"4 tsp baking powder\",\"tags\":[],\"options\":[\"S20\"]},{\"id\":\"L4\",\"text\":\"1 tsp baking soda\",\"tags\":[],\"options\":[\"S21\"]},{\"id\":\"L5\",\"text\":\"1 tsp salt\",\"tags\":[],\"options\":[]},{\"id\":\"L6\",\"text\":\"4 cups buttermilk\",\"tags\":[\"dairy\"],\"options\":[\"S1\",\"S2\",\"S3\"]},{\"id\":\"L7\",\"text\":\"4 large eggs\",\"tags\":[\"egg\"],\"options\":[\"S23\",\"S24\"]},{\"id\":\"L8\",\"text\":\"6 tbsp butter, melted, plus more for the pan\",\"tags\":[\"dairy\"],\"options\":[\"S14\",\"S15\"]},{\"id\":\"L9\",\"text\":\"2 tsp vanilla extract\",\"tags\":[],\"options\":[\"S27\"]}],\"options\":{\"S25\":{\"for\":\"flour\",\"use\":\"gluten-free 1:1 blend\",\"ratio\":\"1:1\",\"context\":\"baking\",\"tags\":[]},\"S26\":{\"for\":\"flour\",\"use\":\"cake flour (thicken)\",\"ratio\":\"1 cup AP = 1 cup cake flour - 2 Tbsp + 2 Tbsp cornstarch\",\"context\":\"baking\",\"tags\":[\"gluten\"]},\"S17\":{\"for\":\"sugar\",\"use\":\"honey\",\"ratio\":\"1 cup sugar = 3/4 cup honey; reduce liquid by 1/4 cup\",\"context\":\"baking\",\"tags\":[\"sugar\"]},\"S20\":{\"for\":\"baking powder\",\"use\":\"baking soda + cream of tartar\",\"ratio\":\"1 tsp = 1/4 tsp baking soda + 1/2 tsp cream of tartar\",\"context\":\"baking\",\"tags\":[]},\"S21\":{\"for\":\"baking soda\",\"use\":\"baking powder (triple)\",\"ratio\":\"1 tsp baking soda = 3 tsp baking powder\",\"context\":\"baking\",\"tags\":[]},\"S1\":{\"for\":\"buttermilk\",\"use\":\"milk + lemon juice\",\"ratio\":\"1 cup = 1 cup milk + 1 Tbsp lemon juice\",\"context\":\"baking\",\"tags\":[\"dairy\"]},\"S2\":{\"for\":\"buttermilk\",\"use\":\"milk + vinegar\",\"ratio\":\"1 cup = 1 cup milk + 1 Tbsp white vinegar\",\"context\":\"baking\",\"tags\":[\"dairy\"]},\"S3\":{\"for\":\"buttermilk\",\"use\":\"plain yogurt (thinned)\",\"ratio\":\"1 cup = 3/4 cup yogurt + 1/4 cup milk\",\"context\":\"any\",\"tags\":[\"dairy\"]},\"S23\":{\"for\":\"eggs\",\"use\":\"flax egg\",\"ratio\":\"1 egg = 1 Tbsp ground flax + 3 Tbsp water\",\"context\":\"baking\",\"tags\":[]},\"S24\":{\"for\":\"eggs\",\"use\":\"applesauce\",\"ratio\":\"1 egg = 1/4 cup unsweetened applesauce\",\"context\":\"baking\",\"tags\":[]},\"S14\":{\"for\":\"butter\",\"use\":\"oil\",\"ratio\":\"1 cup butter = 3/4 cup oil\",\"context\":\"baking\",\"tags\":[]},\"S15\":{\"for\":\"butter\",\"use\":\"coconut oil\",\"ratio\":\"1:1\",\"context\":\"baking\",\"tags\":[]},\"S27\":{\"for\":\"vanilla\",\"use\":\"vanilla bean paste\",\"ratio\":\"1:1\",\"context\":\"baking\",\"tags\":[]}}}",
  "need": "We are out of buttermilk and eggs"
}

Reply:

{"avoid":[],"missing":["L6","L7"],"swaps":[{"line":"L6","use":"S1"},{"line":"L7","use":"S23"}]}

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://recipe-scaler.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":"recipe-scaler"}' | 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": "adapt", "facts": "{\"baking\":true,\"lines\":[{\"id\":\"L1\",\"text\":\"4 cups all-purpose flour\",\"tags\":[\"gluten\"],\"options\":[\"S25\",\"S26\"]},{\"id\":\"L2\",\"text\":\"4 tbsp sugar\",\"tags\":[\"sugar\"],\"options\":[\"S17\"]},{\"id\":\"L3\",\"text\":\"4 tsp baking powder\",\"tags\":[],\"options\":[\"S20\"]},{\"id\":\"L4\",\"text\":\"1 tsp baking soda\",\"tags\":[],\"options\":[\"S21\"]},{\"id\":\"L5\",\"text\":\"1 tsp salt\",\"tags\":[],\"options\":[]},{\"id\":\"L6\",\"text\":\"4 cups buttermilk\",\"tags\":[\"dairy\"],\"options\":[\"S1\",\"S2\",\"S3\"]},{\"id\":\"L7\",\"text\":\"4 large eggs\",\"tags\":[\"egg\"],\"options\":[\"S23\",\"S24\"]},{\"id\":\"L8\",\"text\":\"6 tbsp butter, melted, plus more for the pan\",\"tags\":[\"dairy\"],\"options\":[\"S14\",\"S15\"]},{\"id\":\"L9\",\"text\":\"2 tsp vanilla extract\",\"tags\":[],\"options\":[\"S27\"]}],\"options\":{\"S25\":{\"for\":\"flour\",\"use\":\"gluten-free 1:1 blend\",\"ratio\":\"1:1\",\"context\":\"baking\",\"tags\":[]},\"S26\":{\"for\":\"flour\",\"use\":\"cake flour (thicken)\",\"ratio\":\"1 cup AP = 1 cup cake flour - 2 Tbsp + 2 Tbsp cornstarch\",\"context\":\"baking\",\"tags\":[\"gluten\"]},\"S17\":{\"for\":\"sugar\",\"use\":\"honey\",\"ratio\":\"1 cup sugar = 3/4 cup honey; reduce liquid by 1/4 cup\",\"context\":\"baking\",\"tags\":[\"sugar\"]},\"S20\":{\"for\":\"baking powder\",\"use\":\"baking soda + cream of tartar\",\"ratio\":\"1 tsp = 1/4 tsp baking soda + 1/2 tsp cream of tartar\",\"context\":\"baking\",\"tags\":[]},\"S21\":{\"for\":\"baking soda\",\"use\":\"baking powder (triple)\",\"ratio\":\"1 tsp baking soda = 3 tsp baking powder\",\"context\":\"baking\",\"tags\":[]},\"S1\":{\"for\":\"buttermilk\",\"use\":\"milk + lemon juice\",\"ratio\":\"1 cup = 1 cup milk + 1 Tbsp lemon juice\",\"context\":\"baking\",\"tags\":[\"dairy\"]},\"S2\":{\"for\":\"buttermilk\",\"use\":\"milk + vinegar\",\"ratio\":\"1 cup = 1 cup milk + 1 Tbsp white vinegar\",\"context\":\"baking\",\"tags\":[\"dairy\"]},\"S3\":{\"for\":\"buttermilk\",\"use\":\"plain yogurt (thinned)\",\"ratio\":\"1 cup = 3/4 cup yogurt + 1/4 cup milk\",\"context\":\"any\",\"tags\":[\"dairy\"]},\"S23\":{\"for\":\"eggs\",\"use\":\"flax egg\",\"ratio\":\"1 egg = 1 Tbsp ground flax + 3 Tbsp water\",\"context\":\"baking\",\"tags\":[]},\"S24\":{\"for\":\"eggs\",\"use\":\"applesauce\",\"ratio\":\"1 egg = 1/4 cup unsweetened applesauce\",\"context\":\"baking\",\"tags\":[]},\"S14\":{\"for\":\"butter\",\"use\":\"oil\",\"ratio\":\"1 cup butter = 3/4 cup oil\",\"context\":\"baking\",\"tags\":[]},\"S15\":{\"for\":\"butter\",\"use\":\"coconut oil\",\"ratio\":\"1:1\",\"context\":\"baking\",\"tags\":[]},\"S27\":{\"for\":\"vanilla\",\"use\":\"vanilla bean paste\",\"ratio\":\"1:1\",\"context\":\"baking\",\"tags\":[]}}}", "need": "We are out of buttermilk and eggs"}
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="recipe-scaler:adapt:$(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: avoid, missing, swaps
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: recipe-scaler:adapt:$(shasum -a 256 input.json | cut -c1-16):a1" --data @input.json