← Ad Budget Planner
API
Tokens

Run Ad Budget Planner from your own code

The one metered task, review, is available over HTTP. It takes a monthly ad budget plan the page has already computed - every row's channel, platform, role (Proven, Test or Brand), budget, cost per click, conversion rate, value per conversion and the clicks, conversions, cost per conversion, revenue and ROAS worked out from them, plus the totals and the page's own checks - and returns a verdict, a suggested budget for every row with a one-line reason, and what the numbers show, what is worth testing and what data is MISSING.

The division of labour first: the browser does all the arithmetic - the computed columns, the totals, blended and non-brand ROAS, break-even ROAS from a gross margin, and the checks for the 70/30 test split, 20% budget steps, 50-conversion learning and missing inputs - and writes the CSV, the copy for Sheets and the Markdown. That part is free and never calls the API. Only the review is metered: model alias llm-default, billed per run at the model's price plus a 10% markup. The page sends at most 40 rows a run, then checks every suggestion against the grid before it shows anything - see How the page checks the reply.

Base URL and the response shape

Every endpoint lives under https://api.skillsafe.ai/v1/app-api, and every response has one shape:

{ "ok": true,  "data":  { ... } }
{ "ok": false, "error": { "code": "...", "message": "..." } }

The token is minted for this app (the guest call takes {"slug":"ad-budget-planner"}), so no slug header is needed afterwards. Send it as Authorization: Bearer …. The run body is the input object, sent bare.

StatusCodeMeaning
400validation_errorThe body is not a JSON object, or a required key (task, plan) is missing.
401unauthorizedNo token, or a stale one. Mint a guest token or sign in again.
402insufficient_creditsThe balance is under min_credits. Price with /estimate first.
403forbiddenA guest token tried to run: the review is metered and needs a personal sign-in.
404not_foundUnknown job id.
429rate_limitedBack off and retry.
5xxserver_errorTransient. Retry with the same Idempotency-Key so a retry never double-bills.

The task field and the input

There is one task. Always send it.

FieldTypeRequiredWhat it holds
taskstringyesAlways "review".
planstringyesThe plan as a JSON-encoded string (the input schema takes scalars only) - see below.
notestringnoUp to 600 characters: what you sell, the goal, a total you must not pass.

Inside plan

currency (ISO code), period ("month"), target_cpa, gross_margin_pct and break_even_roas (numbers or null), then rows, totals and checks. Each row: id, channel, platform, role, budget, cpc, conversion_rate_pct, value_per_conversion, cpm, last_month_budget, the computed clicks, conversions, cpa, revenue, roas, share_pct, and missing - the inputs not typed ("cost per click", "conversion rate", "value per conversion"). totals carries budget, clicks, conversions, cpa, revenue, roas, non_brand_roas, non_brand_cpa and test_share_pct; checks is a list of the page's own findings as sentences. Rows without a budget are not sent.

The reply

output.output on the finished job is a string holding one JSON object:

{
  "verdict": "Ready to launch" | "Adjust first" | "Missing data",
  "summary": "2-3 sentences",
  "rows": [ { "id": "...", "action": "Keep" | "Raise" | "Lower" | "Cut" | "Test", "budget": 1200, "reason": "one sentence" } ],
  "facts": ["..."], "hypotheses": ["..."], "missing": ["... MISSING ..."]
}

One rows entry per plan row, same order, same ids. budget is a plain number in the plan's currency. The model is told never to invent a cost per click, a conversion rate or an average, to keep the total unless the note asks otherwise, and to stay within 20% of last month's budget per step.

How the page checks the reply

Worked example - a B2B software plan

idChannelRoleBudgetCost per conversion
saas1Search - high intentProven4000271.43
saas2Search - brandBrand80012.22
saas3IT directors, 200-1000 staffProven6000916.67
saas4Retargeting - case studyTest1200218.18
saas5Search - competitor termsTest1000240

Request body (input.json):

{"task": "review", "plan": "{\"currency\":\"USD\",\"period\":\"month\",\"target_cpa\":350,\"gross_margin_pct\":80,\"break_even_roas\":1.25,\"rows\":[{\"id\":\"saas1\",\"channel\":\"Search - high intent\",\"platform\":\"Google Search\",\"role\":\"Proven\",\"budget\":4000,\"cpc\":9.5,\"conversion_rate_pct\":3.5,\"value_per_conversion\":900,\"cpm\":null,\"last_month_budget\":null,\"clicks\":421.05,\"conversions\":14.74,\"cpa\":271.43,\"revenue\":13263.16,\"roas\":3.32,\"share_pct\":30.77,\"missing\":[]},{\"id\":\"saas2\",\"channel\":\"Search - brand\",\"platform\":\"Google Search\",\"role\":\"Brand\",\"budget\":800,\"cpc\":2.2,\"conversion_rate_pct\":18,\"value_per_conversion\":900,\"cpm\":null,\"last_month_budget\":null,\"clicks\":363.64,\"conversions\":65.45,\"cpa\":12.22,\"revenue\":58909.09,\"roas\":73.64,\"share_pct\":6.15,\"missing\":[]},{\"id\":\"saas3\",\"channel\":\"IT directors, 200-1000 staff\",\"platform\":\"LinkedIn\",\"role\":\"Proven\",\"budget\":6000,\"cpc\":11,\"conversion_rate_pct\":1.2,\"value_per_conversion\":900,\"cpm\":null,\"last_month_budget\":null,\"clicks\":545.45,\"conversions\":6.55,\"cpa\":916.67,\"revenue\":5890.91,\"roas\":0.98,\"share_pct\":46.15,\"missing\":[]},{\"id\":\"saas4\",\"channel\":\"Retargeting - case study\",\"platform\":\"Meta\",\"role\":\"Test\",\"budget\":1200,\"cpc\":2.4,\"conversion_rate_pct\":1.1,\"value_per_conversion\":900,\"cpm\":null,\"last_month_budget\":null,\"clicks\":500,\"conversions\":5.5,\"cpa\":218.18,\"revenue\":4950,\"roas\":4.13,\"share_pct\":9.23,\"missing\":[]},{\"id\":\"saas5\",\"channel\":\"Search - competitor terms\",\"platform\":\"Microsoft Ads\",\"role\":\"Test\",\"budget\":1000,\"cpc\":6,\"conversion_rate_pct\":2.5,\"value_per_conversion\":900,\"cpm\":null,\"last_month_budget\":null,\"clicks\":166.67,\"conversions\":4.17,\"cpa\":240,\"revenue\":3750,\"roas\":3.75,\"share_pct\":7.69,\"missing\":[]}],\"totals\":{\"budget\":13000,\"clicks\":1996.81,\"conversions\":96.4,\"cpa\":134.85,\"revenue\":86763.16,\"roas\":6.67,\"non_brand_roas\":2.28,\"non_brand_cpa\":394.2,\"test_share_pct\":16.92},\"checks\":[\"Under 50 conversions a month. Search - high intent (15), IT directors, 200-1000 staff (6.5), Retargeting - case study (5.5) and 1 more. Automated bidding needs about 50 conversions to learn - start these on manual bids or cost caps.\",\"Above your target cost per conversion. IT directors, 200-1000 staff ($917) against $350. Blended: $135.\",\"Below break-even ROAS 1.25. At 80% gross margin, IT directors, 200-1000 staff (0.98) loses money on the first purchase. Fine only if repeat purchases pay it back - check your payback period.\",\"Brand lifts the blended number. Blended ROAS 6.67 includes brand search; without it ROAS is 2.28 and cost per conversion $394. Brand mostly harvests demand you already have - set targets on the non-brand number.\"]}", "note": "Goal is demo requests for our IT asset management software; sales closes about 1 in 4 demos."}

A reply (output.output, pretty-printed):

{
  "verdict": "Adjust first",
  "summary": "The plan looks strong only because brand search lifts the blended numbers: without it ROAS is 2.28 and cost per conversion is $394, above your $350 target. The LinkedIn row takes 46.15% of the budget at ROAS 0.98, below the 1.25 break-even, while the non-brand search and test rows are under target. I suggest moving budget from LinkedIn to the cheaper non-brand rows in steps of about 20%, keeping the total at 13000.",
  "rows": [
    {
      "id": "saas1",
      "action": "Raise",
      "budget": 4800,
      "reason": "Cost per conversion of $271.43 is under the $350 target and ROAS is 3.32, so it can take a 20% step up."
    },
    {
      "id": "saas2",
      "action": "Keep",
      "budget": 800,
      "reason": "Brand search mostly harvests existing demand, so its $12.22 cost per conversion is not a win and I would not scale it."
    },
    {
      "id": "saas3",
      "action": "Lower",
      "budget": 4760,
      "reason": "Cost per conversion of $916.67 is far above the $350 target and ROAS of 0.98 is below the 1.25 break-even, though repeat purchases could change that."
    },
    {
      "id": "saas4",
      "action": "Raise",
      "budget": 1440,
      "reason": "ROAS of 4.13 and cost per conversion of $218.18 look good, but at 5.5 conversions the sample is small, so raise only 20% as a test."
    },
    {
      "id": "saas5",
      "action": "Raise",
      "budget": 1200,
      "reason": "ROAS of 3.75 and cost per conversion of $240 are under target, but with 4.17 conversions this is still a test and gets a 20% step."
    }
  ],
  "facts": [
    "Blended ROAS is 6.67, but non-brand ROAS is 2.28 and non-brand cost per conversion is $394.20 against a $350 target.",
    "IT directors, 200-1000 staff on LinkedIn has a budget of 6000 (46.15% share), cost per conversion of $916.67 and ROAS 0.98 against a break-even of 1.25.",
    "Search - high intent, Retargeting - case study and Search - competitor terms have cost per conversion of $271.43, $218.18 and $240, all under the $350 target.",
    "Test rows are 16.92% of the budget, below the usual 30%, and every row converts fewer than 50 times a month except brand search at 65.45."
  ],
  "hypotheses": [
    "LinkedIn may still pay back if IT directors buy again or expand later; check the payback period before cutting it further.",
    "The Meta retargeting and Microsoft competitor rows may look good only because their conversion counts are 5.5 and 4.17; hold them for 3-5 days after each raise and check whether cost per conversion holds.",
    "Because sales closes about 1 in 4 demos, a cost per demo near $350 may be acceptable, but check this against what a closed customer is worth versus the $900 per conversion entered."
  ],
  "missing": [
    "Last month's budget is MISSING for every row, so no month-over-month trend or 20% cap check is possible.",
    "The payback period or repeat purchase value for the LinkedIn audience is MISSING."
  ]
}

Step 1 — a tiny client helper

One function that sends JSON and unwraps the response. Paste a personal token from /tokens.html, or leave it empty and mint a guest token in step 2.

BASE="https://api.skillsafe.ai/v1/app-api"
TOKEN="YOUR_TOKEN"   # from https://ad-budget-planner.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 a personal token: sign in on /tokens.html and copy it from there.

# 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":"ad-budget-planner"}' | jq -r '.data.token')

Step 3 — GET /me

Who the token is (subject_type: user or guest) and the credit balance.

api GET /me | jq '.data | {subject_type, credits}'

Step 4 — POST /estimate

Free. The body is the run input itself, the bare object (never wrapped in {"input": ...}). hold_credits is a reservation, not the price; min_credits is what the balance must cover; model_alias reads llm-default and markup_bps reads 1000 (10%). Save the worked example's request body as input.json.

# input.json: the run input object - {"task": "review", "plan": "<JSON string>", "note": "..."} - see the worked example
api POST /estimate "$(cat input.json)" | jq '.data | {hold_credits, min_credits, model, model_alias, markup_bps, warnings}'

Step 5 — POST /run, then poll the job

Send an Idempotency-Key built from the lane and the input: a retry with the same key never bills twice. The page uses ad-budget-planner:<task>:<inputHash>:a<attempt> (the one task is review). The job's output.output is the reply text - one JSON object; truncated: true means the balance cut it short, and the complete entries that did arrive are still usable.

KEY="ad-budget-planner:review:$(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, the reply contract
echo "$J" | jq '.data | {charged_credits, truncated}'
jq -r '"\(.verdict): \(.summary)"' reply.json
jq -r '.rows[]? | "\(.id) \(.action) \(.budget) - \(.reason)"' reply.json   # one per plan row
jq -r '.missing[]? | "MISSING: \(.)"' reply.json
jq -r '.facts[]? | "- \(.)"' reply.json

Step 6 — POST /run-stream

The same run as Server-Sent Events, with the same input.json. Browsers receive progress ticks rather than text deltas; the final done event carries the job, whose output.output is the reply.

# 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: ad-budget-planner:review:$(shasum -a 256 input.json | cut -c1-16):a1" --data @input.json