MCPcopy Create free account
hub / github.com/Superflows-AI/superflows / getFreeTierUsage

Function getFreeTierUsage

lib/edge-runtime/utils.ts:138–153  ·  view source on GitHub ↗
(
  supabase: SupabaseClient<Database>,
  orgId: number,
)

Source from the content-addressed store, hash-verified

136}
137
138export async function getFreeTierUsage(
139 supabase: SupabaseClient<Database>,
140 orgId: number,
141): Promise<{ overLimit: boolean; numQueriesMade: number }> {
142 // The number of first messages sent by the organization's users
143 // This count is just for free tier users. All messages should count to avoid spam.
144 // For paying customers, we only count full AI responses against their usage (see below).
145 const usageRes = await supabase
146 .from("chat_messages")
147 .select("*", { count: "exact" })
148 .eq("org_id", orgId)
149 .eq("role", "user");
150 if (usageRes.error) throw new Error(usageRes.error.message);
151 let numQueriesMade = usageRes.count ?? 0;
152 return { overLimit: numQueriesMade >= USAGE_LIMIT, numQueriesMade };
153}
154
155export function getHost(req: NextRequest) {
156 // fallback is safe according to nextjs

Callers 3

PlaygroundFunction · 0.90
handlerFunction · 0.90
handlerFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected