TypeScript SDK
The TypeScript SDK package in this repository is @synapsex/sdk.
Install
npm install @synapsex/sdk
From source:
cd apps/agents-synapsex/shared/sdk
npm install
Create A Client
import { SynapseXClient } from '@synapsex/sdk';
const client = new SynapseXClient({
baseUrl: 'https://api.synapsex.ai',
accessToken: process.env.SYNAPSEX_ACCESS_TOKEN!,
tenantId: process.env.SYNAPSEX_TENANT_ID!,
});
The SDK sends:
| Header | Value |
|---|
Authorization | Bearer <accessToken> |
X-Tenant-Id | Tenant ID passed to the constructor |
Auth
const session = await client.auth.login(
'user@example.com',
process.env.SYNAPSEX_PASSWORD!,
'acme-corp',
);
client.setAccessToken(session.accessToken);
If you construct the client with refreshToken, the HTTP client can refresh the access token on 401 and retry once.
Agents
const agents = await client.agents.list({ status: 'running', limit: 20 });
const agent = await client.agents.create({
vmId: 'vm-123',
name: 'ops-agent',
type: 'ops',
model: 'gpt-4o',
providerId: 'provider-123',
tools: ['tail_logs', 'get_metrics'],
});
const task = await client.agents.dispatch(agent.id, 'Run diagnostics');
Some SDK agent lifecycle methods target endpoints that are implemented by the orchestrator gateway, not the simplified API Gateway stub. Use the gateway that exposes the matching /v1/agents/{id}/stop, /restart, and /dispatch routes.
Tasks
const tasks = await client.tasks.list({ agentId: agent.id, limit: 10 });
const detail = await client.tasks.get(task.id);
client.tasks.stream(task.id, {
onMessage(event) {
console.log(event);
},
});
Billing, VMs, Incidents, Secrets, Events
The top-level client exposes resource clients for the main platform domains:
await client.billing.getUsageSummary();
await client.vms.list();
await client.incidents.list();
await client.secrets.list();
client.events.connect();
client.events.subscribe({ type: 'agent.heartbeat' }, (event) => {
console.log(event);
});
Intelligent MCP Routing
const plan = await client.mcpRouter.plan({
input: 'Run QAOA for this graph',
tenantId: 'tenant-123',
});
if (plan.requiresApproval) {
console.log(plan.explanation);
}
const result = await client.mcpRouter.ask({
input: 'Run QAOA for this graph',
preferredMcp: 'qcos-mcp',
approve: true,
toolName: 'optimize_qaoa',
toolInput: { graph: [[0, 1], [1, 2]], p: 2, shots: 1024 },
});
Use client.mcpRouter.route() for selection only, plan() for explainable previews, ask() for plan-or-execute behavior, and execute() when the caller has already collected structured inputs and approval.
Error Handling
Non-2xx responses throw ApiError.
import { ApiError } from '@synapsex/sdk';
try {
await client.agents.get('missing');
} catch (error) {
if (error instanceof ApiError) {
console.error(error.status, error.body);
}
}