Skip to main content
This is the TypeScript snippet from your agent’s page in the dashboard, which fills in the agent’s URL for you. It uses the built in fetch, and there is no Onecortex SDK to install. It runs in Node.js 20 or later, Bun and Deno.

Before you begin

  • A deployed agent and its ID, from its page in the dashboard.
  • An API key in ONECORTEX_API_KEY.

Stream the reply

The browser’s EventSource sends only GET requests and cannot set a header, so read the stream from fetch. Replace agt_... with your agent’s ID:
invoke.ts
For the quickstart’s echo agent:
Output
Run it with npx tsx invoke.ts, bun invoke.ts or node invoke.ts on Node.js 22.6 or later. A request that is refused before the run starts, for example with a wrong key, has no stream: check response.ok first if you want its message, which is in the JSON body.
A stream that has started has already sent 200 OK, and cannot change it. If the run fails after that, the failure arrives in the stream as event: error. Handle it: a client that reads only text and done shows a failed run as an empty success.

Get one JSON response

Leave out stream: true to wait for the whole run and get one body:
invoke-json.ts
Output
Every field of the body is on the invoke API.

Continue a conversation

Send the same sessionId on each call to reach the same running instance of your agent:
See Sessions for what a session keeps, and what it does not.
Last modified on September 28, 2026