Node SDK

npm install @glytos/node

Setup

import { Glytos } from '@glytos/node';

const glytos = new Glytos({ apiKey: process.env.GLYTOS_API_KEY! });

To act in a specific environment, name it - dev, staging, prod, or an environment uuid. Without it, requests use the organization's default environment. A value that matches no environment falls back to the default rather than failing.

const prod = new Glytos({ apiKey: process.env.GLYTOS_API_KEY!, environment: 'prod' });

Timeouts

The client sets no timeout of its own: a request waits as long as fetch does. A text turn can take a while when the model writes a long reply, so choose a limit that leaves room for it. To set one, pass a fetch that adds an abort signal:

const glytos = new Glytos({
  apiKey: process.env.GLYTOS_API_KEY!,
  fetch: (input, init) => fetch(input, { ...init, signal: AbortSignal.timeout(120_000) }),
});

The signal covers the whole exchange, including reading the body, so it also ends a stream that runs past it.

Text conversations

A thread holds a conversation; a run is one turn on it. The reply is in the result - there is no run to poll. See Chat.

const thread = await glytos.threads.create({ agent: agentUuid });
const run = await glytos.threads.runs.create(thread, 'What are your opening hours?');

// Or stream it as it is written
for await (const event of glytos.threads.runs.stream(thread, 'Summarise the policy')) {
  if (event.type === 'token') process.stdout.write(event.delta);
}

agents is an alias of workflows: the product calls them agents, the API path is /workflows. Either works.

Resources

The client exposes the API by resource:

await glytos.workflows.list();
await glytos.workflows.retrieve(uuid);
await glytos.workflows.create({ name: 'Receptionist', mode: 'prompt' });
await glytos.workflows.publish(uuid);

await glytos.calls.create({ transport: 'phone', workflow_uuid: uuid, to_number: '+1...' });
await glytos.calls.list();
await glytos.calls.control(callUuid, { action: 'say', text: 'One moment, please.' });

await glytos.workflows.session(workflowUuid, sessionUuid);

The client covers agents (alias workflows), threads, folders, imports, chat, calls, phoneNumbers, sipTrunks, campaigns, dnc, sessions, webhooks, tools, knowledgeBase, vectorStores, integrations, automations, testSuites, analytics, billing, environments, providers, apiKeys and organizations.

Anything not wrapped

The SDK is thin on purpose. Anything it does not wrap is still reachable, with auth and error handling applied:

await glytos.request('GET', '/audit');

Verifying webhooks

import { verifyWebhook } from '@glytos/node';

// `rawBody` must be the untouched request body - parsing and re-serialising it
// changes the bytes and the signature will not match.
const signature = request.headers['x-glytos-signature'];
const ok = typeof signature === 'string' && verifyWebhook(rawBody, signature, secret);

It is also on the client as glytos.webhooks.verify(...). See Webhooks.