This page uses plain HTTPS. The SDKs for eight languages and the dn command line send the same requests: see Choose how to call DecisionNode.
- 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. Keys start with
dn_live_; a key with full access, the default, works with both models and every endpoint. Console, keys and members covers rotation and team access.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", "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 on our evaluation data. 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-main-0.9.1-rc1", "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, "cost": { "usd": 0.000002604, "model_usd": 0.000002604, "boosters_usd": 0, "free_tier": false } } } - 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. - 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.
- Your requests and their answers improve our models unless you opt out in the console. With zero retention, requests and answers sent to
/v1/decideare not stored once the answer is returned and are not used to improve the models; sessions, batches and safety records are described in Data and privacy, which also says how to opt out. - Choice, score and truth are three of the question types. Number answers how many or what value, on a grid you set, and point and box answer where in an image.
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