add rate-limiting

This commit is contained in:
ramnique 2025-02-04 16:35:12 +05:30
parent 024f6c75cc
commit 200e8d2e38
9 changed files with 188 additions and 2 deletions

View file

@ -5,6 +5,7 @@ import { ObjectId } from "mongodb";
import { authCheck } from "@/app/api/v1/utils";
import { convertFromApiToAgenticApiMessages, convertFromAgenticApiToApiMessages, AgenticAPIChatRequest, ApiRequest, ApiResponse, convertWorkflowToAgenticAPI } from "@/app/lib/types";
import { getAgenticApiResponse } from "@/app/lib/utils";
import { check_query_limit } from "@/app/lib/rate_limiting";
// get next turn / agent response
export async function POST(
@ -13,6 +14,11 @@ export async function POST(
): Promise<Response> {
const { projectId } = await params;
// check query limit
if (!await check_query_limit(projectId)) {
return Response.json({ error: "Query limit exceeded" }, { status: 429 });
}
return await authCheck(projectId, req, async () => {
// parse and validate the request body
let body;