Skip to content

Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥

fix(v1/checkCredits): snap crawl limit to remaining credits if over without erroring out (#1350)

Gergő Móricz670ca84ae922
diff --git a/apps/api/src/routes/v1.ts b/apps/api/src/routes/v1.ts
index 4fee4a1ea..f6a463818 100644
--- a/apps/api/src/routes/v1.ts
+++ b/apps/api/src/routes/v1.ts
@@ -52,7 +52,18 @@ function checkCreditsMiddleware(
if (chunk) {
req.acuc = chunk;
}
+ req.account = { remainingCredits };
if (!success) {
+ if (!minimum && req.body && (req.body as any).limit !== undefined && remainingCredits > 0) {
+ logger.warn("Adjusting limit to remaining credits", {
+ teamId: req.auth.team_id,
+ remainingCredits,
+ request: req.body,
+ });
+ (req.body as any).limit = remainingCredits;
+ return next();
+ }
+
const currencyName = req.acuc.is_extract ? "tokens" : "credits"
logger.error(
`Insufficient ${currencyName}: ${JSON.stringify({ team_id: req.auth.team_id, minimum, remainingCredits })}`,
@@ -72,7 +83,6 @@ function checkCreditsMiddleware(
});
}
}
- req.account = { remainingCredits };
next();
})().catch((err) => next(err));
};