Skip to content

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

chore(api): reduce legacy public API rate limits (#17572)

Max Deichmann593677cd4de5
diff --git a/web/src/__tests__/server/observation-api.servertest.ts b/web/src/__tests__/server/observation-api.servertest.ts
index 46d51ef4ff..3cb27f5e08 100644
--- a/web/src/__tests__/server/observation-api.servertest.ts
+++ b/web/src/__tests__/server/observation-api.servertest.ts
@@ -19,8 +19,6 @@ import { v4 as uuidv4 } from "uuid";
import snakeCase from "lodash/snakeCase";
import { env } from "@/src/env.mjs";
-const projectId = "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a";
-
// Helper type for observation data
type ObservationData = {
id: string;
@@ -81,6 +79,17 @@ const insertObservations = async (
};
describe("/api/public/observations API Endpoint", () => {
+ let projectId: string;
+ let auth: string;
+
+ // A fresh org per test keeps each test far below the per-minute legacy
+ // public API quota, which the whole file would exceed on a shared org.
+ beforeEach(async () => {
+ const fixture = await createOrgProjectAndApiKey();
+ projectId = fixture.projectId;
+ auth = fixture.auth;
+ });
+
it("clamps Hobby observation access to the last 30 days", async () => {
const fixture = await createOrgProjectAndApiKey({ plan: "Hobby" });
const oldId = uuidv4();
@@ -149,6 +158,8 @@ describe("/api/public/observations API Endpoint", () => {
GetObservationV1Response,
"GET",
`/api/public/observations/${observationId}?useEventsTable=${useEventsTable}`,
+ undefined,
+ auth,
);
const expectedModelId = (() => {
@@ -196,6 +207,8 @@ describe("/api/public/observations API Endpoint", () => {
GetObservationV1Response,
"GET",
`/api/public/observations/${observationId}?startTime=2024-03-15T08:30:00.000Z&useEventsTable=${useEventsTable}`,
+ undefined,
+ auth,
);
expect(getEventRes.body).toMatchObject({
@@ -229,6 +242,8 @@ describe("/api/public/observations API Endpoint", () => {
GetObservationV1Response,
"GET",
`/api/public/observations/${observationId}?startTime=2024-03-16T00:00:00.000Z&useEventsTable=${useEventsTable}`,
+ undefined,
+ auth,
);
expect(getEventRes.body).toMatchObject({
@@ -242,6 +257,8 @@ describe("/api/public/observations API Endpoint", () => {
const res = await makeAPICall(
"GET",
`/api/public/observations/${uuidv4()}?startTime=2024-03-15T08:30:00&useEventsTable=${useEventsTable}`,
+ undefined,
+ auth,
);
expect(res.status).toBe(400);
@@ -273,6 +290,8 @@ describe("/api/public/observations API Endpoint", () => {
GetObservationV1Response,
"GET",
`/api/public/observations/${observationId}?useEventsTable=${useEventsTable}`,
+ undefined,
+ auth,
);
expect(getEventRes.body).toMatchObject({
id: observationId,
@@ -291,7 +310,7 @@ describe("/api/public/observations API Endpoint", () => {
const observation = createObservationData(useEventsTable, {
id: observationId,
trace_id: traceId,
- project_id: "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a",
+ project_id: projectId,
model_id: "clrkwk4cb000408l576jl7koo",
provided_model_name: "gpt-3.5-turbo",
input: JSON.stringify({ key: "input" }),
@@ -312,6 +331,7 @@ describe("/api/public/observations API Endpoint", () => {
"GET",
`/api/public/observations?traceId=${traceId}${queryParam}`,
undefined,
+ auth,
);
expect(fetchedObservations.status).toBe(200);
@@ -349,7 +369,7 @@ describe("/api/public/observations API Endpoint", () => {
const generationObservation = createObservationData(useEventsTable, {
id: generationId,
trace_id: traceId,
- project_id: "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a",
+ project_id: projectId,
model_id: "model-1",
provided_model_name: "gpt-3.5-turbo",
input: JSON.stringify({ key: "input" }),
@@ -366,7 +386,7 @@ describe("/api/public/observations API Endpoint", () => {
const spanObservation = createObservationData(useEventsTable, {
id: spanId,
trace_id: traceId,
- project_id: "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a",
+ project_id: projectId,
input: JSON.stringify({ key: "input" }),
output: JSON.stringify({ key: "output" }),
version: "2.0.0",
@@ -383,6 +403,7 @@ describe("/api/public/observations API Endpoint", () => {
"GET",
`/api/public/observations?type=GENERATION&traceId=${traceId}${queryParam}`,
undefined,
+ auth,
);
expect(fetchedObservations.status).toBe(200);
@@ -415,7 +436,7 @@ describe("/api/public/observations API Endpoint", () => {
const createdTrace = createTrace({
id: traceId,
[snakeCase(prop)]: value,
- project_id: "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a",
+ project_id: projectId,
});
await createTracesCh([createdTrace]);
@@ -426,7 +447,7 @@ describe("/api/public/observations API Endpoint", () => {
trace_id: traceId,
start_time: timestamp * timeMultiplier,
end_time: timestamp * timeMultiplier,
- project_id: "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a",
+ project_id: projectId,
type: "GENERATION",
[snakeCase(prop)]: value,
});
@@ -437,14 +458,14 @@ describe("/api/public/observations API Endpoint", () => {
GetObservationsV1Response,
"GET",
`/api/public/observations?${prop}=${value}${queryParam}`,
+ undefined,
+ auth,
);
expect(observations.body.meta.totalItems).toBe(1);
expect(observations.body.data.length).toBe(1);
const obsResult = observations.body.data[0];
- expect(obsResult.projectId).toBe(
- "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a",
- );
+ expect(obsResult.projectId).toBe(projectId);
if (prop === "userId") return;
expect((obsResult as any)[prop]).toBe(value);
},
@@ -464,7 +485,7 @@ describe("/api/public/observations API Endpoint", () => {
start_time: timestamp1 * timeMultiplier,
event_ts: timestamp1 * timeMultiplier,
end_time: timestamp1 * timeMultiplier,
- project_id: "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a",
+ project_id: projectId,
type: "GENERATION",
});
@@ -475,7 +496,7 @@ describe("/api/public/observations API Endpoint", () => {
start_time: timestamp2 * timeMultiplier,
event_ts: timestamp2 * timeMultiplier,
end_time: timestamp2 * timeMultiplier,
- project_id: "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a",
+ project_id: projectId,
type: "SPAN",
});
@@ -485,7 +506,7 @@ describe("/api/public/observations API Endpoint", () => {
name: "generation-name",
start_time: timestamp3 * timeMultiplier,
event_ts: timestamp3 * timeMultiplier,
- project_id: "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a",
+ project_id: projectId,
type: "EVENT",
});
@@ -496,7 +517,7 @@ describe("/api/public/observations API Endpoint", () => {
start_time: timestamp4 * timeMultiplier,
event_ts: timestamp4 * timeMultiplier,
end_time: timestamp4 * timeMultiplier,
- project_id: "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a",
+ project_id: projectId,
type: "GENERATION",
});
@@ -511,6 +532,7 @@ describe("/api/public/observations API Endpoint", () => {
"GET",
`/api/public/observations?fromStartTime=${fromTimestamp}&toStartTime=${toTimestamp}&traceId=${traceId}${queryParam}`,
undefined,
+ auth,
);
expect(fetchedObservations.body.data.length).toBe(2);
@@ -528,6 +550,7 @@ describe("/api/public/observations API Endpoint", () => {
"GET",
`/api/public/observations?fromStartTime=${fromTimestamp}&traceId=${traceId}${queryParam}`,
undefined,
+ auth,
);
expect(fetchedObservations.body.data.length).toBe(3);
@@ -548,6 +571,7 @@ describe("/api/public/observations API Endpoint", () => {
"GET",
`/api/public/observations?toStartTime=${toTimestamp}&traceId=${traceId}${queryParam}`,
undefined,
+ auth,
);
expect(fetchedObservations.body.data.length).toBe(3);
@@ -568,6 +592,7 @@ describe("/api/public/observations API Endpoint", () => {
"GET",
`/api/public/observations?limit=1&page=2&traceId=${traceId}${queryParam}`,
undefined,
+ auth,
);
expect(fetchedObservations.body.data.length).toBe(1);
diff --git a/web/src/__tests__/server/rate-limit.servertest.ts b/web/src/__tests__/server/rate-limit.servertest.ts
index 61e1d1ed01..7fa34281f4 100644
--- a/web/src/__tests__/server/rate-limit.servertest.ts
+++ b/web/src/__tests__/server/rate-limit.servertest.ts
@@ -422,11 +422,11 @@ describe("RateLimitService", () => {
it("should apply public-api-legacy rate limits by cloud plan", async () => {
const cases = [
- { plan: "cloud:hobby" as const, points: 15 },
- { plan: "cloud:core" as const, points: 30 },
- { plan: "cloud:pro" as const, points: 100 },
- { plan: "cloud:team" as const, points: 100 },
- { plan: "cloud:enterprise" as const, points: 100 },
+ { plan: "cloud:hobby" as const, points: 5 },
+ { plan: "cloud:core" as const, points: 15 },
+ { plan: "cloud:pro" as const, points: 40 },
+ { plan: "cloud:team" as const, points: 40 },
+ { plan: "cloud:enterprise" as const, points: 40 },
];
const rateLimitService = RateLimitService.getInstance(redis as Redis);
diff --git a/web/src/features/public-api/server/RateLimitService.ts b/web/src/features/public-api/server/RateLimitService.ts
index 39c4863d39..58931f7185 100644
--- a/web/src/features/public-api/server/RateLimitService.ts
+++ b/web/src/features/public-api/server/RateLimitService.ts
@@ -292,7 +292,7 @@ const getPlanBasedRateLimitConfig = (
case "public-api-legacy":
return {
resource: "public-api-legacy",
- points: 15,
+ points: 5,
durationInSec: 60,
};
case "datasets":
@@ -393,7 +393,7 @@ const getPlanBasedRateLimitConfig = (
case "public-api-legacy":
return {
resource: "public-api-legacy",
- points: 30,
+ points: 15,
durationInSec: 60,
};
case "datasets":
@@ -494,7 +494,7 @@ const getPlanBasedRateLimitConfig = (
case "public-api-legacy":
return {
resource: "public-api-legacy",
- points: 100,
+ points: 40,
durationInSec: 60,
};
case "datasets":