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

feat: credits system for AI gateway metering

Louis Beaumontd7e2729b9604
diff --git a/apps/screenpipe-app-tauri/components/settings/pipes-section.tsx b/apps/screenpipe-app-tauri/components/settings/pipes-section.tsx
index b07d008c4..b10825509 100644
--- a/apps/screenpipe-app-tauri/components/settings/pipes-section.tsx
+++ b/apps/screenpipe-app-tauri/components/settings/pipes-section.tsx
@@ -20,6 +20,8 @@ import { Label } from "@/components/ui/label";
import { Badge } from "@/components/ui/badge";
import { homeDir, join } from "@tauri-apps/api/path";
import { revealItemInDir } from "@tauri-apps/plugin-opener";
+import { open as openUrl } from "@tauri-apps/plugin-shell";
+import { useSettings } from "@/lib/hooks/use-settings";
import { openUrl } from "@tauri-apps/plugin-opener";
function parsePipeError(stderr: string): {
@@ -89,6 +91,7 @@ export function PipesSection() {
const [logs, setLogs] = useState<PipeRunLog[]>([]);
const [loading, setLoading] = useState(true);
const [runningPipe, setRunningPipe] = useState<string | null>(null);
+ const { settings } = useSettings();
const fetchPipes = useCallback(async () => {
try {
@@ -188,7 +191,24 @@ export function PipesSection() {
</a>
</p>
</div>
- <div className="flex gap-2">
+ <div className="flex items-center gap-2">
+ {settings.user?.credits_balance != null && (
+ <div className="flex items-center gap-1.5 mr-2">
+ <Badge variant="outline" className="text-xs font-mono">
+ {settings.user.credits_balance} credits
+ </Badge>
+ {settings.user.credits_balance <= 10 && (
+ <Button
+ variant="outline"
+ size="sm"
+ className="text-xs h-7"
+ onClick={() => openUrl("https://screenpi.pe/onboarding")}
+ >
+ buy more
+ </Button>
+ )}
+ </div>
+ )}
<Button variant="outline" size="sm" onClick={fetchPipes}>
<RefreshCw className="h-4 w-4" />
</Button>
diff --git a/apps/screenpipe-app-tauri/components/upgrade-dialog.tsx b/apps/screenpipe-app-tauri/components/upgrade-dialog.tsx
index 4ccefaec9..7aa886c9d 100644
--- a/apps/screenpipe-app-tauri/components/upgrade-dialog.tsx
+++ b/apps/screenpipe-app-tauri/components/upgrade-dialog.tsx
@@ -10,7 +10,7 @@ import { Button } from "@/components/ui/button";
import { Badge } from "@/components/ui/badge";
import { open as openUrl } from "@tauri-apps/plugin-shell";
import { useSettings } from "@/lib/hooks/use-settings";
-import { Sparkles, Zap, Clock, Star } from "lucide-react";
+import { Sparkles, Zap, Clock, Star, Coins } from "lucide-react";
interface UpgradeDialogProps {
open: boolean;
@@ -27,6 +27,7 @@ export function UpgradeDialog({
}: UpgradeDialogProps) {
const { settings } = useSettings();
const isLoggedIn = !!settings.user?.token;
+ const creditsBalance = settings.user?.credits_balance ?? 0;
const handleSubscribe = async (isAnnual: boolean) => {
const baseUrl = isAnnual
@@ -113,9 +114,34 @@ export function UpgradeDialog({
>
<Zap className="h-5 w-5 shrink-0" />
<div className="text-left flex-1 min-w-0">
- <div className="font-medium">$99/mo</div>
+ <div className="font-medium">$29/mo — screenpipe pro</div>
<div className="text-xs text-muted-foreground">
- unlimited queries, all models, cloud sync, priority support
+ 200 queries/day + 500 credits/mo + encrypted sync + all models
+ </div>
+ </div>
+ </Button>
+
+ {/* Buy Credits */}
+ <Button
+ variant="outline"
+ className="w-full justify-start gap-3 h-auto py-3"
+ onClick={async () => {
+ await openUrl("https://screenpi.pe/onboarding");
+ onOpenChange(false);
+ }}
+ >
+ <Coins className="h-5 w-5 shrink-0" />
+ <div className="text-left flex-1 min-w-0">
+ <div className="font-medium">
+ buy credits
+ {creditsBalance > 0 && (
+ <span className="text-xs font-normal text-muted-foreground ml-2">
+ ({creditsBalance} remaining)
+ </span>
+ )}
+ </div>
+ <div className="text-xs text-muted-foreground">
+ credits extend your daily limit — use anytime after free quota
</div>
</div>
</Button>
diff --git a/apps/screenpipe-app-tauri/lib/hooks/use-settings.tsx b/apps/screenpipe-app-tauri/lib/hooks/use-settings.tsx
index 7598f735a..ec088dccc 100644
--- a/apps/screenpipe-app-tauri/lib/hooks/use-settings.tsx
+++ b/apps/screenpipe-app-tauri/lib/hooks/use-settings.tsx
@@ -205,7 +205,8 @@ let DEFAULT_SETTINGS: Settings = {
bio: null,
website: null,
contact: null,
- cloud_subscribed: null
+ cloud_subscribed: null,
+ credits_balance: null
},
showScreenpipeShortcut: "Control+Super+S",
startRecordingShortcut: "Super+Alt+U",
diff --git a/apps/screenpipe-app-tauri/lib/utils/tauri.ts b/apps/screenpipe-app-tauri/lib/utils/tauri.ts
index 5ea3b5c3f..0a4c72032 100644
--- a/apps/screenpipe-app-tauri/lib/utils/tauri.ts
+++ b/apps/screenpipe-app-tauri/lib/utils/tauri.ts
@@ -808,7 +808,7 @@ export type SyncDeviceInfo = { id: string; deviceId: string; deviceName: string
* Sync status response.
*/
export type SyncStatusResponse = { enabled: boolean; isSyncing: boolean; lastSync: string | null; lastError: string | null; storageUsed: bigint | null; storageLimit: bigint | null; deviceCount: number | null; deviceLimit: number | null; syncTier: string | null; machineId: string }
-export type User = { id: string | null; name: string | null; email: string | null; image: string | null; token: string | null; clerk_id: string | null; api_key: string | null; credits: Credits | null; stripe_connected: boolean | null; stripe_account_status: string | null; github_username: string | null; bio: string | null; website: string | null; contact: string | null; cloud_subscribed: boolean | null }
+export type User = { id: string | null; name: string | null; email: string | null; image: string | null; token: string | null; clerk_id: string | null; api_key: string | null; credits: Credits | null; credits_balance: number | null; stripe_connected: boolean | null; stripe_account_status: string | null; github_username: string | null; bio: string | null; website: string | null; contact: string | null; cloud_subscribed: boolean | null }
/** tauri-specta globals **/
diff --git a/apps/screenpipe-app-tauri/lib/utils/validation.ts b/apps/screenpipe-app-tauri/lib/utils/validation.ts
index 615c69dfd..42b284294 100644
--- a/apps/screenpipe-app-tauri/lib/utils/validation.ts
+++ b/apps/screenpipe-app-tauri/lib/utils/validation.ts
@@ -31,6 +31,7 @@ export const userSchema = z.object({
website: z.string().url("Invalid website URL").nullable(),
contact: z.string().nullable(),
cloud_subscribed: z.boolean().nullable(),
+ credits_balance: z.number().nullable(),
});
export const aiProviderTypeSchema = z.enum(["openai", "native-ollama", "custom", "pi"]);
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/store.rs b/apps/screenpipe-app-tauri/src-tauri/src/store.rs
index 557b97576..1aec3f29e 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/store.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/store.rs
@@ -313,6 +313,7 @@ pub struct User {
pub website: Option<String>,
pub contact: Option<String>,
pub cloud_subscribed: Option<bool>,
+ pub credits_balance: Option<i32>,
}
impl Default for User {
@@ -333,6 +334,7 @@ impl Default for User {
website: None,
contact: None,
cloud_subscribed: None,
+ credits_balance: None,
}
}
}
@@ -492,6 +494,7 @@ impl Default for SettingsStore {
website: None,
contact: None,
cloud_subscribed: None,
+ credits_balance: None,
},
#[cfg(target_os = "windows")]
show_screenpipe_shortcut: "Alt+S".to_string(),
diff --git a/packages/ai-gateway/src/index.ts b/packages/ai-gateway/src/index.ts
index 7a8710947..a78ae5d9b 100644
--- a/packages/ai-gateway/src/index.ts
+++ b/packages/ai-gateway/src/index.ts
@@ -73,20 +73,43 @@ async function handleRequest(request: Request, env: Env, ctx: ExecutionContext):
const ipAddress = request.headers.get('cf-connecting-ip') || undefined;
const usage = await trackUsage(env, authResult.deviceId, authResult.tier, authResult.userId, ipAddress);
if (!usage.allowed) {
+ const creditsExhausted = (usage.creditsRemaining ?? 0) <= 0;
return addCorsHeaders(createErrorResponse(429, JSON.stringify({
- error: 'daily_limit_exceeded',
- message: `You've used all ${usage.limit} free AI queries for today. Resets at ${usage.resetsAt}`,
+ error: creditsExhausted ? 'credits_exhausted' : 'daily_limit_exceeded',
+ message: creditsExhausted
+ ? `You've used all free queries and have no credits remaining. Buy more at screenpi.pe`
+ : `You've used all ${usage.limit} free AI queries for today. Resets at ${usage.resetsAt}`,
used_today: usage.used,
limit_today: usage.limit,
resets_at: usage.resetsAt,
tier: authResult.tier,
- upgrade_options: authResult.tier === 'anonymous'
- ? { login: { benefit: '+25 daily queries, more models' }, subscribe: { benefit: 'Unlimited queries, all models' } }
- : { subscribe: { benefit: 'Unlimited queries, all models' } },
+ credits_remaining: usage.creditsRemaining ?? 0,
+ upgrade_options: {
+ ...(authResult.tier === 'anonymous'
+ ? { login: { benefit: '+25 daily queries, more models' } }
+ : {}),
+ buy_credits: {
+ url: 'https://screenpi.pe/onboarding',
+ benefit: 'Credits extend your daily limit — use anytime',
+ },
+ subscribe: {
+ url: 'https://screenpi.pe/onboarding',
+ benefit: '200 queries/day + 500 credits/mo + encrypted sync',
+ price: '$29/mo',
+ },
+ },
})));
}
- return await handleChatCompletions(body, env);
+ // Add credit info header if paid via credits
+ const response = await handleChatCompletions(body, env);
+ if (usage.paidVia === 'credits' && usage.creditsRemaining !== undefined) {
+ const newResponse = new Response(response.body, response);
+ newResponse.headers.set('X-Credits-Remaining', String(usage.creditsRemaining));
+ newResponse.headers.set('X-Paid-Via', 'credits');
+ return newResponse;
+ }
+ return response;
}
// Web search endpoint - uses Gemini's Google Search grounding
@@ -96,12 +119,13 @@ async function handleRequest(request: Request, env: Env, ctx: ExecutionContext):
const usage = await trackUsage(env, authResult.deviceId, authResult.tier, authResult.userId, ipAddress);
if (!usage.allowed) {
return addCorsHeaders(createErrorResponse(429, JSON.stringify({
- error: 'daily_limit_exceeded',
+ error: (usage.creditsRemaining ?? 0) <= 0 ? 'credits_exhausted' : 'daily_limit_exceeded',
message: `You've used all ${usage.limit} free queries for today. Resets at ${usage.resetsAt}`,
used_today: usage.used,
limit_today: usage.limit,
resets_at: usage.resetsAt,
tier: authResult.tier,
+ credits_remaining: usage.creditsRemaining ?? 0,
})));
}
return await handleWebSearch(request, env);
@@ -173,12 +197,13 @@ async function handleRequest(request: Request, env: Env, ctx: ExecutionContext):
const usage = await trackUsage(env, authResult.deviceId, authResult.tier, authResult.userId, ipAddress);
if (!usage.allowed) {
return addCorsHeaders(createErrorResponse(429, JSON.stringify({
- error: 'daily_limit_exceeded',
+ error: (usage.creditsRemaining ?? 0) <= 0 ? 'credits_exhausted' : 'daily_limit_exceeded',
message: `You've used all ${usage.limit} AI queries for today. Resets at ${usage.resetsAt}`,
used_today: usage.used,
limit_today: usage.limit,
resets_at: usage.resetsAt,
tier: authResult.tier,
+ credits_remaining: usage.creditsRemaining ?? 0,
})));
}
@@ -204,12 +229,13 @@ async function handleRequest(request: Request, env: Env, ctx: ExecutionContext):
const usage = await trackUsage(env, authResult.deviceId, authResult.tier, authResult.userId, ipAddress);
if (!usage.allowed) {
return addCorsHeaders(createErrorResponse(429, JSON.stringify({
- error: 'daily_limit_exceeded',
+ error: (usage.creditsRemaining ?? 0) <= 0 ? 'credits_exhausted' : 'daily_limit_exceeded',
message: `You've used all ${usage.limit} AI queries for today. Resets at ${usage.resetsAt}`,
used_today: usage.used,
limit_today: usage.limit,
resets_at: usage.resetsAt,
tier: authResult.tier,
+ credits_remaining: usage.creditsRemaining ?? 0,
})));
}