Skip to content

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

feat(billing): merge credits and tokens (#2352)

Gergő Móricz168fc6db07a0
diff --git a/apps/api/src/__tests__/snips/v1/billing.test.ts b/apps/api/src/__tests__/snips/v1/billing.test.ts
index c45e96e56..325af196c 100644
--- a/apps/api/src/__tests__/snips/v1/billing.test.ts
+++ b/apps/api/src/__tests__/snips/v1/billing.test.ts
@@ -382,7 +382,7 @@ describeIf(TEST_PRODUCTION)("Billing tests", () => {
const rc2 = (await tokenUsage(identity)).remaining_tokens;
- expect(rc1 - rc2).toBe(305);
+ expect(rc1 - rc2).toBe(315); // rounded to closest 15 due to internal logic
},
300000,
);
diff --git a/apps/api/src/controllers/auth.ts b/apps/api/src/controllers/auth.ts
index 598a85682..fdbfd086c 100644
--- a/apps/api/src/controllers/auth.ts
+++ b/apps/api/src/controllers/auth.ts
@@ -190,7 +190,7 @@ export async function getACUC(
const client =
Math.random() > 2 / 3 ? supabase_rr_service : supabase_service;
({ data, error } = await client.rpc(
- "auth_credit_usage_chunk_35",
+ "auth_credit_usage_chunk_36",
{
input_key: api_key,
i_is_extract: isExtract,
@@ -317,7 +317,7 @@ export async function getACUCTeam(
const client =
Math.random() > 2 / 3 ? supabase_rr_service : supabase_service;
({ data, error } = await client.rpc(
- "auth_credit_usage_chunk_35_from_team",
+ "auth_credit_usage_chunk_36_from_team",
{
input_team: team_id,
i_is_extract: isExtract,
diff --git a/apps/api/src/services/billing/batch_billing.ts b/apps/api/src/services/billing/batch_billing.ts
index 8e675129b..560fbfb08 100644
--- a/apps/api/src/services/billing/batch_billing.ts
+++ b/apps/api/src/services/billing/batch_billing.ts
@@ -304,7 +304,7 @@ async function supaBillTeam(
_logger.info(`Batch billing team ${team_id} for ${credits} credits`);
// Perform the actual database operation
- const { data, error } = await supabase_service.rpc("bill_team_5", {
+ const { data, error } = await supabase_service.rpc("bill_team_6", {
_team_id: team_id,
sub_id: subscription_id ?? null,
fetch_subscription: subscription_id === undefined,