Typescript SDK

Integrate Alephant Analytics into your TypeScript & Node.js applications

View as Markdown

The official Alephant Analytics TypeScript SDK provides access to the Alephant Analytics API from TypeScript and Node.js applications. It allows you to query telemetry, fetch daily usage series, and retrieve real-time summary statistics for FinOps dashboards.

Installation

Install the SDK via npm, yarn, or pnpm:

$npm install @alephantai/logs-collector-analytics

Initialization

Import and initialize the client. The default environment is development (https://analytics-dev.alephant.io). Use the production environment only after the production Analytics service has been deployed.

1import {
2 LogsCollectorAnalyticsClient,
3 LogsCollectorAnalyticsEnvironment,
4} from "@alephantai/logs-collector-analytics";
5
6const client = new LogsCollectorAnalyticsClient({
7 environment: LogsCollectorAnalyticsEnvironment.Development,
8});

Example Usage

Smoke test

Use the public health endpoint to verify that the SDK can reach the Analytics dev service.

1const health = await client.analyticsAtomic.getHealth();
2console.log(health.data.status);

Live 24-hour panel

Retrieve a rolling live-24h dashboard panel. Authenticated SaaS analytics routes accept the Authorization and X-Workspace-Id headers as request fields.

1async function fetchLivePanel() {
2 try {
3 const response = await client.analyticsSaas.getSaasLive24H({
4 limit: 5,
5 Authorization: `Bearer ${process.env.ALEPHANT_API_TOKEN}`,
6 "X-Workspace-Id": process.env.ALEPHANT_WORKSPACE_ID,
7 });
8
9 console.log(response.data);
10 } catch (error) {
11 console.error("Failed to fetch live panel:", error);
12 }
13}

Retrieving usage series

Fetch daily usage metrics over a specified date range.

1async function fetchCostTimeseries() {
2 const response = await client.analyticsSaas.getSaasUsage({
3 dateFrom: "2026-03-01",
4 dateTo: "2026-03-31",
5 Authorization: `Bearer ${process.env.ALEPHANT_API_TOKEN}`,
6 "X-Workspace-Id": process.env.ALEPHANT_WORKSPACE_ID,
7 });
8
9 console.log(response.data);
10}

Error Handling

The SDK throws structured errors for non-2xx API responses, allowing you to gracefully handle authentication, rate limits, or validation errors programmatically.