TypeScript SDK
@meetloyd/client is the official TypeScript client for the MeetLoyd API. It is typed end to end, reads streamed answers for you, and works in Node.js, Bun and React Native.
Install
npm install @meetloyd/client
# or
bun add @meetloyd/client
Quick start
import { MeetLoyd } from '@meetloyd/client'
const client = new MeetLoyd({
apiKey: process.env.MEETLOYD_API_KEY!, // starts with ml_
})
// List the agents you can see
const { agents } = await client.agents.list()
// Run one and wait for the answer
const run = await client.agents.execute(agents[0].id, 'Summarise yesterday’s tickets')
console.log(run.output)
Create the key under Settings → API access (see Authentication).
Configuration
const client = new MeetLoyd({
apiKey: 'ml_…', // required
baseUrl: 'https://api.meetloyd.com', // optional: this is the default
timeout: 30000, // optional, milliseconds
})
Set baseUrl only if your organisation runs a dedicated or on-premises installation.
Agents
// Every agent lives in a workspace and a team
const agent = await client.agents.create({
appId: 'app_456',
teamId: 'team_789', // or: createTeam: true, newTeamName: 'Support'
name: 'Support Agent',
model: 'claude-sonnet-latest', // optional, this is the default
systemPrompt: 'You answer customer questions about orders.',
})
await client.agents.update(agent.id, { name: 'Order Support' })
const run = await client.agents.execute(agent.id, 'Where is order 1042?')
const { runs } = await client.agents.runs(agent.id, { limit: 10 })
await client.agents.pause(agent.id)
await client.agents.resume(agent.id)
await client.agents.delete(agent.id)
create checks before calling the API that you passed a workspace and exactly one of teamId or createTeam. If not, it throws a MeetLoydError with code TEAM_REQUIRED.
Conversations and streaming
const conversation = await client.conversations.create({ agentId: agent.id })
// Stream the answer as it is written
for await (const event of client.conversations.stream(conversation.id, 'Hello!')) {
switch (event.type) {
case 'token': process.stdout.write(event.token); break
case 'tool_call': console.log('\nUsed', event.toolCall.name); break
case 'replace': console.log('\nFinal answer:', event.content); break
case 'done': console.log('\nTokens:', event.data.tokenUsage?.total); break
case 'error': console.error(event.error); break
}
}
// Or wait for the whole answer
const { content, tokenUsage, cost } = await client.conversations.send(conversation.id, 'And in French?')
// Read the history
const { messages, hasMore } = await client.conversations.history(conversation.id, { limit: 50 })
A replace event means the answer was rewritten after streaming, for example by a guardrail. Show event.content instead of what you streamed. send() does this for you.
Other modules
| Module | What it covers |
|---|---|
client.tasks | Create, run, cancel and delete tasks, and read their runs (tasks.runs(id)) |
client.workflows | Create and update workflows, run, activate, pause (back to draft), runs and cancellation |
client.schedules | Create schedules, pause and resume them, trigger one now |
client.triggers | Create triggers, enable and disable them |
client.templates | Browse templates and deploy(idOrSlug, { appId, teamId? }) one as a new agent |
client.manifests | Validate, resolve, deploy, upgrade and roll back team manifests |
client.apiKeys | list, get, create({ name, permissions?, expiresInDays? }), update (rename), delete |
client.securityCenter | Security overview, score, recommendations, and the MFA, session, password and login policies |
client.identity | Agent identity, tokens and tool-access policies (Agent Identity API) |
client.teams | Teams, and who has access to them: listMembers, addMember(teamId, userId, 'team_editor'), updateMemberRole, removeMember |
client.webhooks | Create, update, test and delete webhooks, list the events you can subscribe to and recent deliveries |
client.audit | Audit logs (query, get, getStats, CSV export), the tamper check (verifyIntegrity), audit alerts and SIEM integrations |
client.accessReviews | Access review campaigns: create, activate, getItems, decide, complete |
client.billing | Usage, invoices, the card on file (getPaymentMethod) and a link to the billing portal (createPortalSession) |
client.memory, client.usage, client.notifications | The matching parts of the API |
There is no in-place key rotation: create a new key, move your integration to it, then delete the old one.
Errors
Every failure throws a MeetLoydError:
import { MeetLoyd, MeetLoydError } from '@meetloyd/client'
try {
await client.agents.get('agent_missing')
} catch (error) {
if (error instanceof MeetLoydError) {
console.log(error.status) // 404
console.log(error.code) // 'notFound'
console.log(error.message) // 'Agent not found'
}
}
A timeout throws status 408 with code TIMEOUT, and a network failure throws status 0 with code NETWORK_ERROR.
Calling any endpoint
For an endpoint without a typed method, use the low-level helpers. They add your key, apply the timeout and throw MeetLoydError:
const data = await client.request<{ stats: unknown }>('GET', '/api/v1/conversations/stats')
for await (const event of client.stream('POST', `/api/v1/conversations/${id}/messages`, { message: 'Hi' })) {
// same events as conversations.stream()
}
Good practice
- Read the key from the environment or a secret store, never from source code.
- Create one client and reuse it.
- Stream long or interactive answers with
conversations.stream(). - Branch on
error.statusanderror.code, never on the message text.
Next: the CLI, built on this SDK.