Skip to content

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

billing: avoid recording preview credits in ledgers; update test descriptions for zero-credit research endpoints

David Tippettdc2ea5933f8a
diff --git a/apps/api/src/__tests__/snips/v2/research.test.ts b/apps/api/src/__tests__/snips/v2/research.test.ts
index a5ad6a77e..95d0a6e0d 100644
--- a/apps/api/src/__tests__/snips/v2/research.test.ts
+++ b/apps/api/src/__tests__/snips/v2/research.test.ts
@@ -173,7 +173,7 @@ describeIf(HAS_RESEARCH)("Research API", () => {
});
describeIf(TEST_PRODUCTION)("research billing", () => {
- it("bills read-paper as one scrape-like credit", async () => {
+ it("research read-paper remains zero-credit", async () => {
const identity = await idmux({
name: "research/bills read paper",
credits: 100,
@@ -193,7 +193,7 @@ describeIf(HAS_RESEARCH)("Research API", () => {
expect(before - after).toBe(0);
}, 180000);
- it("bills search-like endpoints by returned result count", async () => {
+ it("research search-like endpoints remain zero-credit", async () => {
const identity = await idmux({
name: "research/bills search papers",
credits: 100,
diff --git a/apps/api/src/controllers/v2/search.ts b/apps/api/src/controllers/v2/search.ts
index 814d356d4..47dfb6fe8 100644
--- a/apps/api/src/controllers/v2/search.ts
+++ b/apps/api/src/controllers/v2/search.ts
@@ -301,7 +301,9 @@ export async function searchController(
time_taken: timeTakenInSeconds,
team_id: req.auth.team_id,
options: req.body,
- credits_cost: shouldBill ? result.searchCredits : 0,
+ // Don't record preview tokens as billed in the ledger — only record
+ // credits when billing is actually applied.
+ credits_cost: !isSearchPreview && shouldBill ? result.searchCredits : 0,
zeroDataRetention,
},
false,
@@ -324,7 +326,9 @@ export async function searchController(
response: null,
num_results: result.response.developer?.length ?? 0,
time_taken: timeTakenInSeconds,
- credits_cost: shouldBill ? result.searchCredits : 0,
+ // Ensure preview-mode searches don't get a non-zero credits_cost
+ // in the research ledger when preview tokens are used.
+ credits_cost: !isSearchPreview && shouldBill ? result.searchCredits : 0,
is_successful: true,
zeroDataRetention,
}).catch(ledgerError => {