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.

Shell
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

ask.mjs
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:

Shell
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:

Shell
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.

JavaScript, invoice.mjs
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.

SDK errors and what to do
KindWhat happenedWhat to do
configurationThe API key is missing or not in the right form.Set SESS_API_KEY and run again.
api with code INVALID_SCHEMA and a fieldA 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.
apiSess refused the request; code says why.Look up the code in Error codes.
wait_ended with code WAIT_TIMEOUTNo answer arrived while waiting.Wait again on the same Session and revision. Do not create a second one.
wait_ended with another codeNo 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, transportA 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.
abortedYour code cancelled the call with its abort signal.Nothing to fix; the Session stays available.
protocolSess's answer was not in the form the SDK expects.Do not retry in a loop. Contact support with the request ID.
unknown_outcomeThe create may or may not have happened.Do not create again automatically: a retry could send the person a second link.
receipt_verificationThe answer did not match its signed receipt.Do not use the answer. Contact support.

Where next

Was this page useful?

Tell us more

Thanks for telling us.

You’ve sent a lot of answers in the last hour. Please try again later.

This couldn’t be sent right now. Please try again later.

That didn’t go through. Keep your note under 280 characters and send it again.

No account needed. We keep your answer, your note and this page’s address for a year, with a one-way code of your network address to stop abuse. Please leave out personal details.