Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Helicone Helicone ExportDashboardData

From Leeroopedia
Knowledge Sources
Domains Analytics, Export
Last Updated 2026-02-14 06:32 GMT

Overview

Dashboard data export functionality that converts Helicone analytics metrics and time-series data into a multi-sheet Excel workbook for offline analysis.

Description

exportDashboardData.ts provides the exportDashboardToExcel function along with supporting type definitions for structuring dashboard export data. It uses the xlsx (SheetJS) library to create structured Excel workbooks with up to 12 separate sheets.

Type Definitions:

The file defines several time-series data interfaces:

  • CostOverTime -- Cost values indexed by time
  • ErrorOverTime -- Error counts indexed by time
  • TokensOverTime -- Prompt and completion token counts over time
  • LatencyOverTime -- Duration measurements over time
  • ThreatsOverTime -- Threat detection counts over time
  • TimeToFirstToken -- TTFT measurements over time
  • UsersOverTime -- Active user counts over time
  • TokensPerRequest -- Average token metrics per request

The DashboardExportData interface aggregates:

  • metrics -- Summary statistics (totalCost, totalRequests, averageLatency, averageTokensPerRequest, activeUsers, averageTimeToFirstToken, totalThreats)
  • overTimeData -- Time-series arrays for requests, costs, latency, users, TTFT, threats, errors, and tokens
  • models -- Model usage breakdown with requests, tokens, and cost per model
  • providers -- Provider usage breakdown with total requests per provider

Excel Workbook Generation:

The exportDashboardToExcel function creates a workbook with the following sheets (each conditionally included when data is available):

  1. Summary -- Key metrics (total cost, total requests, average latency, token averages, active users, TTFT, threats) plus the time range
  2. Requests -- Request counts over time
  3. Requests by Status -- Request counts with HTTP status codes over time
  4. Costs -- Cost values over time
  5. Latency -- Latency duration over time
  6. Users -- Active user counts over time
  7. Time to First Token -- TTFT measurements over time
  8. Threats -- Threat counts over time
  9. Errors -- Error counts over time
  10. Tokens -- Prompt, completion, and total tokens over time
  11. Top Models -- Model breakdown with requests, tokens, and cost
  12. Top Providers -- Provider breakdown with request counts

Each sheet has auto-sized column widths for readability.

Usage

Use this function when the user wants to download their dashboard analytics as an Excel file. The function is typically triggered by an export button in the dashboard UI and produces a downloadable Blob.

Code Reference

Source Location

Signature

export interface DashboardExportData {
  metrics: {
    totalCost: { data: Result<number, string> | undefined };
    totalRequests: { data: Result<number, string> | undefined };
    averageLatency: { data: Result<number, string> | undefined };
    averageTokensPerRequest: { data: Result<TokensPerRequest, string> | undefined };
    activeUsers: { data: Result<number, string> | undefined };
    averageTimeToFirstToken: { data: Result<number, string> | undefined };
    totalThreats: { data: Result<number, string> | undefined };
  };
  overTimeData: {
    requests: { data: Result<RequestsOverTime[], string> | undefined };
    requestsWithStatus: { data: Result<(RequestsOverTime & { status: number })[], string> | undefined };
    costs: { data: Result<CostOverTime[], string> | undefined };
    latency: { data: Result<LatencyOverTime[], string> | undefined };
    users: { data: Result<UsersOverTime[], string> | undefined };
    timeToFirstToken: { data: Result<TimeToFirstToken[], string> | undefined };
    threats: { data: Result<ThreatsOverTime[], string> | undefined };
    errors: { data: Result<ErrorOverTime[], string> | undefined };
    promptTokensOverTime: { data: Result<TokensOverTime[], string> | undefined };
  };
  models: Result<Array<{ model: string; total_requests: number; cost: number; ... }>, unknown>;
  providers: Result<Array<{ provider: string; total_requests: number }>, unknown>;
}

export async function exportDashboardToExcel(
  data: DashboardExportData,
  timeFilter: { start: Date; end: Date },
): Promise<Blob>;

Import

import {
  exportDashboardToExcel,
  DashboardExportData,
} from "@/lib/exportDashboardData";

I/O Contract

Inputs

Name Type Required Description
data DashboardExportData Yes Complete dashboard analytics data including metrics, time-series, models, and providers
timeFilter.start Date Yes Start of the time range for the exported data
timeFilter.end Date Yes End of the time range for the exported data

Outputs

Name Type Description
(return) Promise<Blob> An Excel file as a Blob with MIME type application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

Excel Sheet Structure

Sheet Name Columns Source Data
Summary metric, value Aggregate metrics + time range
Requests timestamp, count overTimeData.requests
Requests by Status timestamp, count, status overTimeData.requestsWithStatus
Costs timestamp, cost overTimeData.costs
Latency timestamp, duration_ms overTimeData.latency
Users timestamp, count overTimeData.users
Time to First Token timestamp, ttft_ms overTimeData.timeToFirstToken
Threats timestamp, count overTimeData.threats
Errors timestamp, count overTimeData.errors
Tokens timestamp, prompt_tokens, completion_tokens, total_tokens overTimeData.promptTokensOverTime
Top Models model, total_requests, total_completion_tokens, total_prompt_tokens, total_tokens, cost models
Top Providers provider, total_requests providers

Usage Examples

import { exportDashboardToExcel, DashboardExportData } from "@/lib/exportDashboardData";

// Assuming dashboardData is assembled from TanStack Query hooks
const blob = await exportDashboardToExcel(dashboardData, {
  start: new Date("2024-01-01"),
  end: new Date("2024-01-31"),
});

// Trigger browser download
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = "helicone-dashboard-export.xlsx";
a.click();
URL.revokeObjectURL(url);

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment