Skip to main content
The HTTP API creates Sessions, reads their events and sends follow-ups. Use it when your own product shows the conversation. This page builds a small TypeScript client that starts a Session on your computer, follows it, and sends a follow-up.

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

Create an API key in Settings > API with the scopes below, and export it. Do not paste the key into a file.
See Authentication and scopes.

Base URL and calls

Every call goes to https://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

The target field selects the computer:
  • {"kind": "headless", "device_id": "...", "cwd": "/path"} runs on a computer you connected with reason connect. Get device_id from the devices list. Use cwd to choose the folder.
  • {"kind": "cloud"} runs on a Reason cloud computer.
  • Omit target and it runs in the cloud.
Creating a Session returns at once. The Session runs in the background, so poll it.

Sample

Save as reason-chat.ts and run it with bun reason-chat.ts.

Verify

  • Run the script. It prints the Session URL, then the pwd reply, 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 exit and outcome success. Treat any other outcome as not done.
To stop a Session early, send POST .../cancel with {"mode": "graceful"}.

Notes

  • Events can repeat across pages. The sample keeps the highest seq per id and orders by position. Events reference explains why.
  • The sample reads assistant events only. Tool calls and reasoning are in the same feed with other type values.
  • Pending: a public TypeScript SDK with event long polling is in progress. Until it ships, use the calls above.