Skip to content

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

feat(search): bill for PDFs properly

Gergő Móricza8e0482718c6
diff --git a/apps/api/src/controllers/v1/search.ts b/apps/api/src/controllers/v1/search.ts
index c9c9bf3c4..8a34c4386 100644
--- a/apps/api/src/controllers/v1/search.ts
+++ b/apps/api/src/controllers/v1/search.ts
@@ -255,7 +255,13 @@ export async function searchController(
}
// Bill team once for all successful results
- billTeam(req.auth.team_id, req.acuc?.sub_id, responseData.data.length).catch((error) => {
+ billTeam(req.auth.team_id, req.acuc?.sub_id, responseData.data.reduce((a,x) => {
+ if (x.metadata?.numPages !== undefined && x.metadata.numPages > 0) {
+ return a + x.metadata.numPages;
+ } else {
+ return a + 1;
+ }
+ }, 0)).catch((error) => {
logger.error(
`Failed to bill team ${req.auth.team_id} for ${responseData.data.length} credits: ${error}`,
);