Skip to content

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

Update /search endpoint pricing to 2 credits per 10 search results (#2299)

devin-ai-integration[bot]8224bb1a01f5
diff --git a/apps/api/src/controllers/v1/search.ts b/apps/api/src/controllers/v1/search.ts
index b4daccab5..04ad37556 100644
--- a/apps/api/src/controllers/v1/search.ts
+++ b/apps/api/src/controllers/v1/search.ts
@@ -225,7 +225,8 @@ export async function searchController(
res: Response<SearchResponse>,
) {
// Get timing data from middleware (includes all middleware processing time)
- const middlewareStartTime = (req as any).requestTiming?.startTime || new Date().getTime();
+ const middlewareStartTime =
+ (req as any).requestTiming?.startTime || new Date().getTime();
const controllerStartTime = new Date().getTime();
const jobId = uuidv4();
@@ -313,7 +314,7 @@ export async function searchController(
title: r.title,
description: r.description,
})) as Document[];
- credits_billed = responseData.data.length;
+ credits_billed = Math.ceil((responseData.data.length * 2) / 10);
} else {
logger.info("Scraping search results");
const scrapePromises = searchResults.map(result =>
@@ -452,7 +453,10 @@ export async function searchController(
// Log final timing information
const totalRequestTime = new Date().getTime() - middlewareStartTime;
const controllerTime = new Date().getTime() - controllerStartTime;
- const scrapeful = !!(req.body.scrapeOptions.formats && req.body.scrapeOptions.formats.length > 0);
+ const scrapeful = !!(
+ req.body.scrapeOptions.formats &&
+ req.body.scrapeOptions.formats.length > 0
+ );
logger.info("Request metrics", {
version: "v1",
mode: "search",
@@ -477,9 +481,9 @@ export async function searchController(
}
Sentry.captureException(error);
- logger.error("Unhandled error occurred in search", {
+ logger.error("Unhandled error occurred in search", {
version: "v1",
- error
+ error,
});
return res.status(500).json({
success: false,
diff --git a/apps/api/src/controllers/v2/search.ts b/apps/api/src/controllers/v2/search.ts
index 7893338fd..28f83ba3a 100644
--- a/apps/api/src/controllers/v2/search.ts
+++ b/apps/api/src/controllers/v2/search.ts
@@ -321,8 +321,8 @@ export async function searchController(
const isAsyncScraping = req.body.asyncScraping && shouldScrape;
if (!shouldScrape) {
- // No scraping - just count results for billing
- credits_billed = totalResultsCount;
+ // No scraping - 2 credits per 10 search results (0.2 credits per result)
+ credits_billed = Math.ceil((totalResultsCount * 2) / 10);
} else {
// Common setup for both async and sync scraping
logger.info(