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’sEventSource sends only GET requests and cannot set a header, so read the stream from fetch. Replace agt_... with your agent’s ID:
invoke.ts
echo agent:
Output
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.
Get one JSON response
Leave outstream: true to wait for the whole run and get one body:
invoke-json.ts
Output
Continue a conversation
Send the samesessionId on each call to reach the same running instance of your agent: