Skip to main content

Headless frontend client

Install @dataira/client when your frontend framework or design system should own the entire interface.

npm install @dataira/client
import { DatairaClient } from "@dataira/client";

const client = new DatairaClient({
baseUrl: "https://api.dataira.ai",
getToken: async () => {
const response = await fetch("/api/dataira-token", { method: "POST" });
return (await response.json()).token;
},
});

const conversations = await client.listConversations();
const metrics = await client.listMetrics();
const dashboards = await client.listDashboards();

Organize end-user resources

Collections can contain conversations, saved metrics, and dashboards. A resource can belong to zero or many Collections. Stars and pins are independent preferences and do not change Collection membership.

const collection = await client.collections.create("Quarterly review");
await client.collections.addItem(collection.id, "metric", metrics[0].id);
await client.collections.star("metric", metrics[0].id);
await client.collections.pin("dashboard", dashboards[0].id);

Every call inherits the Project, Environment, end-user, datasource, and row scope from the short-lived token. A caller cannot pass a different end-user ID to escape that scope.

Save and compose analytics

const saved = await client.saveMetric({
title: "Monthly revenue",
questionText: "Revenue by month",
chart: { type: "bar", data: [] },
});

const dashboard = await client.createDashboard({ name: "Executive overview" });
await client.addWidget(dashboard.id, saved.id);

Use dashboardLayout and updateDashboardLayout to persist drag/resize geometry. Use chatSession(existingConversationId) to continue a thread.