SDK quickstart
Ask a person one question from Node.js.
On this page
1. Install
You need Node.js 22 (22.14 or later) or Node.js 24, and a Sess API key. Create one in your developer account.
npm install @sess.si/sdk@0.5.0
The SDK is published on npm as 0.5.0, the latest tag. Install it by its exact version.
2. Ask
import { Sess } from '@sess.si/sdk';
const sess = new Sess({ apiKey: process.env.SESS_API_KEY });
const plan = await sess.ask({
question: 'Plan your weekend',
details: 'Tell me where and when. I will suggest three plans that fit the forecast.',
submit_label: 'Next',
fields: [
{ type: 'choice', name: 'place', label: 'Where', options: ['Toronto', 'Vancouver', 'Montréal'] },
{ type: 'choice', name: 'day', label: 'Which day', options: ['Saturday', 'Sunday'] },
],
});
console.log(`Open this Sess link on your phone: ${plan.link}`);
3. What you'll see
Save it as ask.mjs, set your key, and run it:
read -rs SESS_API_KEY && export SESS_API_KEY
node ask.mjs
You will see a Sess link. Open it on any device and answer.
The link is the person's key to the page: anyone who has it can answer. Send it only to the person you are asking, and keep it out of logs and chat channels.
Keep the words short: the question at most 60 characters, each field label at most 40, each option at most 30 and the button (submit_label) at most 16. A longer text is never cut; the error names it and its limit. See Limits.
Build your first agent
One command creates a weekend planner that asks you two questions and plans on the real forecast:
npm create @sess.si/agent@0.3.0 my-agent
It asks for your API key, hidden as you paste it, and a contact for the weather services, then prints a Sess link. Answer the two questions on your phone. Your plan prints in the terminal with a verified receipt.
Run it again later with cd my-agent && npm start. The agent is two files. To change a question, edit one form() in agent.mjs.
Ask for approval of a bill
invoice() builds the items component and its actions, and adds up the subtotal and total for you. Amounts are whole numbers in the currency’s smallest unit: 420000 is $4,200.00 in CAD. money() checks one, and never rounds or converts.
import { Sess, invoice } from '@sess.si/sdk';
const sess = new Sess({ apiKey: process.env.SESS_API_KEY });
const { data } = await sess.sessions.create({ interaction: invoice({
title: 'Approve invoice 2041?', label: 'Invoice 2041', currency: 'CAD', // amounts in cents
rows: [{ name: 'Design retainer, October', amount: 420000 },
{ name: 'Stock photography licence', detail: '2 × $49.99', amount: 9998 }],
lines: [{ label: 'GST 5%', amount: 21500, role: 'tax' }],
}) });
console.log('Open this link on your phone:', data.human_url);
const { response } = await sess.sessions.waitForResponse(data.id, { revision: data.revision });
console.log(response.action_id); // 'approve' or 'decline'
The money rules, the limits and the other transactions are in Commerce.
If something fails
Every error is a SessError with a kind; check the kind, not the message.
| Kind | What happened | What to do |
|---|---|---|
configuration | The API key is missing or not in the right form. | Set SESS_API_KEY and run again. |
api with code INVALID_SCHEMA and a field | A text is too long. The error names it (field), its length and the limit, all in characters. | Shorten that text to at most the limit and create again. Nothing was created, so the person gets one link. See Limits. |
api | Sess refused the request; code says why. | Look up the code in Error codes. |
wait_ended with code WAIT_TIMEOUT | No answer arrived while waiting. | Wait again on the same Session and revision. Do not create a second one. |
wait_ended with another code | No answer can arrive for this revision: REVISION_SUPERSEDED (a newer revision was published), CLOSED_WITHOUT_RESPONSE (the Session ended unanswered) or NOT_INTERACTIVE. | Do not wait again. Read the Session to see its current state. |
timeout, transport | A request did not complete: it ran out of time or the network failed. | Try again later. A create that may already have reached Sess is reported as unknown_outcome instead. |
aborted | Your code cancelled the call with its abort signal. | Nothing to fix; the Session stays available. |
protocol | Sess's answer was not in the form the SDK expects. | Do not retry in a loop. Contact support with the request ID. |
unknown_outcome | The create may or may not have happened. | Do not create again automatically: a retry could send the person a second link. |
receipt_verification | The answer did not match its signed receipt. | Do not use the answer. Contact support. |
Where next
- Quickstart with curl: the same loop over plain HTTPS, with no signup.
- Concepts: what a request is, the Session resource, revisions, results and receipts.
- API reference: every operation the SDK calls.