Use this skill whenever the user mentions cost, costs, pricing, budget, spending, token usage, API costs, Gemini costs, AI costs, model costs, Supabase costs, Vercel costs, infrastructure costs, billing, 'how much does this cost', 'my bill is too high', 'reduce costs', 'save money', 'cost optimization', token counting, rate limiting for cost, model routing, 'which model should I use', tiered models, usage tracking, usage dashboard, or ANY cost management task — even if they don't explicitly say 'cost'. Running 3 Gemini models + Supabase + Vercel + multiple services without cost controls is a ticking time bomb.
dudedesi120 estrellas8 abr 2026
Ocupación
Categorías
Finanzas e Inversión
Contenido de la habilidad
Track and control costs across all your services. Focus: AI token costs and holistic budgeting. Cross-reference: vercel-power-user §9 for Vercel plan limits.
-- supabase/migrations/xxx_token_usage.sql
CREATE TABLE token_usage (
id uuid DEFAULT gen_random_uuid() PRIMARY KEY,
user_id uuid REFERENCES auth.users(id) ON DELETE SET NULL,
model text NOT NULL,
complexity text NOT NULL,
prompt_tokens integer NOT NULL DEFAULT 0,
completion_tokens integer NOT NULL DEFAULT 0,
total_tokens integer NOT NULL DEFAULT 0,
estimated_cost_usd numeric(10, 6) NOT NULL DEFAULT 0,
feature text,
created_at timestamptz DEFAULT now()
);
CREATE INDEX idx_token_usage_user ON token_usage(user_id, created_at DESC);
CREATE INDEX idx_token_usage_date ON token_usage(created_at DESC);
// Don't call Gemini twice for the same input
import { Redis } from "@upstash/redis";
const redis = new Redis({ url: process.env.UPSTASH_REDIS_REST_URL!, token: process.env.UPSTASH_REDIS_REST_TOKEN! });
export async function generateWithCache(prompt: string, task: string) {
const cacheKey = `ai:${task}:${hashPrompt(prompt)}`;
const cached = await redis.get<string>(cacheKey);
if (cached) return cached;
const result = await generateWithTracking(task, prompt);
await redis.set(cacheKey, result, { ex: 3600 }); // Cache 1 hour
return result;
}
Batch Operations
// BAD: One API call per item
for (const item of items) {
await generateWithTracking("classify", `Classify: ${item.text}`);
}
// GOOD: Batch into one call
const batchPrompt = items.map((item, i) => `${i + 1}. ${item.text}`).join("\n");
const result = await generateWithTracking(
"classify",
`Classify each item:\n${batchPrompt}\n\nReturn JSON array of classifications.`
);
7. Monthly Cost Review Template
## Monthly Cost Review — [Month Year]
### Service Costs
| Service | Budget | Actual | % Used | Action |
|---------|--------|--------|--------|--------|
| Gemini API | $100 | $ | % | |
| Supabase | $25 | $ | % | |
| Vercel | $20 | $ | % | |
| Upstash | $10 | $ | % | |
| Resend | $20 | $ | % | |
| Stripe fees | N/A | $ | N/A | |
| **Total** | **$175** | **$** | | |
### Top Token Consumers
| Feature | Tokens Used | Cost | Model |
|---------|------------|------|-------|
| | | | |
### Action Items
- [ ] Review and clean up unused Supabase storage
- [ ] Check for expensive queries (pg_stat_statements)
- [ ] Verify model routing is using cheapest appropriate model
- [ ] Delete old token_usage records (> 90 days)
Rules
Track every AI call — Log tokens, model, cost, and feature for every Gemini request.
Use the cheapest model that works — flash-lite for simple tasks, flash for medium, pro only when needed.
Cache AI responses — Same input = same output. Cache with Redis.
Set hard limits — Configure daily budget limits that reject requests when exceeded.
Batch when possible — One prompt with 10 items is cheaper than 10 separate prompts.
Select specific columns — Never select("*") in production queries.
Clean up storage — Delete unused files from Supabase Storage monthly.
Monitor daily — Check the cost dashboard or set up Slack alerts for budget thresholds.
Review monthly — Use the review template above to catch cost creep.