Implementation:Helicone Helicone ExportDashboardData
| 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 timeErrorOverTime-- Error counts indexed by timeTokensOverTime-- Prompt and completion token counts over timeLatencyOverTime-- Duration measurements over timeThreatsOverTime-- Threat detection counts over timeTimeToFirstToken-- TTFT measurements over timeUsersOverTime-- Active user counts over timeTokensPerRequest-- 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):
- Summary -- Key metrics (total cost, total requests, average latency, token averages, active users, TTFT, threats) plus the time range
- Requests -- Request counts over time
- Requests by Status -- Request counts with HTTP status codes over time
- Costs -- Cost values over time
- Latency -- Latency duration over time
- Users -- Active user counts over time
- Time to First Token -- TTFT measurements over time
- Threats -- Threat counts over time
- Errors -- Error counts over time
- Tokens -- Prompt, completion, and total tokens over time
- Top Models -- Model breakdown with requests, tokens, and cost
- 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
- Repository: Helicone
- File: web/lib/exportDashboardData.ts
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);