Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

chore: rate limit legacy endpoints (#3473)

Max Deichmann5ba440f2de36
diff --git a/packages/shared/src/interfaces/rate-limits.ts b/packages/shared/src/interfaces/rate-limits.ts
index 866487851b..840842e6f8 100644
--- a/packages/shared/src/interfaces/rate-limits.ts
+++ b/packages/shared/src/interfaces/rate-limits.ts
@@ -6,6 +6,7 @@ export const RateLimitResource = z.enum([
"public-api",
"public-api-metrics",
"prompts",
+ "legacy-ingestion",
]);
// result of the rate limit check.
diff --git a/web/src/features/public-api/server/RateLimitService.ts b/web/src/features/public-api/server/RateLimitService.ts
index 47b4631d36..efca91c7be 100644
--- a/web/src/features/public-api/server/RateLimitService.ts
+++ b/web/src/features/public-api/server/RateLimitService.ts
@@ -185,16 +185,38 @@ const getPlanBasedRateLimitConfig = (
switch (plan) {
case "oss":
case "self-hosted:enterprise":
- return { resource, points: null, durationInSec: null };
+ return {
+ resource,
+ points: null,
+ durationInSec: null,
+ };
case "cloud:hobby":
case "cloud:pro":
switch (resource) {
case "ingestion":
- return { resource: "ingestion", points: 1000, durationInSec: 60 };
+ return {
+ resource: "ingestion",
+ points: 1000,
+ durationInSec: 60,
+ };
+ case "legacy-ingestion":
+ return {
+ resource: "prompts",
+ points: 400,
+ durationInSec: 60,
+ };
case "prompts":
- return { resource: "prompts", points: null, durationInSec: null };
+ return {
+ resource: "prompts",
+ points: null,
+ durationInSec: null,
+ };
case "public-api":
- return { resource: "public-api", points: 1000, durationInSec: 60 };
+ return {
+ resource: "public-api",
+ points: 1000,
+ durationInSec: 60,
+ };
case "public-api-metrics":
return {
resource: "public-api-metrics",
@@ -208,11 +230,29 @@ const getPlanBasedRateLimitConfig = (
case "cloud:team":
switch (resource) {
case "ingestion":
- return { resource: "ingestion", points: 5000, durationInSec: 60 };
+ return {
+ resource: "ingestion",
+ points: 5000,
+ durationInSec: 60,
+ };
+ case "legacy-ingestion":
+ return {
+ resource: "prompts",
+ points: 400,
+ durationInSec: 60,
+ };
case "prompts":
- return { resource: "prompts", points: null, durationInSec: null };
+ return {
+ resource: "prompts",
+ points: null,
+ durationInSec: null,
+ };
case "public-api":
- return { resource: "public-api", points: 1000, durationInSec: 60 };
+ return {
+ resource: "public-api",
+ points: 1000,
+ durationInSec: 60,
+ };
case "public-api-metrics":
return {
resource: "public-api-metrics",
diff --git a/web/src/pages/api/public/generations.ts b/web/src/pages/api/public/generations.ts
index cd2563ebab..fdbbb03048 100644
--- a/web/src/pages/api/public/generations.ts
+++ b/web/src/pages/api/public/generations.ts
@@ -17,6 +17,7 @@ export default withMiddlewares({
name: "Create Generation (Legacy)",
bodySchema: PostGenerationsV1Body,
responseSchema: PostGenerationsV1Response,
+ rateLimitResource: "legacy-ingestion",
fn: async ({ body, auth }) => {
const ingestionBatch = transformGenerationPostToIngestionBatch(body);
const result = await handleBatch(ingestionBatch, auth, tokenCount);
@@ -32,6 +33,7 @@ export default withMiddlewares({
name: "Patch Generation (Legacy)",
bodySchema: PatchGenerationsV1Body,
responseSchema: PatchGenerationsV1Response,
+ rateLimitResource: "legacy-ingestion",
fn: async ({ body, auth }) => {
const ingestionBatch = transformGenerationPatchToIngestionBatch(body);
const result = await handleBatch(ingestionBatch, auth, tokenCount);
diff --git a/web/src/pages/api/public/traces/index.ts b/web/src/pages/api/public/traces/index.ts
index 05b3f1277f..d9add9bd24 100644
--- a/web/src/pages/api/public/traces/index.ts
+++ b/web/src/pages/api/public/traces/index.ts
@@ -23,9 +23,10 @@ import { tokenCount } from "@/src/features/ingest/usage";
export default withMiddlewares({
POST: createAuthedAPIRoute({
- name: "Create Trace",
+ name: "Create Trace (Legacy)",
bodySchema: PostTracesV1Body,
responseSchema: PostTracesV1Response, // Adjust this if you have a specific response schema
+ rateLimitResource: "legacy-ingestion",
fn: async ({ body, auth }) => {
await telemetry();