Skip to main content

TypeScript SDK

The official TypeScript SDK for MeetLoyd (@meetloyd/client) provides typed access to the platform API with streaming support. It covers agents, conversations, tasks, schedules, triggers, memory, teams, manifests, governance, billing, and more.

Installation

npm install @meetloyd/client
# or
bun add @meetloyd/client

Quick Start

import { MeetLoyd } from '@meetloyd/client';

const client = new MeetLoyd({
apiKey: 'sk_live_your_api_key',
baseUrl: 'https://app.meetloyd.com', // Optional (defaults to localhost:4000)
timeout: 30000, // Optional, in ms
});

// List agents
const { agents } = await client.agents.list();
console.log(agents);

// Create an agent
const agent = await client.agents.create({
name: 'My Assistant',
systemPrompt: 'You are a helpful assistant.',
model: 'claude-sonnet-4-6',
});

// Execute an agent (single message, non-streaming)
const run = await client.agents.execute(agent.id, 'Hello!');
console.log(run);

Client Configuration

The MeetLoyd constructor accepts a MeetLoydConfig object:

const client = new MeetLoyd({
apiKey: 'sk_live_...', // Required
baseUrl: 'https://...', // Optional (default: http://localhost:4000)
timeout: 30000, // Optional, ms (default: 30000)
});

API Modules

The client exposes the following API modules as public properties:

ModuleDescription
client.agentsList, get, create, update, delete, execute, pause, resume agents; list runs
client.conversationsCreate, get, delete conversations; stream and send messages
client.usageUsage summary, daily breakdown, per-agent usage
client.tasksCRUD for tasks, run, cancel
client.workflowsCRUD for workflows, run, pause, activate; list/cancel runs
client.teamsCRUD for teams, member management
client.templatesBrowse, deploy, manage templates
client.schedulesCRUD for schedules, pause/resume/trigger
client.triggersCRUD for triggers, enable/disable/test
client.manifestsValidate, resolve, deploy, upgrade, rollback manifests
client.memoryCreate, search, list, delete memories; quick-store helpers; team memory; A2A; storage config
client.toolsList, get, test, delete tools; list builtins
client.storeBrowse, install, uninstall; reviews
client.apiKeysList, create, delete, rotate API keys
client.governanceKill switch, prompt versioning, suggestions, A/B tests, audit log
client.budgetsBudget CRUD, check, summary, stats
client.dlpDLP config, classifications, permissions, violations
client.cotChain-of-thought config, records, annotations
client.complianceCompliance frameworks, reports, schedules, evidence
client.lifecycleFirst-start, charters, handshakes, discovery cache
client.securityCenterDashboard, controls, config
client.accessReviewsAccess review CRUD, decisions
client.ssoSSO/SAML config
client.auditAudit logs, SIEM integrations, hash chain verification
client.incidentsIncidents, timeline, security alerts, change requests
client.identityNANDA AgentFacts, SPIFFE, TBAC, token exchange, attestations
client.contextGraphEntities, edges, visibility policies, propagation, cross-team hints
client.projectsProjects, milestones, artifacts, members, vault, dispatch rules
client.filesUpload, download, parse, scan files
client.modelsList models, capabilities, cost calculation
client.billingSubscription, plans, invoices, payment methods
client.analyticsDashboard, time series, rankings, costs, errors, patterns
client.notificationsList, read, preferences, push subscriptions
client.webhooksCRUD for webhooks, deliveries, retry
client.oauthIntegrationsBrowse catalog, connect/disconnect, OAuth config
client.loydSurfacesLoyd chat interface

Agents API

// List agents (paginated)
const { agents, meta } = await client.agents.list({ page: 1, limit: 20 });

// Get a single agent
const agent = await client.agents.get('agent-id');

// Create an agent
const newAgent = await client.agents.create({
name: 'Support Agent',
systemPrompt: 'You are a customer support agent.',
model: 'claude-sonnet-4-6',
});

// Update an agent
const updated = await client.agents.update('agent-id', { name: 'New Name' });

// Delete an agent
await client.agents.delete('agent-id');

// Execute (non-streaming)
const run = await client.agents.execute('agent-id', 'Summarize this report.');

// List runs for an agent
const { runs } = await client.agents.runs('agent-id', { limit: 10 });

// Pause / Resume
await client.agents.pause('agent-id');
await client.agents.resume('agent-id');

Conversations API

// Create a conversation
const conversation = await client.conversations.create({ agentId: 'agent-id' });

// Get conversation with messages
const conv = await client.conversations.get('conversation-id');

// List conversations by agent
const { conversations } = await client.conversations.listByAgent('agent-id');

// Stream a response (SSE)
for await (const event of client.conversations.stream('conversation-id', 'Hello!')) {
if (event.type === 'token') {
process.stdout.write(event.token);
} else if (event.type === 'tool_call') {
console.log('Tool called:', event.toolCall);
} else if (event.type === 'done') {
console.log('Done. Tokens:', event.data.tokenUsage.total);
} else if (event.type === 'error') {
console.error('Error:', event.error);
}
}

// Send and collect the full response (convenience wrapper around stream)
const result = await client.conversations.send('conversation-id', 'Hello!');
console.log(result.content);
console.log(result.tokenUsage); // { input, output, total }
console.log(result.cost);

// Delete a conversation
await client.conversations.delete('conversation-id');

Error Handling

The SDK exports a single error class, MeetLoydError:

import { MeetLoyd, MeetLoydError } from '@meetloyd/client';

try {
await client.agents.get('nonexistent');
} catch (error) {
if (error instanceof MeetLoydError) {
console.log(error.message); // Human-readable message
console.log(error.status); // HTTP status code (e.g. 404)
console.log(error.code); // Optional error code string (e.g. 'NOT_FOUND')
}
}

MeetLoydError is thrown for HTTP errors, timeouts (status 408, code TIMEOUT), and network failures (status 0, code NETWORK_ERROR).

Low-Level Request Methods

For advanced use cases, the client exposes three request methods:

// JSON request
const data = await client.request<MyType>('GET', '/api/v1/custom-endpoint');

// XML body request (e.g. MSPDI import)
const data = await client.requestText<MyType>('POST', '/api/v1/projects/import', xmlString);

// SSE streaming
for await (const event of client.stream('POST', '/api/v1/some-stream', body)) {
// event: StreamEvent { type: 'token' | 'tool_call' | 'done' | 'error', ... }
}

Best Practices

  1. Use environment variables for API keys -- never hardcode them.
  2. Reuse the client instance -- create once and share across your application.
  3. Use streaming for interactive or long-running responses (conversations.stream()).
  4. Handle MeetLoydError -- check error.status to distinguish 401/403/404/429 errors.

Next: Learn about the Python SDK for Python applications.