← Email Preference Center Generator
Your token

Email Preference Center Generator API

Reading your lines, checking the setup, and writing the preference page, the unsubscribe page, the rules and the plan all run free in the browser and need no API. The API is for the one metered step: send the page's topics by id, its frequencies and pause choices, the current line above each unsubscribe step, and a description of your emails, and get back, as JSON, a heading and intro, plain topic names and one-line descriptions, a save button, the unsubscribe-step lines, and notes on topics that overlap. The model only rewords; the page keeps every topic, frequency and pause, and refuses wording that adds a fact, a frequency or a promise you did not write.

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

taskWhat it doesReply
copyWrites an email preference center's wording: heading, intro, topic names and descriptions, save button and the line above each unsubscribe step. It never adds, removes, merges or reorders topics, frequencies or pauses.One JSON object

Input fields

All values are strings. task and center are required.

FieldMeaning
task"copy"
aboutEmpty, or your description of your emails: who gets them and what each kind contains. The page sends at most 900 characters; a longer description is cut in the middle, keeping the start and the end, with a marker.
centerJSON text: {name, heading, intro, save, topics, frequencies, pause_days, lines}, where topics is a list of {id, label, desc} in order (ids like t2, at most 12), frequencies a list of labels most often first, pause_days a list of numbers, and lines an object with the steps the page has: fewer, topics, pause, leave.
center_noteEmpty, or a sentence saying how much of the description was cut.

The reply

job.output.output is text holding one JSON object (sometimes inside a ```json fence) with six keys: heading, intro, save (strings), topics (one {id, label, desc} per topic in input order), overlaps (a list of {ids, why}, often empty; advice only) and lines (one string per step sent). Before using it, check that every id is one you sent and that no new wording adds a number, name, frequency or promise your text lacks; the page does this and lists what it refused. If the balance ran low, truncated is true and the object may stop early; the page keeps every entry that arrived whole.

Worked example

Input (input.json), the vague shop list sample on the page (4 topics):

{
  "task": "copy",
  "about": "Kettle & Fern sells loose-leaf tea and teaware online. Updates are new teas when they arrive. News is the story behind each tea estate we buy from. Offers are our two seasonal sales. Other is order and delivery tips. We send whenever there is something new.",
  "center": "{\"name\":\"Kettle & Fern\",\"heading\":\"Email preferences for Kettle & Fern\",\"intro\":\"Choose which emails you get and how often. You can unsubscribe from everything below.\",\"save\":\"Save my choices\",\"topics\":[{\"id\":\"t1\",\"label\":\"Updates\",\"desc\":\"\"},{\"id\":\"t2\",\"label\":\"News\",\"desc\":\"\"},{\"id\":\"t3\",\"label\":\"Offers\",\"desc\":\"\"},{\"id\":\"t4\",\"label\":\"Other\",\"desc\":\"\"}],\"frequencies\":[\"whenever we send\"],\"pause_days\":[],\"lines\":{\"topics\":\"Only want some of them? Keep the topics you like.\",\"leave\":\"Or stop every email from Kettle & Fern with one click.\"}}",
  "center_note": ""
}

Reply:

{
  "heading": "Kettle & Fern emails",
  "intro": "Choose which emails you get and how often. You can unsubscribe from everything on this page.",
  "save": "Save my choices",
  "topics": [
    {"id": "t1", "label": "New tea arrivals", "desc": "New teas, sent when they arrive"},
    {"id": "t2", "label": "Tea estate stories", "desc": "The story behind each tea estate we buy from"},
    {"id": "t3", "label": "Seasonal sales", "desc": "Our two seasonal sales"},
    {"id": "t4", "label": "Order and delivery tips", "desc": "Tips for your orders and deliveries"}
  ],
  "overlaps": [],
  "lines": {
    "topics": "Only want some of them? Keep the topics you like.",
    "leave": "Or unsubscribe to stop every email from Kettle & Fern."
  }
}

On the page, "Updates", "News", "Offers" and "Other" become "New tea arrivals", "Tea estate stories", "Seasonal sales" and "Order and delivery tips", each from the description, and the check drops three of its warnings. The single frequency and the missing pause stay flagged: only your own lines can add those.

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://email-preference-center.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":"email-preference-center"}' | 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": "copy", "about": "", "center": "{...}", "center_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="email-preference-center:copy:$(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: heading, intro, save, topics, overlaps, lines
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: email-preference-center:copy:$(shasum -a 256 input.json | cut -c1-16):a1" --data @input.json