What you will have
- A script that creates a Session on a computer you own, or in the cloud if none is connected.
- A printed transcript of the agent’s replies, read from
/events. - A follow-up message in the same Session.
Prerequisites
See Authentication and scopes.
Base URL and calls
Every call goes tohttps://api.reasonmachines.com/v3, with Authorization: Bearer $REASON_API_KEY. Get your organization ID once from GET /v3/self (the field is org_id).
Where the Session runs
Thetarget field selects the computer:
{"kind": "headless", "device_id": "...", "cwd": "/path"}runs on a computer you connected withreason connect. Getdevice_idfrom the devices list. Usecwdto choose the folder.{"kind": "cloud"}runs on a Reason cloud computer.- Omit
targetand it runs in the cloud.
Sample
Save asreason-chat.ts and run it with bun reason-chat.ts.
Verify
- Run the script. It prints the Session URL, then the
pwdreply, then the follow-up reply. - Open the URL. The same Session shows the same two turns in the Reason app.
- Check the exit status: a finished Session has status
exitand outcomesuccess. Treat any other outcome as not done.
POST .../cancel with {"mode": "graceful"}.
Notes
- Events can repeat across pages. The sample keeps the highest
seqperidand orders byposition. Events reference explains why. - The sample reads
assistantevents only. Tool calls and reasoning are in the same feed with othertypevalues. - Pending: a public TypeScript SDK with event long polling is in progress. Until it ships, use the calls above.

