Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥
TypeScript aiai-agentsai-crawlerai-scrapingai-searchcrawlerdata-extractionhtml-to-markdownllmmarkdownscraperscrapingweb-crawlerweb-dataweb-data-extractionweb-scraperweb-scrapingweb-searchwebscraping
feat(api/billing): bill deterministic json at 10 credits on codegen, 3 on cached script (#3750)
tomsideguide6b7c5e9cf27c
diff --git a/apps/api/src/lib/scrape-billing.test.ts b/apps/api/src/lib/scrape-billing.test.tsindex 9f4c72cb2..70361b069 100644--- a/apps/api/src/lib/scrape-billing.test.ts+++ b/apps/api/src/lib/scrape-billing.test.ts@@ -24,4 +24,66 @@ describe("calculateCreditsToBeBilled", () => {expect(credits).toBe(30);});++ it("bills deterministic JSON at 10 credits when the script was generated", async () => {+ const credits = await calculateCreditsToBeBilled(+ {+ formats: [{ type: "deterministicJson", schema: {} }],+ } as any,+ {+ teamId: "team-id",+ },+ {+ metadata: {+ statusCode: 200,+ proxyUsed: "basic",+ },+ } as any,+ {+ totalCost: 0.01,+ calls: [+ {+ type: "other",+ model: "vertex/gemini",+ cost: 0.01,+ metadata: { module: "deterministic-json", role: "codegen" },+ },+ ],+ } as any,+ {} as any,+ );++ expect(credits).toBe(10);+ });++ it("bills deterministic JSON at 3 credits when a cached script was reused", async () => {+ const credits = await calculateCreditsToBeBilled(+ {+ formats: [{ type: "deterministicJson", schema: {} }],+ } as any,+ {+ teamId: "team-id",+ },+ {+ metadata: {+ statusCode: 200,+ proxyUsed: "basic",+ },+ } as any,+ {+ totalCost: 0.001,+ calls: [+ {+ type: "other",+ model: "groq/llama",+ cost: 0.001,+ metadata: { module: "deterministic-json", role: "askLlm" },+ },+ ],+ } as any,+ {} as any,+ );++ expect(credits).toBe(3);+ });});diff --git a/apps/api/src/lib/scrape-billing.ts b/apps/api/src/lib/scrape-billing.tsindex 3efa05045..2de00540a 100644--- a/apps/api/src/lib/scrape-billing.ts+++ b/apps/api/src/lib/scrape-billing.ts@@ -73,7 +73,14 @@ export async function calculateCreditsToBeBilled(}if (hasFormatOfType(options.formats, "deterministicJson")) {- creditsToBeBilled = 7;+ // 10 when this run generated the extractor script, 3 when it reused a+ // cached one. The codegen call is tagged in deterministicJson/llm/client.ts.+ const generatedScript = costTrackingJSON.calls?.some(+ call =>+ call.metadata?.module === "deterministic-json" &&+ call.metadata?.role === "codegen",+ );+ creditsToBeBilled = generatedScript ? 10 : 3;}if (