Sales Territory Planner API
Reading the account list, the territory split, the fair-share check, the coverage tiers and the downloads all run free in the browser and are not part of this API. The API runs the one metered step: writing the territory plan (names, focus, first accounts, rules of engagement and handoff notes) for a split you already have.
Base URL: https://api.skillsafe.ai/v1/app-api. Every response is an envelope {"data": ..., "error": null} or {"data": null, "error": {"code", "message"}}.
The task field
This app has one task. Always send "task": "plan".
| task | What it does | Reply |
|---|---|---|
plan | Reads each rep's territory and every account's new owner against a description of the team, and writes a summary, a name, a focus and 1 to 3 first accounts for every territory, 3 to 6 rules of engagement, up to 5 handoff notes for accounts that change owner and up to 3 questions. | One JSON object |
The input
All values are strings. task, context, reps, accounts and figures are required; send "" for anything else you do not have.
| Field | What to send |
|---|---|
task | "plan" |
context | The sales team and what it sells, in your own words (at most 1,200 characters). The only source of facts beyond the lists. |
reps | One line per rep: id | name | home: ... | share N% | N accounts | potential $X | N% of a fair share | regions: ... | kept N, gained N, lost N | tiers A N, B N, C N. Ids are r1, r2... |
accounts | One line per account: id | name | region (group) | $X | tier A/B/C | stays with X, moves from X to Y, or new to Y | why. Ids are a1, a2... At most 120 lines. |
figures | Totals, one per line: counts, how it was split, each rep's fair share, the verdict, accounts changing owner, tier sizes. |
checks | The checks, one per line: fix | ..., watch | ... or note | .... |
clip_note | Empty, or a sentence saying which accounts were left out of the list. |
The reply
job.output.output is text holding one JSON object: summary, territories ({rep, name, focus, first_accounts}, one per rep), rules ({rule, why}), handoffs ({account, note}) and questions. Before using it, check that every rep is an id you sent, that every first account belongs to that rep, that every handoff is for an account that changes owner, and that no sentence has a number, name or claim your input does not have. The page does exactly that, and shows what it refused.
Worked examples
The three examples on the page, each with the exact input the page sends and a model reply.
US software, 5 reps
Input:
{
"task": "plan",
"context": "We sell HR and payroll software to mid-market companies across the US. Five account executives; Elena Ruiz joined last month and is ramping, so she gets half a territory. Dana Wells left the team, so her accounts need new owners.",
"reps": "r1 | Ana Lopez | home: West | share 100% | 7 accounts | potential $1,202,000 | 103% of a fair share | regions: West 7 | kept 2, gained 1, lost 0 | tiers A 2, B 1, C 4\nr2 | Ben Okafor | home: South | share 100% | 7 accounts | potential $1,164,000 | 100% of a fair share | regions: South 6, West 1 | kept 3, gained 0, lost 0 | tiers A 2, B 1, C 4\nr3 | Chloe Park | home: Northeast | share 100% | 4 accounts | potential $1,112,000 | 95% of a fair share | regions: Northeast 2, Midwest 1, South 1 | kept 3, gained 0, lost 0 | tiers A 2, B 1, C 1\nr4 | Dev Shah | home: Midwest | share 100% | 7 accounts | potential $1,177,000 | 101% of a fair share | regions: Midwest 4, Northeast 3 | kept 3, gained 0, lost 0 | tiers A 2, B 2, C 3\nr5 | Elena Ruiz | home: West | share 50% | 3 accounts | potential $605,000 | 104% of a fair share | regions: Northeast 2, West 1 | kept 0, gained 1, lost 0 | tiers A 0, B 3, C 0",
"accounts": "a1 | Northwind Logistics | CA (West) | $420,000 | tier A | stays with Ana Lopez | kept with current owner\na2 | Bayview Health | CA (West) | $310,000 | tier A | stays with Ana Lopez | kept with current owner\na3 | Cascade Outfitters | WA (West) | $185,000 | tier B | moves from Dana Wells to Ana Lopez | rep's home region\na4 | Pinecrest Foods | OR (West) | $96,000 | tier C | new to Ana Lopez | rep's home region\na5 | Redrock Mining | AZ (West) | $240,000 | tier B | moves from Dana Wells to Elena Ruiz | rep's home region\na6 | Summit Credit Union | CO (West) | $130,000 | tier C | stays with Ben Okafor | kept with current owner\na7 | Lone Star Freight | TX (South) | $365,000 | tier A | stays with Ben Okafor | kept with current owner\na8 | Gulfline Energy | TX (South) | $290,000 | tier A | stays with Ben Okafor | kept with current owner\na9 | Magnolia Insurance | GA (South) | $175,000 | tier B | new to Ben Okafor | rep's home region\na10 | Sunbelt Clinics | FL (South) | $210,000 | tier B | stays with Chloe Park | kept with current owner\na11 | Palmetto Bank | SC (South) | $88,000 | tier C | new to Ben Okafor | rep's home region\na12 | Bluegrass Distillers | KY (South) | $64,000 | tier C | new to Ben Okafor | rep's home region\na13 | Lakeshore Retail | IL (Midwest) | $260,000 | tier A | stays with Dev Shah | kept with current owner\na14 | Prairie Mutual | IA (Midwest) | $72,000 | tier C | new to Chloe Park | balances the load\na15 | Great Lakes Steel | OH (Midwest) | $330,000 | tier A | stays with Dev Shah | kept with current owner\na16 | Motor City Parts | MI (Midwest) | $145,000 | tier B | new to Dev Shah | rep's home region\na17 | Twin Cities Media | MN (Midwest) | $118,000 | tier C | stays with Dev Shah | kept with current owner\na18 | Harbor Point Capital | NY (Northeast) | $480,000 | tier A | stays with Chloe Park | kept with current owner\na19 | Empire Analytics | NY (Northeast) | $205,000 | tier B | new to Elena Ruiz | balances the load\na20 | Liberty Pharma | NJ (Northeast) | $350,000 | tier A | stays with Chloe Park | kept with current owner\na21 | Keystone Manufacturing | PA (Northeast) | $160,000 | tier B | new to Elena Ruiz | same region as the rep's other accounts\na22 | Beacon Hill Partners | MA (Northeast) | $225,000 | tier B | new to Dev Shah | balances the load\na23 | Granite State Software | NH (Northeast) | $58,000 | tier C | new to Dev Shah | balances the load\na24 | Ocean State Marine | RI (Northeast) | $41,000 | tier C | new to Dev Shah | same region as the rep's other accounts\na25 | Desert Sun Resorts | NV (West) | $112,000 | tier C | new to Ana Lopez | rep's home region\na26 | Wasatch Outdoor | UT (West) | $79,000 | tier C | new to Ana Lopez | rep's home region\na27 | Ozark Farms | AR (South) | $52,000 | tier C | new to Ben Okafor | rep's home region\na28 | Big Sky Ranch Supply | MT (West) | no potential given | tier C | new to Ana Lopez | rep's home region",
"figures": "Accounts: 28; reps: 5; split by potential; allowed spread 10%; current owners kept\nTotal potential: $5,260,000\nFair share for Ana Lopez: $1,168,889\nFair share for Ben Okafor: $1,168,889\nFair share for Chloe Park: $1,168,889\nFair share for Dev Shah: $1,168,889\nFair share for Elena Ruiz: $584,444\nVerdict: Balanced: every rep within 10% of a fair share\nAccounts changing owner: 2\nTier A: 8 accounts, $2,805,000\nTier B: 8 accounts, $1,545,000\nTier C: 12 accounts, $910,000",
"checks": "watch | 1 account has no potential, so counted as $0: Big Sky Ranch Supply.\nnote | 2 accounts are owned by someone not in your rep list (Dana Wells); they were reassigned.\nnote | 2 accounts change owner. Each needs a handoff from the old owner.",
"clip_note": ""
}
Reply:
{
"summary": "The 28 accounts were split by potential across five reps, and every rep is within 10% of a fair share. Two accounts change owner, both from Dana Wells, who has left the team. The first thing to look at is Big Sky Ranch Supply, which has no potential given and was counted as $0.",
"territories": [
{
"rep": "r1",
"name": "West",
"focus": "Ana Lopez should grow the tier A accounts Northwind Logistics and Bayview Health and win over Cascade Outfitters, which comes over from Dana Wells.",
"first_accounts": [
"a1",
"a2",
"a3"
]
},
{
"rep": "r2",
"name": "South",
"focus": "Ben Okafor should protect the tier A accounts Lone Star Freight and Gulfline Energy and build relationships with the new South accounts such as Magnolia Insurance.",
"first_accounts": [
"a7",
"a8"
]
},
{
"rep": "r3",
"name": "Northeast and Midwest",
"focus": "Chloe Park holds the largest tier A accounts in the Northeast, Harbor Point Capital and Liberty Pharma, and can spend most of their time deepening them.",
"first_accounts": [
"a18",
"a20"
]
},
{
"rep": "r4",
"name": "Midwest and Northeast",
"focus": "Dev Shah should grow the tier A accounts Lakeshore Retail and Great Lakes Steel while getting to know the new Northeast accounts such as Beacon Hill Partners.",
"first_accounts": [
"a13",
"a15"
]
},
{
"rep": "r5",
"name": "Northeast and West",
"focus": "Elena Ruiz is still ramping, so their time is best spent on the tier B accounts Redrock Mining, Empire Analytics and Keystone Manufacturing.",
"first_accounts": [
"a5",
"a19",
"a21"
]
}
],
"rules": [
{
"rule": "An account belongs to the rep who holds it on this list, wherever its offices are.",
"why": "Several reps cover accounts outside their home region, so one named owner stops two reps calling the same mid-market company."
},
{
"rule": "A new account that is not on the list goes to the rep who holds that region, and Elena Ruiz only takes one after the other reps have been considered.",
"why": "Elena Ruiz is ramping on half a territory, so new leads should not crowd their first months."
},
{
"rule": "A moved account is handed over by someone on the team who knows its history, and the new owner gathers its open deals and contacts before the first call.",
"why": "Dana Wells has left, so the usual introduction from the old owner is not possible for the two accounts that moved."
},
{
"rule": "Give Big Sky Ranch Supply a potential figure as soon as one is known and then recheck the split.",
"why": "It was counted as $0, so the current balance may shift once a real number is entered."
},
{
"rule": "Review the split each quarter and whenever a new rep joins or Elena Ruiz moves to a full territory.",
"why": "Ramp-up changes how much a fair share means for Elena Ruiz, and a team of five reps drifts quickly."
}
],
"handoffs": [
{
"account": "a5",
"note": "Elena Ruiz should gather the account history for Redrock Mining from the team, including open opportunities and contacts, before the first call, since Dana Wells has left."
},
{
"account": "a3",
"note": "Ana Lopez should collect what the team knows about Cascade Outfitters, such as open quotes and key contacts, before reaching out, since Dana Wells has left."
}
],
"questions": [
"What potential should Big Sky Ranch Supply carry instead of $0?",
"Which open opportunities did Dana Wells leave on Redrock Mining and Cascade Outfitters?",
"Does Elena Ruiz have a point at which they move from half a territory to a full one?"
]
}
On the page, every rep id is matched against the reps sent, every first account against that rep's accounts, every handoff against the accounts that move, and every sentence for numbers and names the input does not have.
UK medical devices
Input:
{
"task": "plan",
"context": "We sell surgical stapling devices to NHS hospitals and private clinics. Four field reps who visit theatres in person, so travel time matters. Isla Grant is a new hire starting in the north at half a quota.",
"reps": "r1 | Priya Nair | home: South West, Midlands, Wales | share 100% | 5 accounts | potential £730,000 | 99% of a fair share | regions: Midlands 2, South West 2, Wales 1 | kept 3, gained 0, lost 0 | tiers A 2, B 2, C 1\nr2 | Tom Becker | home: London | share 100% | 4 accounts | potential £755,000 | 102% of a fair share | regions: London 4 | kept 3, gained 0, lost 0 | tiers A 2, B 1, C 1\nr3 | Sam Howell | home: North West, Scotland | share 100% | 8 accounts | potential £715,000 | 97% of a fair share | regions: North West 3, Scotland 2, Midlands 1, South West 1, Wales 1 | kept 2, gained 0, lost 0 | tiers A 1, B 2, C 5\nr4 | Isla Grant | home: North East, Scotland | share 50% | 3 accounts | potential £390,000 | 105% of a fair share | regions: North East 2, Scotland 1 | kept 0, gained 0, lost 0 | tiers A 1, B 1, C 1",
"accounts": "a1 | St Aldhelm's Hospital | South West | £180,000 | tier A | stays with Priya Nair | kept with current owner\na2 | Severn Valley Trust | South West | £95,000 | tier B | stays with Priya Nair | kept with current owner\na3 | Kingsbridge Clinic | South West | £40,000 | tier C | new to Sam Howell | balances the load\na4 | Thameside General | London | £320,000 | tier A | stays with Tom Becker | kept with current owner\na5 | Royal Docklands Hospital | London | £260,000 | tier A | stays with Tom Becker | kept with current owner\na6 | Camden Day Surgery | London | £55,000 | tier C | new to Tom Becker | rep's home region\na7 | Hampstead Heart Centre | London | £120,000 | tier B | stays with Tom Becker | kept with current owner\na8 | Mercia University Hospitals | Midlands | £240,000 | tier A | stays with Priya Nair | kept with current owner\na9 | Trent Orthopaedic | Midlands | £85,000 | tier C | new to Priya Nair | rep's home region\na10 | Black Country Health | Midlands | £110,000 | tier B | new to Sam Howell | balances the load\na11 | Pennine Acute Trust | North West | £210,000 | tier A | stays with Sam Howell | kept with current owner\na12 | Mersey Children's Hospital | North West | £150,000 | tier B | stays with Sam Howell | kept with current owner\na13 | Lakeland Community Hospital | North West | £35,000 | tier C | new to Sam Howell | rep's home region\na14 | Tyne Valley Infirmary | North East | £140,000 | tier B | new to Isla Grant | rep's home region\na15 | Wearside Medical | North East | £60,000 | tier C | new to Isla Grant | rep's home region\na16 | Forth Royal Infirmary | Scotland | £190,000 | tier A | new to Isla Grant | rep's home region\na17 | Clyde Surgical Centre | Scotland | £75,000 | tier C | new to Sam Howell | rep's home region\na18 | Highland Health Board | Scotland | £45,000 | tier C | new to Sam Howell | rep's home region\na19 | Cardiff Bay Hospital | Wales | £130,000 | tier B | new to Priya Nair | rep's home region\na20 | Swansea Valley Clinic | Wales | £50,000 | tier C | new to Sam Howell | balances the load",
"figures": "Accounts: 20; reps: 4; split by potential; allowed spread 15%; current owners kept\nTotal potential: £2,590,000\nFair share for Priya Nair: £740,000\nFair share for Tom Becker: £740,000\nFair share for Sam Howell: £740,000\nFair share for Isla Grant: £370,000\nVerdict: Balanced: every rep within 15% of a fair share\nAccounts changing owner: 0\nTier A: 6 accounts, £1,400,000\nTier B: 6 accounts, £745,000\nTier C: 8 accounts, £445,000",
"checks": "watch | Forth Royal Infirmary alone is 51% of Isla Grant's fair share. An account that size is hard to balance around; consider a named-account owner for it.",
"clip_note": ""
}
Reply:
{
"summary": "The 20 accounts were split by potential across four reps, and every rep is within 15% of a fair share. No account changes owner, so there are no handoffs to plan. The first thing to look at is Forth Royal Infirmary, which alone is 51% of Isla Grant's fair share and is hard to balance around.",
"territories": [
{
"rep": "r1",
"name": "Midlands, South West and Wales",
"focus": "Priya Nair should grow the tier A accounts St Aldhelm's Hospital and Mercia University Hospitals and use the new Cardiff Bay Hospital to build a presence in Wales.",
"first_accounts": [
"a1",
"a8",
"a19"
]
},
{
"rep": "r2",
"name": "London",
"focus": "Tom Becker covers four London accounts, so theatre visits stay short on travel and the time can go into the two large tier A hospitals, Thameside General and Royal Docklands Hospital.",
"first_accounts": [
"a4",
"a5"
]
},
{
"rep": "r3",
"name": "North West and Scotland",
"focus": "Sam Howell holds one tier A account, Pennine Acute Trust, and several small tier C accounts across five regions, so visits should be grouped by region to limit travel.",
"first_accounts": [
"a11",
"a10"
]
},
{
"rep": "r4",
"name": "North East and Scotland",
"focus": "Isla Grant is new and starts at half a quota, so the early effort may go to Forth Royal Infirmary in tier A and then Tyne Valley Infirmary.",
"first_accounts": [
"a16",
"a14"
]
}
],
"rules": [
{
"rule": "An account belongs to the rep who holds it on this list, even when a hospital in one region buys through another.",
"why": "Reps visit theatres in person, so one owner per account avoids two people travelling to the same site."
},
{
"rule": "A new account that is not on the list goes to the rep whose home region it sits in.",
"why": "Home regions keep travel time down for a four-person field team."
},
{
"rule": "Isla Grant works the northern accounts with the other reps' help on Scotland until the first visits are done.",
"why": "Isla Grant is a new hire at half a quota, and Forth Royal Infirmary is a large share of that territory."
},
{
"rule": "Review the split when a new rep joins or after each quarter.",
"why": "A new hire's quota and the large tier A accounts can shift the balance quickly in a small team."
}
],
"handoffs": [],
"questions": [
"Is a half quota realistic for Isla Grant given how large Forth Royal Infirmary is?",
"Does Sam Howell's spread across five regions fit the time available for in-person theatre visits?"
]
}
On the page, every rep id is matched against the reps sent, every first account against that rep's accounts, every handoff against the accounts that move, and every sentence for numbers and names the input does not have.
Rebalance 3 reps
Input:
{
"task": "plan",
"context": "A three-person inside sales team selling scheduling software to small businesses. Marcus has carried most of the pipeline for a year and is overloaded; we want a fairer split before the new quarter.",
"reps": "r1 | Marcus Lee | home: none given | share 100% | 4 accounts | potential $360,000 | 97% of a fair share | regions: Central 2, East 1, West 1 | kept 3, gained 1, lost 5 | tiers A 3, B 0, C 1\nr2 | Nina Patel | home: none given | share 100% | 6 accounts | potential $390,000 | 105% of a fair share | regions: Central 3, East 3 | kept 2, gained 3, lost 1 | tiers A 1, B 3, C 2\nr3 | Omar Haddad | home: none given | share 100% | 6 accounts | potential $365,000 | 98% of a fair share | regions: West 4, East 2 | kept 3, gained 2, lost 0 | tiers A 1, B 2, C 3",
"accounts": "a1 | Acme Robotics | East | $90,000 | tier A | moves from Marcus Lee to Nina Patel | balances the load\na2 | Brightline Studios | East | $45,000 | tier C | moves from Marcus Lee to Nina Patel | same region as the rep's other accounts\na3 | Corvid Security | East | $130,000 | tier A | stays with Marcus Lee | stays with current owner\na4 | Delta Kitchens | East | $30,000 | tier C | moves from Marcus Lee to Omar Haddad | balances the load\na5 | Evergreen Schools | East | $75,000 | tier B | moves from Marcus Lee to Nina Patel | same region as the rep's other accounts\na6 | Fieldstone Legal | East | $60,000 | tier B | moves from Marcus Lee to Omar Haddad | balances the load\na7 | Glacier Water | Central | $110,000 | tier A | stays with Marcus Lee | stays with current owner\na8 | Horizon Travel | Central | $40,000 | tier C | stays with Nina Patel | stays with current owner\na9 | Ironwood Builders | Central | $85,000 | tier B | stays with Nina Patel | stays with current owner\na10 | Juniper Dental | Central | $25,000 | tier C | moves from Nina Patel to Marcus Lee | balances the load\na11 | Kestrel Aviation | West | $150,000 | tier A | stays with Omar Haddad | stays with current owner\na12 | Lumen Labs | West | $35,000 | tier C | stays with Omar Haddad | stays with current owner\na13 | Meridian Hotels | West | $95,000 | tier A | stays with Marcus Lee | stays with current owner\na14 | Nimbus Cloud | West | $70,000 | tier B | stays with Omar Haddad | stays with current owner\na15 | Orchid Florists | West | $20,000 | tier C | new to Omar Haddad | same region as the rep's other accounts\na16 | Pioneer Seeds | Central | $55,000 | tier B | new to Nina Patel | same region as the rep's other accounts",
"figures": "Accounts: 16; reps: 3; split by potential; allowed spread 10%; current owners not locked\nTotal potential: $1,115,000\nFair share for Marcus Lee: $371,667\nFair share for Nina Patel: $371,667\nFair share for Omar Haddad: $371,667\nVerdict: Balanced: every rep within 10% of a fair share\nAccounts changing owner: 6\nTier A: 5 accounts, $575,000\nTier B: 5 accounts, $345,000\nTier C: 6 accounts, $195,000",
"checks": "note | 6 accounts change owner. Each needs a handoff from the old owner.\nnote | No reps were listed, so the 3 owners in your list were used.",
"clip_note": ""
}
Reply:
{
"summary": "The 16 accounts were split by potential across three reps, and every rep is within 10% of a fair share. Six accounts change owner, five of them from Marcus Lee, who was carrying the most pipeline, so the handoffs are the first thing to plan before the new quarter.",
"territories": [
{
"rep": "r1",
"name": "Central, East and West",
"focus": "Marcus Lee keeps three tier A accounts, Corvid Security, Glacier Water and Meridian Hotels, and can spend the time freed up growing them.",
"first_accounts": [
"a3",
"a7",
"a13"
]
},
{
"rep": "r2",
"name": "Central and East",
"focus": "Nina Patel gains three East accounts from Marcus Lee, including the tier A Acme Robotics, and should win over those contacts early while covering Central.",
"first_accounts": [
"a1",
"a5"
]
},
{
"rep": "r3",
"name": "West and East",
"focus": "Omar Haddad holds the largest West account, Kestrel Aviation, and also picks up two East accounts from Marcus Lee to bring into the routine.",
"first_accounts": [
"a11",
"a6"
]
}
],
"rules": [
{
"rule": "An account belongs to the rep who holds it on this list, even when it sits in one region and buys from another.",
"why": "With three reps on an inside team, one owner per small business avoids two people calling the same buyer."
},
{
"rule": "A new account that is not on the list goes to the rep who already covers its region.",
"why": "Marcus Lee, Nina Patel and Omar Haddad each cover Central, East or West accounts, so regions keep new leads predictable."
},
{
"rule": "A moved account stays with its old owner until the introduction call and the handover of open deals are done.",
"why": "Six accounts change owner and the old owner knows the contacts best."
},
{
"rule": "The split is reviewed each quarter and whenever a new rep joins.",
"why": "Marcus Lee was overloaded before this rebalance, so drift in workload should be caught early."
}
],
"handoffs": [
{
"account": "a1",
"note": "Marcus Lee should introduce Nina Patel to Acme Robotics and pass on any open opportunities and key contacts."
},
{
"account": "a5",
"note": "Marcus Lee should hand over the contacts and any open quotes at Evergreen Schools in an introduction call with Nina Patel."
},
{
"account": "a6",
"note": "Marcus Lee should brief Omar Haddad on Fieldstone Legal's history and any deals in progress."
},
{
"account": "a2",
"note": "Marcus Lee should share the main contact and recent conversations at Brightline Studios with Nina Patel."
},
{
"account": "a4",
"note": "Marcus Lee should pass the contact details and any open follow-ups at Delta Kitchens to Omar Haddad."
}
],
"questions": [
"Do any of the moving accounts have deals close to signing that would be disrupted by a change of owner?",
"Does a small business that works in one region but buys from another need its own ownership rule?"
]
}
On the page, every rep id is matched against the reps sent, every first account against that rep's accounts, every handoff against the accounts that move, and every sentence for numbers and names the input does not have.
Errors
| HTTP | What to do |
|---|---|
| 401 | The token is missing, expired or a guest token on a run. Get a personal token on the token page. |
| 402 | The balance is below what the run reserves. Top up at skillsafe.ai/account/billing. |
| 400 | The body is not a JSON object of the fields above, or a required field is missing. |
| 429 | Wait 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://sales-territory-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"}
}import json, urllib.request
BASE = "https://api.skillsafe.ai/v1/app-api"
TOKEN = "paste-your-token-here" # from https://sales-territory-planner.skillsafe.ai/tokens.html
def api(method, path, body=None, headers=None):
req = urllib.request.Request(BASE + path, method=method,
data=None if body is None else json.dumps(body).encode(),
headers={"Content-Type": "application/json", **({"Authorization": "Bearer " + TOKEN} if TOKEN else {}), **(headers or {})})
with urllib.request.urlopen(req) as r:
env = json.load(r)
if env.get("error"):
raise RuntimeError(env["error"])
return env["data"]// sales-territory-planner.mjs -- Node 18+ (global fetch)
const BASE = "https://api.skillsafe.ai/v1/app-api";
let TOKEN = "paste-your-token-here"; // from https://sales-territory-planner.skillsafe.ai/tokens.html
async function api(method, path, body, headers = {}) {
const r = await fetch(BASE + path, { method, headers: { "Content-Type": "application/json",
...(TOKEN ? { Authorization: "Bearer " + TOKEN } : {}), ...headers },
body: body === undefined ? undefined : JSON.stringify(body) });
const env = await r.json();
if (env.error) throw new Error(env.error.code + ": " + env.error.message);
return env.data;
}package main
import ("bytes"; "encoding/json"; "fmt"; "net/http")
const base = "https://api.skillsafe.ai/v1/app-api"
var token = "paste-your-token-here" // from https://sales-territory-planner.skillsafe.ai/tokens.html
func api(method, path string, body any, headers map[string]string) (map[string]any, error) {
var buf bytes.Buffer
if body != nil { json.NewEncoder(&buf).Encode(body) }
req, _ := http.NewRequest(method, base+path, &buf)
req.Header.Set("Content-Type", "application/json")
if token != "" { req.Header.Set("Authorization", "Bearer "+token) }
for k, v := range headers { req.Header.Set(k, v) }
res, err := http.DefaultClient.Do(req)
if err != nil { return nil, err }
defer res.Body.Close()
var env struct { Data map[string]any; Error map[string]any }
json.NewDecoder(res.Body).Decode(&env)
if env.Error != nil { return nil, fmt.Errorf("%v", env.Error) }
return env.Data, nil
}// SalesTerritoryPlanner.java -- Java 17+, with com.fasterxml.jackson.core:jackson-databind
import com.fasterxml.jackson.databind.*;
import java.net.URI; import java.net.http.*; import java.util.*;
public class SalesTerritoryPlanner {
static final String BASE = "https://api.skillsafe.ai/v1/app-api";
static String token = "paste-your-token-here"; // from https://sales-territory-planner.skillsafe.ai/tokens.html
static final ObjectMapper M = new ObjectMapper();
static final HttpClient C = HttpClient.newHttpClient();
static JsonNode api(String method, String path, Object body, Map<String, String> headers) throws Exception {
var b = HttpRequest.newBuilder(URI.create(BASE + path)).header("Content-Type", "application/json");
if (!token.isEmpty()) b.header("Authorization", "Bearer " + token);
if (headers != null) headers.forEach(b::header);
b.method(method, body == null ? HttpRequest.BodyPublishers.noBody() : HttpRequest.BodyPublishers.ofString(M.writeValueAsString(body)));
JsonNode env = M.readTree(C.send(b.build(), HttpResponse.BodyHandlers.ofString()).body());
if (env.hasNonNull("error")) throw new RuntimeException(env.get("error").toString());
return env.get("data");
}
}require "json"
require "net/http"
BASE = "https://api.skillsafe.ai/v1/app-api"
TOKEN = "paste-your-token-here" # from https://sales-territory-planner.skillsafe.ai/tokens.html
def api(method, path, body = nil, headers = {})
uri = URI(BASE + path)
req = Net::HTTPGenericRequest.new(method, !body.nil?, true, uri.request_uri,
{ "Content-Type" => "application/json" }.merge(TOKEN.empty? ? {} : { "Authorization" => "Bearer #{TOKEN}" }).merge(headers))
req.body = JSON.generate(body) unless body.nil?
env = JSON.parse(Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |h| h.request(req) }.body)
raise env["error"].to_s if env["error"]
env["data"]
end<?php
const BASE = "https://api.skillsafe.ai/v1/app-api";
$TOKEN = "paste-your-token-here"; // from https://sales-territory-planner.skillsafe.ai/tokens.html
function api(string $method, string $path, $body = null, array $headers = []) {
global $TOKEN;
$h = ["Content-Type: application/json"];
if ($TOKEN) $h[] = "Authorization: Bearer $TOKEN";
foreach ($headers as $k => $v) $h[] = "$k: $v";
$ch = curl_init(BASE . $path);
curl_setopt_array($ch, [CURLOPT_CUSTOMREQUEST => $method, CURLOPT_HTTPHEADER => $h, CURLOPT_RETURNTRANSFER => true]);
if ($body !== null) curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body));
$env = json_decode(curl_exec($ch), true);
if (!empty($env["error"])) throw new Exception(json_encode($env["error"]));
return $env["data"];
}// Program.cs -- .NET 6+ console app
using System.Net.Http.Json; using System.Text.Json; using System.Text.Json.Nodes;
static class Api {
public const string Base = "https://api.skillsafe.ai/v1/app-api";
public static string Token = "paste-your-token-here"; // from https://sales-territory-planner.skillsafe.ai/tokens.html
static readonly HttpClient C = new();
public static async Task<JsonNode?> Call(string method, string path, object? body = null, Dictionary<string, string>? headers = null) {
var req = new HttpRequestMessage(new HttpMethod(method), Base + path);
if (Token != "") req.Headers.Add("Authorization", "Bearer " + Token);
if (headers != null) foreach (var h in headers) req.Headers.Add(h.Key, h.Value);
if (body != null) req.Content = JsonContent.Create(body);
var env = JsonNode.Parse(await (await C.SendAsync(req)).Content.ReadAsStringAsync())!;
if (env["error"] is JsonNode e && e.GetValueKind() != JsonValueKind.Null) throw new Exception(e.ToJsonString());
return env["data"];
}
}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":"sales-territory-planner"}' | jq -r '.data.token')# a guest token (enough for /me and /estimate); a run needs your personal token from /tokens.html
TOKEN = ""
TOKEN = api("POST", "/guest", {"slug": "sales-territory-planner"})["token"]// a guest token (enough for /me and /estimate); a run needs your personal token from /tokens.html
TOKEN = "";
TOKEN = (await api("POST", "/guest", { slug: "sales-territory-planner" })).token;// inside main: a guest token (enough for /me and /estimate); a run needs your personal token
token = ""
g, err := api("POST", "/guest", map[string]string{"slug": "sales-territory-planner"}, nil)
if err != nil { panic(err) }
token = g["token"].(string)// inside main: a guest token (enough for /me and /estimate); a run needs your personal token
token = "";
token = api("POST", "/guest", Map.of("slug", "sales-territory-planner"), null).get("token").asText();# a guest token (enough for /me and /estimate); a run needs your personal token from /tokens.html
TOKEN.replace("")
TOKEN.replace(api("POST", "/guest", { slug: "sales-territory-planner" })["token"])// a guest token (enough for /me and /estimate); a run needs your personal token from /tokens.html
$TOKEN = "";
$TOKEN = api("POST", "/guest", ["slug" => "sales-territory-planner"])["token"];// a guest token (enough for /me and /estimate); a run needs your personal token from /tokens.html
Api.Token = "";
Api.Token = (await Api.Call("POST", "/guest", new { slug = "sales-territory-planner" }))!["token"]!.GetValue<string>();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}' me = api("GET", "/me")
print(me["subject_type"], me.get("credits"))const me = await api("GET", "/me");
console.log(me.subject_type, me.credits);me, _ := api("GET", "/me", nil, nil)
fmt.Println(me["subject_type"], me["credits"])JsonNode me = api("GET", "/me", null, null);
System.out.println(me.get("subject_type") + " " + me.get("credits"));me = api("GET", "/me")
puts [me["subject_type"], me["credits"]].inspect$me = api("GET", "/me");
echo $me["subject_type"], " ", $me["credits"] ?? "", "\n";var me = await Api.Call("GET", "/me");
Console.WriteLine($"{me!["subject_type"]} {me["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": "plan", "context": "A three-person inside sales team selling scheduling software to small businesses. Marcus has carried most of the pipeline for a year and is overloaded; we want a fairer split before the new quarter.", "reps": "r1 | Marcus Lee | home: none given | share 100% | 4 accounts | potential $360,000 | 97% of a fair share | regions: Central 2, East 1, West 1 | kept 3, gained 1, lost 5 | tiers A 3, B 0, C 1\nr2 | Nina Patel | home: none given | share 100% | 6 accounts | potential $390,000 | 105% of a fair share | regions: Central 3, East 3 | kept 2, gained 3, lost 1 | tiers A 1, B 3, C 2\nr3 | Omar Haddad | home: none given | share 100% | 6 accounts | potential $365,000 | 98% of a fair share | regions: West 4, East 2 | kept 3, gained 2, lost 0 | tiers A 1, B 2, C 3", "accounts": "a1 | Acme Robotics | East | $90,000 | tier A | moves from Marcus Lee to Nina Patel | balances the load\na2 | Brightline Studios | East | $45,000 | tier C | moves from Marcus Lee to Nina Patel | same region as the rep's other accounts\na3 | Corvid Security | East | $130,000 | tier A | stays with Marcus Lee | stays with current owner\na4 | Delta Kitchens | East | $30,000 | tier C | moves from Marcus Lee to Omar Haddad | balances the load\na5 | Evergreen Schools | East | $75,000 | tier B | moves from Marcus Lee to Nina Patel | same region as the rep's other accounts\na6 | Fieldstone Legal | East | $60,000 | tier B | moves from Marcus Lee to Omar Haddad | balances the load\na7 | Glacier Water | Central | $110,000 | tier A | stays with Marcus Lee | stays with current owner\na8 | Horizon Travel | Central | $40,000 | tier C | stays with Nina Patel | stays with current owner\na9 | Ironwood Builders | Central | $85,000 | tier B | stays with Nina Patel | stays with current owner\na10 | Juniper Dental | Central | $25,000 | tier C | moves from Nina Patel to Marcus Lee | balances the load\na11 | Kestrel Aviation | West | $150,000 | tier A | stays with Omar Haddad | stays with current owner\na12 | Lumen Labs | West | $35,000 | tier C | stays with Omar Haddad | stays with current owner\na13 | Meridian Hotels | West | $95,000 | tier A | stays with Marcus Lee | stays with current owner\na14 | Nimbus Cloud | West | $70,000 | tier B | stays with Omar Haddad | stays with current owner\na15 | Orchid Florists | West | $20,000 | tier C | new to Omar Haddad | same region as the rep's other accounts\na16 | Pioneer Seeds | Central | $55,000 | tier B | new to Nina Patel | same region as the rep's other accounts", "figures": "Accounts: 16; reps: 3; split by potential; allowed spread 10%; current owners not locked\nTotal potential: $1,115,000\nFair share for Marcus Lee: $371,667\nFair share for Nina Patel: $371,667\nFair share for Omar Haddad: $371,667\nVerdict: Balanced: every rep within 10% of a fair share\nAccounts changing owner: 6\nTier A: 5 accounts, $575,000\nTier B: 5 accounts, $345,000\nTier C: 6 accounts, $195,000", "checks": "note | 6 accounts change owner. Each needs a handoff from the old owner.\nnote | No reps were listed, so the 3 owners in your list were used.", "clip_note": ""}
api POST /estimate "$(cat input.json)" | jq '.data | {hold_credits, min_credits, model, model_alias, markup_bps, warnings}' inp = json.load(open("input.json")) # {"task": "plan", "context": "A three-person inside sales team selling scheduling software to small businesses. Marcus has carried most of the pipeline for a year and is overloaded; we want a fairer split before the new quarter.", "reps": "r1 | Marcus Lee | home: none given | share 100% | 4 accounts | potential $360,000 | 97% of a fair share | regions: Central 2, East 1, West 1 | kept 3, gained 1, lost 5 | tiers A 3, B 0, C 1\nr2 | Nina Patel | home: none given | share 100% | 6 accounts | potential $390,000 | 105% of a fair share | regions: Central 3, East 3 | kept 2, gained 3, lost 1 | tiers A 1, B 3, C 2\nr3 | Omar Haddad | home: none given | share 100% | 6 accounts | potential $365,000 | 98% of a fair share | regions: West 4, East 2 | kept 3, gained 2, lost 0 | tiers A 1, B 2, C 3", "accounts": "a1 | Acme Robotics | East | $90,000 | tier A | moves from Marcus Lee to Nina Patel | balances the load\na2 | Brightline Studios | East | $45,000 | tier C | moves from Marcus Lee to Nina Patel | same region as the rep's other accounts\na3 | Corvid Security | East | $130,000 | tier A | stays with Marcus Lee | stays with current owner\na4 | Delta Kitchens | East | $30,000 | tier C | moves from Marcus Lee to Omar Haddad | balances the load\na5 | Evergreen Schools | East | $75,000 | tier B | moves from Marcus Lee to Nina Patel | same region as the rep's other accounts\na6 | Fieldstone Legal | East | $60,000 | tier B | moves from Marcus Lee to Omar Haddad | balances the load\na7 | Glacier Water | Central | $110,000 | tier A | stays with Marcus Lee | stays with current owner\na8 | Horizon Travel | Central | $40,000 | tier C | stays with Nina Patel | stays with current owner\na9 | Ironwood Builders | Central | $85,000 | tier B | stays with Nina Patel | stays with current owner\na10 | Juniper Dental | Central | $25,000 | tier C | moves from Nina Patel to Marcus Lee | balances the load\na11 | Kestrel Aviation | West | $150,000 | tier A | stays with Omar Haddad | stays with current owner\na12 | Lumen Labs | West | $35,000 | tier C | stays with Omar Haddad | stays with current owner\na13 | Meridian Hotels | West | $95,000 | tier A | stays with Marcus Lee | stays with current owner\na14 | Nimbus Cloud | West | $70,000 | tier B | stays with Omar Haddad | stays with current owner\na15 | Orchid Florists | West | $20,000 | tier C | new to Omar Haddad | same region as the rep's other accounts\na16 | Pioneer Seeds | Central | $55,000 | tier B | new to Nina Patel | same region as the rep's other accounts", "figures": "Accounts: 16; reps: 3; split by potential; allowed spread 10%; current owners not locked\nTotal potential: $1,115,000\nFair share for Marcus Lee: $371,667\nFair share for Nina Patel: $371,667\nFair share for Omar Haddad: $371,667\nVerdict: Balanced: every rep within 10% of a fair share\nAccounts changing owner: 6\nTier A: 5 accounts, $575,000\nTier B: 5 accounts, $345,000\nTier C: 6 accounts, $195,000", "checks": "note | 6 accounts change owner. Each needs a handoff from the old owner.\nnote | No reps were listed, so the 3 owners in your list were used.", "clip_note": ""}
est = api("POST", "/estimate", inp)
print(est["hold_credits"], est["min_credits"], est["model"], est.get("warnings"))import { readFileSync } from "node:fs";
const input = JSON.parse(readFileSync("input.json", "utf8")); // {task, context, reps, accounts, figures, checks, clip_note}
const est = await api("POST", "/estimate", input);
console.log(est.hold_credits, est.min_credits, est.model, est.warnings);raw, _ := os.ReadFile("input.json") // add "os" to the imports
var input map[string]any
json.Unmarshal(raw, &input)
est, _ := api("POST", "/estimate", input, nil)
fmt.Println(est["hold_credits"], est["min_credits"], est["model"])Map<String, Object> input = M.readValue(new java.io.File("input.json"), Map.class);
JsonNode est = api("POST", "/estimate", input, null);
System.out.println(est.get("hold_credits") + " " + est.get("min_credits") + " " + est.get("model"));input = JSON.parse(File.read("input.json"))
est = api("POST", "/estimate", input)
puts [est["hold_credits"], est["min_credits"], est["model"]].inspect$input = json_decode(file_get_contents("input.json"), true);
$est = api("POST", "/estimate", $input);
echo $est["hold_credits"], " ", $est["min_credits"], " ", $est["model"], "\n";var input = JsonNode.Parse(File.ReadAllText("input.json"))!;
var est = await Api.Call("POST", "/estimate", input);
Console.WriteLine($"{est!["hold_credits"]} {est["min_credits"]} {est["model"]}");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="sales-territory-planner:plan:$(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: summary, territories, rules, handoffs, questions
echo "$J" | jq '.data | {charged_credits, truncated}' import hashlib, time
key = "sales-territory-planner:" + inp["task"] + ":" + hashlib.sha256(json.dumps(inp).encode()).hexdigest()[:16] + ":a1"
job = api("POST", "/run", inp, {"Idempotency-Key": key})
while True:
j = api("GET", "/jobs/" + job["job_id"])
if j["status"] in ("succeeded", "failed", "cancelled"):
break
time.sleep(2)
reply = json.loads(j["output"]["output"]) # {summary, territories, rules, handoffs, questions}
print(j["charged_credits"], j.get("truncated"), reply.get("summary"))import { createHash } from "node:crypto";
const key = `sales-territory-planner:${input.task}:${createHash("sha256").update(JSON.stringify(input)).digest("hex").slice(0, 16)}:a1`;
const job = await api("POST", "/run", input, { "Idempotency-Key": key });
let j;
do { await new Promise((r) => setTimeout(r, 2000)); j = await api("GET", "/jobs/" + job.job_id); }
while (!["succeeded", "failed", "cancelled"].includes(j.status));
const reply = JSON.parse(j.output.output);
console.log(j.charged_credits, j.truncated, reply.summary);sum := sha256.Sum256(raw) // add "crypto/sha256", "encoding/hex", "time" to the imports
key := "sales-territory-planner:" + input["task"].(string) + ":" + hex.EncodeToString(sum[:8]) + ":a1"
job, _ := api("POST", "/run", input, map[string]string{"Idempotency-Key": key})
var j map[string]any
for {
time.Sleep(2 * time.Second)
j, _ = api("GET", "/jobs/"+job["job_id"].(string), nil, nil)
if s := j["status"]; s == "succeeded" || s == "failed" || s == "cancelled" { break }
}
fmt.Println(j["charged_credits"], j["truncated"], j["output"].(map[string]any)["output"])var digest = java.security.MessageDigest.getInstance("SHA-256").digest(M.writeValueAsBytes(input));
String key = "sales-territory-planner:" + input.get("task") + ":" + HexFormat.of().formatHex(digest, 0, 8) + ":a1";
JsonNode job = api("POST", "/run", input, Map.of("Idempotency-Key", key)), j;
do { Thread.sleep(2000); j = api("GET", "/jobs/" + job.get("job_id").asText(), null, null); }
while (!Set.of("succeeded", "failed", "cancelled").contains(j.get("status").asText()));
JsonNode reply = M.readTree(j.get("output").get("output").asText());
System.out.println(j.get("charged_credits") + " " + reply);require "digest"
key = "sales-territory-planner:#{input["task"]}:#{Digest::SHA256.hexdigest(JSON.generate(input))[0, 16]}:a1"
job = api("POST", "/run", input, { "Idempotency-Key" => key })
j = nil
loop do
sleep 2
j = api("GET", "/jobs/#{job["job_id"]}")
break if %w[succeeded failed cancelled].include?(j["status"])
end
reply = JSON.parse(j["output"]["output"])
puts [j["charged_credits"], j["truncated"], reply["summary"]].inspect$key = "sales-territory-planner:" . $input["task"] . ":" . substr(hash("sha256", json_encode($input)), 0, 16) . ":a1";
$job = api("POST", "/run", $input, ["Idempotency-Key" => $key]);
do { sleep(2); $j = api("GET", "/jobs/" . $job["job_id"]); }
while (!in_array($j["status"], ["succeeded", "failed", "cancelled"]));
$reply = json_decode($j["output"]["output"], true);
echo $j["charged_credits"], " ", $reply["summary"], "\n";var digest = System.Security.Cryptography.SHA256.HashData(System.Text.Encoding.UTF8.GetBytes(input.ToJsonString()));
var key = $"sales-territory-planner:{input["task"]}:{Convert.ToHexString(digest, 0, 8).ToLowerInvariant()}:a1";
var job = await Api.Call("POST", "/run", input, new() { ["Idempotency-Key"] = key });
JsonNode j;
do { await Task.Delay(2000); j = (await Api.Call("GET", "/jobs/" + job!["job_id"]))!; }
while (!new[] { "succeeded", "failed", "cancelled" }.Contains(j["status"]!.GetValue<string>()));
var reply = JsonNode.Parse(j["output"]!["output"]!.GetValue<string>());
Console.WriteLine($"{j["charged_credits"]} {reply}");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: sales-territory-planner:plan:$(shasum -a 256 input.json | cut -c1-16):a1" --data @input.jsonrin = json.load(open("input.json")) # {"task": "plan", "context": "A three-person inside sales team selling scheduling software to small businesses. Marcus has carried most of the pipeline for a year and is overloaded; we want a fairer split before the new quarter.", "reps": "r1 | Marcus Lee | home: none given | share 100% | 4 accounts | potential $360,000 | 97% of a fair share | regions: Central 2, East 1, West 1 | kept 3, gained 1, lost 5 | tiers A 3, B 0, C 1\nr2 | Nina Patel | home: none given | share 100% | 6 accounts | potential $390,000 | 105% of a fair share | regions: Central 3, East 3 | kept 2, gained 3, lost 1 | tiers A 1, B 3, C 2\nr3 | Omar Haddad | home: none given | share 100% | 6 accounts | potential $365,000 | 98% of a fair share | regions: West 4, East 2 | kept 3, gained 2, lost 0 | tiers A 1, B 2, C 3", "accounts": "a1 | Acme Robotics | East | $90,000 | tier A | moves from Marcus Lee to Nina Patel | balances the load\na2 | Brightline Studios | East | $45,000 | tier C | moves from Marcus Lee to Nina Patel | same region as the rep's other accounts\na3 | Corvid Security | East | $130,000 | tier A | stays with Marcus Lee | stays with current owner\na4 | Delta Kitchens | East | $30,000 | tier C | moves from Marcus Lee to Omar Haddad | balances the load\na5 | Evergreen Schools | East | $75,000 | tier B | moves from Marcus Lee to Nina Patel | same region as the rep's other accounts\na6 | Fieldstone Legal | East | $60,000 | tier B | moves from Marcus Lee to Omar Haddad | balances the load\na7 | Glacier Water | Central | $110,000 | tier A | stays with Marcus Lee | stays with current owner\na8 | Horizon Travel | Central | $40,000 | tier C | stays with Nina Patel | stays with current owner\na9 | Ironwood Builders | Central | $85,000 | tier B | stays with Nina Patel | stays with current owner\na10 | Juniper Dental | Central | $25,000 | tier C | moves from Nina Patel to Marcus Lee | balances the load\na11 | Kestrel Aviation | West | $150,000 | tier A | stays with Omar Haddad | stays with current owner\na12 | Lumen Labs | West | $35,000 | tier C | stays with Omar Haddad | stays with current owner\na13 | Meridian Hotels | West | $95,000 | tier A | stays with Marcus Lee | stays with current owner\na14 | Nimbus Cloud | West | $70,000 | tier B | stays with Omar Haddad | stays with current owner\na15 | Orchid Florists | West | $20,000 | tier C | new to Omar Haddad | same region as the rep's other accounts\na16 | Pioneer Seeds | Central | $55,000 | tier B | new to Nina Patel | same region as the rep's other accounts", "figures": "Accounts: 16; reps: 3; split by potential; allowed spread 10%; current owners not locked\nTotal potential: $1,115,000\nFair share for Marcus Lee: $371,667\nFair share for Nina Patel: $371,667\nFair share for Omar Haddad: $371,667\nVerdict: Balanced: every rep within 10% of a fair share\nAccounts changing owner: 6\nTier A: 5 accounts, $575,000\nTier B: 5 accounts, $345,000\nTier C: 6 accounts, $195,000", "checks": "note | 6 accounts change owner. Each needs a handoff from the old owner.\nnote | No reps were listed, so the 3 owners in your list were used.", "clip_note": ""}
req = urllib.request.Request(BASE + "/run-stream", method="POST", data=json.dumps(rin).encode(),
headers={"Content-Type": "application/json", "Authorization": "Bearer " + TOKEN,
"Idempotency-Key": "sales-territory-planner:plan:" + hashlib.sha256(json.dumps(rin).encode()).hexdigest()[:16] + ":a1"})
with urllib.request.urlopen(req) as r:
for line in r:
line = line.decode().strip()
if line.startswith("data:"):
print(line[5:].strip()[:200])const rin = JSON.parse(readFileSync("input.json", "utf8"));
const r = await fetch(BASE + "/run-stream", { method: "POST", body: JSON.stringify(rin), headers: {
"Content-Type": "application/json", Authorization: "Bearer " + TOKEN,
"Idempotency-Key": `sales-territory-planner:plan:${createHash("sha256").update(JSON.stringify(rin)).digest("hex").slice(0, 16)}:a1` } });
const dec = new TextDecoder();
for await (const chunk of r.body) for (const line of dec.decode(chunk).split("\n"))
if (line.startsWith("data:")) console.log(line.slice(5).trim().slice(0, 200));rraw, _ := os.ReadFile("input.json") // add "bufio", "strings" to the imports
rs := sha256.Sum256(rraw)
req, _ := http.NewRequest("POST", base+"/run-stream", bytes.NewReader(rraw))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer "+token)
req.Header.Set("Idempotency-Key", "sales-territory-planner:plan:"+hex.EncodeToString(rs[:8])+":a1")
res, _ := http.DefaultClient.Do(req)
sc := bufio.NewScanner(res.Body)
for sc.Scan() { if l := sc.Text(); strings.HasPrefix(l, "data:") { fmt.Println(l[5:]) } }String rin = java.nio.file.Files.readString(java.nio.file.Path.of("input.json"));
var rd = java.security.MessageDigest.getInstance("SHA-256").digest(rin.getBytes());
var sreq = HttpRequest.newBuilder(URI.create(BASE + "/run-stream")).header("Content-Type", "application/json")
.header("Authorization", "Bearer " + token).header("Idempotency-Key", "sales-territory-planner:plan:" + HexFormat.of().formatHex(rd, 0, 8) + ":a1")
.POST(HttpRequest.BodyPublishers.ofString(rin)).build();
C.send(sreq, HttpResponse.BodyHandlers.ofLines()).body().filter(l -> l.startsWith("data:")).forEach(System.out::println);rin = File.read("input.json")
uri = URI(BASE + "/run-stream")
req = Net::HTTP::Post.new(uri, "Content-Type" => "application/json", "Authorization" => "Bearer #{TOKEN}",
"Idempotency-Key" => "sales-territory-planner:plan:#{Digest::SHA256.hexdigest(rin)[0, 16]}:a1")
req.body = rin
Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |h|
h.request(req) { |res| res.read_body { |chunk| chunk.each_line { |l| puts l if l.start_with?("data:") } } }
end$rin = file_get_contents("input.json");
$ch = curl_init(BASE . "/run-stream");
curl_setopt_array($ch, [CURLOPT_POST => true, CURLOPT_POSTFIELDS => $rin, CURLOPT_HTTPHEADER => [
"Content-Type: application/json", "Authorization: Bearer $TOKEN",
"Idempotency-Key: sales-territory-planner:plan:" . substr(hash("sha256", $rin), 0, 16) . ":a1"],
CURLOPT_WRITEFUNCTION => function ($ch, $chunk) { foreach (explode("\n", $chunk) as $l) if (str_starts_with($l, "data:")) echo $l, "\n"; return strlen($chunk); }]);
curl_exec($ch);var rin = File.ReadAllText("input.json");
var rd = System.Security.Cryptography.SHA256.HashData(System.Text.Encoding.UTF8.GetBytes(rin));
var sreq = new HttpRequestMessage(HttpMethod.Post, Api.Base + "/run-stream") { Content = new StringContent(rin, System.Text.Encoding.UTF8, "application/json") };
sreq.Headers.Add("Authorization", "Bearer " + Api.Token);
sreq.Headers.Add("Idempotency-Key", $"sales-territory-planner:plan:{Convert.ToHexString(rd, 0, 8).ToLowerInvariant()}:a1");
using var http = new HttpClient();
using var res = await http.SendAsync(sreq, HttpCompletionOption.ResponseHeadersRead);
using var rdr = new StreamReader(await res.Content.ReadAsStreamAsync());
for (string? l; (l = await rdr.ReadLineAsync()) != null;) if (l.StartsWith("data:")) Console.WriteLine(l);