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

@ -6,6 +6,7 @@ import { ObjectId, WithId } from "mongodb";
import { authCheck } from "../../../utils";
import { AgenticAPIChatRequest, convertFromAgenticAPIChatMessages, convertToAgenticAPIChatMessages, convertWorkflowToAgenticAPI } from "@/app/lib/types";
import { callClientToolWebhook, getAgenticApiResponse } from "@/app/lib/utils";
import { check_query_limit } from "@/app/lib/rate_limiting";
const chatsCollection = db.collection<z.infer<typeof apiV1.Chat>>("chats");
const chatMessagesCollection = db.collection<z.infer<typeof apiV1.ChatMessage>>("chatMessages");
@ -18,6 +19,11 @@ export async function POST(
return await authCheck(req, async (session) => {
const { chatId } = await params;
// check query limit
if (!await check_query_limit(session.projectId)) {
return Response.json({ error: "Query limit exceeded" }, { status: 429 });
}
// parse and validate the request body
let body;
try {