Skip to content

Commit 43a86f7

Browse files
authored
dataset rate limit (#5527)
1 parent fd5f5d8 commit 43a86f7

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

valhalla/jawn/src/managers/dataset/HeliconeDatasetManager.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,17 @@ export class HeliconeDatasetManager extends BaseManager {
4747
);
4848
}
4949

50+
private async getTodayRowCount(): Promise<number> {
51+
const result = await dbExecute<{ count: number }>(
52+
`SELECT COUNT(*)::int as count
53+
FROM helicone_dataset_row
54+
WHERE organization_id = $1
55+
AND created_at >= CURRENT_DATE`,
56+
[this.authParams.organizationId]
57+
);
58+
return result.data?.[0]?.count ?? 0;
59+
}
60+
5061
async getDatasets(params: {
5162
datasetIds?: string[];
5263
}): Promise<Result<HeliconeDataset[], string>> {
@@ -205,6 +216,16 @@ export class HeliconeDatasetManager extends BaseManager {
205216
datasetId: string,
206217
addRequests: string[]
207218
): Promise<Result<null, string>> {
219+
// Rate limit: 1000 rows per day per organization
220+
const todayCount = await this.getTodayRowCount();
221+
if (todayCount + addRequests.length > 1000) {
222+
return err(
223+
`Rate limit exceeded: You can add up to 1000 dataset rows per day. ` +
224+
`Today's usage: ${todayCount}. Requested: ${addRequests.length}. ` +
225+
`Limit resets at midnight UTC.`
226+
);
227+
}
228+
208229
try {
209230
// Build the VALUES part of the query dynamically
210231
const values = addRequests

0 commit comments

Comments
 (0)