Analyze Pollinations revenue, pack purchases, and tier spending patterns. Query Polar for payment history and Tinybird for usage data.
pollinations repository root.jq and sops.enter.pollinations.ai/observability/scripts/tb-prod.sh "<sql>" (below written
as tb-prod.sh). It uses the production read token from SOPS; the staging workspace has
no real revenue.set -o pipefail before piping query output so a failed query fails the whole pipeline.Revenue queries must filter successful Stripe checkout events so asynchronous payment methods are counted exactly once.
tb-prod.sh "SELECT toStartOfWeek(timestamp) AS week, round(sum(amount_cents) / 100, 2) AS revenue_usd, count() AS purchases FROM stripe_event WHERE payment_status = 'paid' AND event_type IN ('checkout.session.completed', 'checkout.session.async_payment_succeeded') AND timestamp >= now() - INTERVAL 90 DAY GROUP BY week ORDER BY week DESC FORMAT JSON" | jq '.data'
tb-prod.sh "SELECT timestamp, user_id, session_id, amount_cents / 100 AS amount, currency, payment_method FROM stripe_event WHERE payment_status = 'paid' AND event_type IN ('checkout.session.completed', 'checkout.session.async_payment_succeeded') ORDER BY timestamp DESC LIMIT 100 FORMAT JSON" | jq '.data'
tb-prod.sh "SELECT user_id, round(sum(amount_cents) / 100, 2) AS revenue_usd, count() AS purchases FROM stripe_event WHERE payment_status = 'paid' AND event_type IN ('checkout.session.completed', 'checkout.session.async_payment_succeeded') AND timestamp >= now() - INTERVAL 30 DAY GROUP BY user_id ORDER BY revenue_usd DESC LIMIT 50 FORMAT JSON" | jq '.data'
tb-prod.sh "SELECT toStartOfWeek(start_time) AS week, splitByChar(':', selected_meter_slug)[-1] AS meter_source, sum(total_price) AS total_spend, count() AS requests FROM generation_event_v2 WHERE start_time >= now() - INTERVAL 60 DAY AND environment = 'production' GROUP BY week, meter_source ORDER BY week DESC FORMAT JSON" | jq '.data'
generation_event_v2 spend (pack_spend, selected_meter_slug) says which bucket was
consumed, not how it was funded. pack_balance is credited by Stripe purchases and
auto-top-ups, but also by BYOP markup and community-model rewards (paid into the payer's
bucket, shared/billing/track-helpers.ts) and some quest rewards. So pack spend β cash.
And Stripe checkout rows alone miss auto-top-ups, which never create a checkout.session.*
event. To separate cash from earned funding, reconcile each source on its own and don't
add figures with different monetary bases:
pollen_credited (stripe_event, payment_status = 'paid')amount_usd (principal credited β see below)No cash purchase β non-payment or abuse; pack spend β proof of cash.
Auto-top-up amount_usd in D1 is the Pollen principal credited; Stripe fees and taxes sit
on top. Gross cash is in Tinybird stripe_event as payment_intent.succeeded rows with an
empty user_id (auto top-ups are not attributed there); per user, fetch the invoice by
stripe_invoice_id and use amount_paid. Keep principal, gross payment, tax, refunds and
net revenue as separate numbers.
Define a past price change from the code deployed at the time, not the PR title or
announcement β an "X% cheaper" announcement can coexist with a same-day multiplier change
that cancels it. Confirm billed unit prices in generation_event_v2:
tb-prod.sh "SELECT toDate(start_time) AS day, round(avg(total_price), 6) AS avg_unit_price, count() AS requests FROM generation_event_v2 WHERE model_used = '<model>' AND start_time BETWEEN '<before>' AND '<after>' GROUP BY day ORDER BY day FORMAT JSON" | jq '.data'
Provider cost, priceMultiplier markup and pack-credit promotions move independently;
check all three. Keep cash paid separate from Pollen credited β a Pollen discount doesn't
change cash buying power. Note who was exposed before the payment event you're explaining
and any simultaneous changes.
For "these users pay more" or "X caused conversion" claims, define the comparison first:
stripe_event is the source of truth for pack-purchase revenue analytics.generation_event_v2 records Pollen consumption, not cash revenue.user_id, so revenue and usage can be joined directly.daily_stripe_revenue pipe applies the same paid-event filter.total_price) for
strategic claims.