Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

fix: show credit balance in billing UI and distinguish credits_exhausted errors

Louis Beaumont79f2913fc9ff
diff --git a/apps/screenpipe-app-tauri/components/settings/billing-section.tsx b/apps/screenpipe-app-tauri/components/settings/billing-section.tsx
index 5b7f66d24..61a9bdc1a 100644
--- a/apps/screenpipe-app-tauri/components/settings/billing-section.tsx
+++ b/apps/screenpipe-app-tauri/components/settings/billing-section.tsx
@@ -13,7 +13,7 @@ import { Skeleton } from "@/components/ui/skeleton";
import { Progress } from "@/components/ui/progress";
import { toast } from "@/components/ui/use-toast";
import { commands } from "@/lib/utils/tauri";
-import { CreditCard, RefreshCw, Loader2, Sparkles, Zap } from "lucide-react";
+import { CreditCard, RefreshCw, Loader2, Sparkles, Zap, Wallet } from "lucide-react";
const BILLING_API = "https://screenpi.pe/api/billing";
const USAGE_API = "https://api.screenpi.pe/v1/usage";
@@ -25,6 +25,7 @@ interface UsageData {
remaining: number;
resets_at: string;
model_access: string[];
+ credits_balance?: number;
}
interface BillingData {
@@ -302,7 +303,10 @@ export function BillingSection() {
<div className="flex items-center justify-between">
<p className="text-xs text-muted-foreground">
{usage?.used_today ?? 0} / {usage?.limit_today ?? 0} queries
- {usageRatio >= 1 && " — limit reached, using paid credits"}
+ {usageRatio >= 1 &&
+ (usage?.credits_balance != null && usage.credits_balance > 0
+ ? ` — using paid credits ($${usage.credits_balance.toFixed(2)} remaining)`
+ : " — no credits remaining")}
</p>
{usage?.resets_at && (
<p className="text-xs text-muted-foreground">
@@ -314,6 +318,32 @@ export function BillingSection() {
)}
</Card>
+ {/* Credit balance */}
+ {usage?.credits_balance != null && (
+ <Card className="p-4">
+ <div className="flex items-center gap-3">
+ <Wallet className="h-4 w-4 text-muted-foreground" />
+ <div className="flex-1">
+ <div className="flex items-center justify-between">
+ <p className="text-sm font-medium text-foreground">
+ Credit balance
+ </p>
+ <p className="text-sm font-semibold text-foreground">
+ ${usage.credits_balance.toFixed(2)}
+ </p>
+ </div>
+ <p className="text-xs text-muted-foreground mt-0.5">
+ {usageRatio >= 1 && usage.credits_balance > 0
+ ? "daily limit reached — queries are using your credit balance"
+ : usageRatio >= 1 && usage.credits_balance <= 0
+ ? "no credits remaining — pipes using cloud AI will fail"
+ : "credits are used after your daily free queries run out"}
+ </p>
+ </div>
+ </div>
+ </Card>
+ )}
+
{/* Payment method */}
{billing?.stripe_customer && (
<Card className="p-4">
diff --git a/apps/screenpipe-app-tauri/components/settings/pipes-section.tsx b/apps/screenpipe-app-tauri/components/settings/pipes-section.tsx
index 7ed739958..6961a9d76 100644
--- a/apps/screenpipe-app-tauri/components/settings/pipes-section.tsx
+++ b/apps/screenpipe-app-tauri/components/settings/pipes-section.tsx
@@ -120,11 +120,12 @@ the pipe.md file MUST start with --- on the very first line (YAML front-matter).
create the pipe.md file, install it, and enable it. here is what the user wants:`;
function parsePipeError(stderr: string): {
- type: "daily_limit" | "rate_limit" | "unknown";
+ type: "daily_limit" | "credits_exhausted" | "rate_limit" | "unknown";
message: string;
used?: number;
limit?: number;
resets_at?: string;
+ credits_remaining?: number;
} {
// stderr format: '429 "{\"error\":...}"\n' — inner quotes are backslash-escaped
const jsonMatch = stderr.match(/\d{3}\s+"(.+)"/s);
@@ -149,8 +150,9 @@ function parsePipeError(stderr: string): {
}
if (parsed.error === "credits_exhausted") {
return {
- type: "daily_limit",
- message: parsed.message || "free credits exhausted",
+ type: "credits_exhausted",
+ message: parsed.message || "no credits remaining — buy more at screenpi.pe",
+ credits_remaining: parsed.credits_remaining ?? 0,
};
}
} catch {}
@@ -854,17 +856,21 @@ export function PipesSection() {
</Card>
) : (
<div className="space-y-2">
- {/* Global daily limit banner — shown once at top */}
+ {/* Global daily limit / credits exhausted banner — shown once at top */}
{(() => {
- const limitError = filteredPipes
+ const errors = filteredPipes
.filter((p) => p.last_success === false && p.last_error)
- .map((p) => parsePipeError(p.last_error!))
- .find((e) => e.type === "daily_limit");
+ .map((p) => parsePipeError(p.last_error!));
+ const limitError = errors.find(
+ (e) => e.type === "credits_exhausted" || e.type === "daily_limit"
+ );
if (!limitError) return null;
return (
<div className="flex items-center gap-2 text-xs px-4 py-2 border rounded-md">
<span className="text-muted-foreground">
- {limitError.message}
+ {limitError.type === "credits_exhausted"
+ ? "no credits remaining — buy more at screenpi.pe"
+ : limitError.message}
{limitError.resets_at && (
<> · resets {new Date(limitError.resets_at).toLocaleTimeString()}</>
)}
@@ -990,10 +996,10 @@ export function PipesSection() {
</div>
)}
- {/* Per-pipe error (skip daily_limit — shown globally above) */}
+ {/* Per-pipe error (skip daily_limit/credits_exhausted — shown globally above) */}
{!isRunning && pipe.last_success === false && pipe.last_error && (() => {
const error = parsePipeError(pipe.last_error);
- if (error.type === "daily_limit") return null;
+ if (error.type === "daily_limit" || error.type === "credits_exhausted") return null;
if (error.type === "rate_limit") {
return (
<p className="mt-2 text-xs text-muted-foreground">{error.message}</p>
diff --git a/packages/ai-gateway/src/index.ts b/packages/ai-gateway/src/index.ts
index 516d8e6e6..ae30e6d86 100644
--- a/packages/ai-gateway/src/index.ts
+++ b/packages/ai-gateway/src/index.ts
@@ -51,7 +51,7 @@ async function handleRequest(request: Request, env: Env, ctx: ExecutionContext):
// Usage status endpoint - returns current usage without incrementing
if (path === '/v1/usage' && request.method === 'GET') {
- const status = await getUsageStatus(env, authResult.deviceId, authResult.tier);
+ const status = await getUsageStatus(env, authResult.deviceId, authResult.tier, authResult.userId);
return addCorsHeaders(createSuccessResponse(status));
}
diff --git a/packages/ai-gateway/src/services/usage-tracker.ts b/packages/ai-gateway/src/services/usage-tracker.ts
index 7cc1379bb..c50a3362a 100644
--- a/packages/ai-gateway/src/services/usage-tracker.ts
+++ b/packages/ai-gateway/src/services/usage-tracker.ts
@@ -307,7 +307,8 @@ export async function trackUsage(
export async function getUsageStatus(
env: Env,
deviceId: string,
- tier: UserTier
+ tier: UserTier,
+ userId?: string
): Promise<UsageStatus> {
const today = getTodayUTC();
const limits = TIER_CONFIG[tier];
@@ -338,6 +339,11 @@ export async function getUsageStatus(
model_access: limits.allowedModels,
};
+ // Fetch credit balance if user is logged in
+ if (userId) {
+ status.credits_balance = await getCreditBalance(env, userId);
+ }
+
// Add upgrade options for non-subscribed users
if (tier === 'anonymous') {
status.upgrade_options = {
diff --git a/packages/ai-gateway/src/types.ts b/packages/ai-gateway/src/types.ts
index a9ea3c845..f5093530d 100644
--- a/packages/ai-gateway/src/types.ts
+++ b/packages/ai-gateway/src/types.ts
@@ -193,6 +193,7 @@ export interface UsageStatus {
remaining: number;
resets_at: string;
model_access: string[];
+ credits_balance?: number;
upgrade_options?: {
login?: { benefit: string };
subscribe?: { benefit: string };