- 1
Get an API key#
Open the console, go to API keys and choose Create key. The key is shown once, so copy it straight into your environment. Live keys start with
dn_live_.export DECISIONNODE_API_KEY="dn_live_..." - 2
Send your first request#
Post a state and your questions to
https://api.decisionnode.com/v1/decidehttps://api.decisionnode.com/. This one routes a support message, ranks its urgency and asks whether to refund it automatically.v1/ decide curl https://api.decisionnode.com/v1/decide \ -H "Authorization: Bearer $DECISIONNODE_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "decisionnode-latest", "state": "Customer: I was charged twice and nobody has replied for 3 days.", "questions": { "route": { "type": "choice", "instructions": "Where should this go?", "criteria": { "billing": "money", "bug": "broken", "account": "login" } }, "urgency": { "type": "score", "instructions": "How urgent is this?", "criteria": ["routine", "today", "urgent", "critical"] }, "refund": { "type": "truth", "instructions": "Refund this automatically?" } } }' - 3
Read the answers#
Each answer comes back under the key you gave its question. The route is
billingwith confidence 0.81, the urgency sits at 2.31 on your 0 to 3 scale, and the refund probability is 0.94. That last one is a Truth answer: the calibrated probability, from 0.00 to 1.00, that the statement is true, here that this charge should be refunded automatically. 0.80 means true about 8 times in 10. Your code picks the cut-off: 0.50 for a plain yes or no, higher when acting on a false yes is costly, as with a refund.{ "model": "decisionnode-1.0", "answers": { "route": { "type": "choice", "choice": "billing", "confidence": 0.81, "probabilities": { "account": 0.05, "billing": 0.87, "bug": 0.08 } }, "urgency": { "type": "score", "score": 2.31, "confidence": 0.47, "legend": { "0": "routine", "1": "today", "2": "urgent", "3": "critical" }, "probabilities": { "0": 0.01, "1": 0.09, "2": 0.48, "3": 0.42 } }, "refund": { "type": "truth", "truth": 0.94 } }, "usage": { "input_tokens": 62, "output_tokens": 0 } } - 4
Branch on them#
Answers are numbers and keys, so your code acts on them the moment they land. Sure cases go straight through; unsure ones take the safe path, still automatically.
route = answers["route"] urgency = answers["urgency"] refund = answers["refund"] if refund["truth"] >= 0.8: # sure: refund now issue_refund(ticket) reply(ticket, template="refund_issued") elif route["confidence"] < 0.7: # unsure: safe path reply(ticket, template="ask_for_order_id") else: # sure: route it priority = round(urgency["score"]) assign(ticket, route["choice"], priority)
What just happened#
- The model read the state once and answered all three questions in one pass, with
decisionnode-latest. - It generated no text:
usage.output_tokensis always 0, and output is free. - The request used 62 input tokens. At $0.042 per million, a million of these requests cost about $2.60.
- Up to 64k tokens fit in one request, so the state can be a whole thread or a JSON record.
- Choice, score and truth are three of the four question types. The fourth, Number, answers how many or what value, on a grid you set.
Next steps#
- Write better questionsOptions, scales and instructions that the model reads well.Read
- Gate on confidenceAct above a threshold, re-check the unsure middle with the full model, and take the safe path below it.Read
- Add an imageReceipts, photos and screenshots in the same request.Read
- Handle errors400 to 529: which to fix, which to retry, and what to do when credit runs out.Read