Large experiments fail to download in UI
Last updated: February 22, 2026
This issue is applicable to customers matching these conditions
Plans: Any
Deployments: Any
Use case: Experiments with a large amount of rows
Issue
While attempting to download an Experiment as a CSV or JSON file, you notice the malloc of size <number> failed in the UI and the download fails.
Cause
The UI attempts to load the entire dataset into memory at once, causing memory allocation failures for experiments with thousands of records.
Resolution
Run the below script to download the Experiment rows in batches with the API.
Note: This will save a file named experiment_data.csv in the same directory that you run the script in.
import { writeFile } from "fs/promises";
const API_URL = "https://api.braintrust.dev";
const EXPERIMENT_ID = "your-experiment-id";
const API_KEY = "your-api-key";
interface FetchResponse {
events: any[];
cursor?: string;
}
async function* fetchExperimentWithPagination(experimentId: string, limit = 200) {
const headers = {
Authorization: `Bearer ${API_KEY}`,
};
let cursor: string | undefined = undefined;
while (true) {
const url = new URL(`${API_URL}/v1/experiment/${experimentId}/fetch`);
url.searchParams.set("limit", limit.toString());
if (cursor) {
url.searchParams.set("cursor", cursor);
}
const response = await fetch(url.toString(), { headers });
const data: FetchResponse = await response.json();
if (!data.events || data.events.length === 0) {
break;
}
for (const event of data.events) {
yield event;
}
// Get cursor from response body
cursor = data.cursor;
if (!cursor) {
break;
}
}
}
function convertToCSV(events: any[]): string {
if (events.length === 0) return "";
// Get all unique keys from all events
const keys = Array.from(
new Set(events.flatMap((event) => Object.keys(event)))
);
// Create header row
const header = keys.join(",");
// Create data rows
const rows = events.map((event) =>
keys
.map((key) => {
const value = event[key];
// Handle values that might contain commas, quotes, or newlines
if (value === null || value === undefined) return "";
const stringValue = typeof value === "object" ? JSON.stringify(value) : String(value);
// Escape quotes and wrap in quotes if contains comma, quote, or newline
if (stringValue.includes(",") || stringValue.includes('"') || stringValue.includes("\n")) {
return `"${stringValue.replace(/"/g, '""')}"`;
}
return stringValue;
})
.join(",")
);
return [header, ...rows].join("\n");
}
// Usage
async function main() {
const events = [];
for await (const event of fetchExperimentWithPagination(EXPERIMENT_ID, 500)) {
events.push(event);
}
const csv = convertToCSV(events);
await writeFile("experiment_data.csv", csv);
console.log(`Wrote ${events.length} events to experiment_data.csv`);
}
main();