:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(replay-vision): show credits with a dollar anchor in scanner UI (#73279)
Arno Hillenf11de4ac5c70
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex b4650dcb03a5..ffeee45b8a11 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -6883,9 +6883,9 @@ snapshots:scenes-app-project-homepage--project-homepage--light:hash: v1.k794b7964.2eafc7385bf39f5be7d4d6d0ad1b70897952bcf37a16bd3ae6c644716cd16d25.25OmRYioQX_VF2kc2AVnvYlE0yve6YNcY2FDdJwV5kEscenes-app-replay-vision--scanners-list--dark:- hash: v1.k794b7964.c224db762849cf8b332d37e72b254a859d40cd113b36b78f6f031e1f17efcf73.9d-GzGqGR4iCPVCCEOySYcYbGOR2NMRhr9JR9eOndBA+ hash: v1.k794b7964.ea15abb4e5defc4511ffbcadca20f2d5568c2d272c112bd08588728fce9325a7.FAVbx6yFt4se4F6rADOjwkqV8yP4ooVPshzDQwh62UYscenes-app-replay-vision--scanners-list--light:- hash: v1.k794b7964.75b0fb01ded84eec9ed41f4503f5bd4bee361050b080f5d98793cb13e2dd7ac3.22HYMtg-KTJxgcNp2yxQLnlleJ7fdtvDnSRMyaZNGjA+ hash: v1.k794b7964.99f5f4499dca089b44d7bce7dee60424c7bdeefb860a8882d5ca8cbf06abce69.MHJZLg5-Q8USBaHeY-N_hqBMtEfuRArXAsAgnwEk4gsscenes-app-saved-insights--empty-state--dark:hash: v1.k794b7964.43545664c9133c8afd354be6a6ed8f808c35b381101325d9605114632fcdc0c9.l8w9uEOEmrH6Xl1kNd9ueRtg_51cJUSjWLdjWDM0Fkoscenes-app-saved-insights--empty-state--light:diff --git a/products/replay_vision/frontend/replay_scanners/ReplayScanner.tsx b/products/replay_vision/frontend/replay_scanners/ReplayScanner.tsxindex 8127a013ab11..b2c4aeba2c88 100644--- a/products/replay_vision/frontend/replay_scanners/ReplayScanner.tsx+++ b/products/replay_vision/frontend/replay_scanners/ReplayScanner.tsx@@ -20,7 +20,7 @@ import { IngestionLimitBanner } from '../components/IngestionLimitBanner'import { ReplayVisionFeedbackButton } from '../components/ReplayVisionFeedbackButton'import { visionQuotaLogic } from '../logics/visionQuotaLogic'import { getReplayVisionEditDisabledReason } from '../utils/accessControl'-import { formatCredits } from '../utils/credits'+import { formatCreditsRange } from '../utils/credits'import { quotaBannerState } from '../utils/quotaProjection'import { ScannerConfigReadonly } from './components/ScannerConfigReadonly'import { ScannerDigestCard } from './components/ScannerDigestCard'@@ -167,8 +167,8 @@ function QuotaBanner(): JSX.Element | null {return (<LemonBanner type="warning">{state.kind === 'exhausted'- ? `Monthly spend limit reached (${formatCredits(state.quota.credits_used)} of ${formatCredits(state.quota.credit_limit ?? 0)}). New observations are paused until ${state.resetsOn}.`- : `${formatCredits(state.quota.credits_used)} of your ${formatCredits(state.quota.credit_limit ?? 0)} monthly spend limit used. New observations will pause once you hit the limit. Resets ${state.resetsOn}.`}+ ? `Monthly spend limit reached: ${formatCreditsRange(state.quota.credits_used, state.quota.credit_limit ?? 0)}. New observations are paused until ${state.resetsOn}.`+ : `You've used ${formatCreditsRange(state.quota.credits_used, state.quota.credit_limit ?? 0)} this month. New observations will pause once you hit the limit. Resets ${state.resetsOn}.`}</LemonBanner>)}diff --git a/products/replay_vision/frontend/replay_scanners/ReplayScannersScene.stories.tsx b/products/replay_vision/frontend/replay_scanners/ReplayScannersScene.stories.tsxindex f1e4f6406f1c..ee0a5ddd67a7 100644--- a/products/replay_vision/frontend/replay_scanners/ReplayScannersScene.stories.tsx+++ b/products/replay_vision/frontend/replay_scanners/ReplayScannersScene.stories.tsx@@ -43,6 +43,7 @@ const scanner = (overrides: Partial<ReplayScannerApi> = {}): ReplayScannerApi =>created_at: '2026-05-12T00:00:00Z',updated_at: '2026-05-12T00:00:00Z',created_by: null,+ credits_this_month: 0,...overrides,}) as ReplayScannerApi@@ -54,6 +55,7 @@ const scanners = {scanner({id: '00000000-0000-0000-0000-00000000000a',name: 'Confused checkout',+ credits_this_month: 1250,description: 'Flags sessions where the user hesitated at payment.',scanner_type: 'monitor',sampling_rate: 1,@@ -62,6 +64,7 @@ const scanners = {scanner({id: '00000000-0000-0000-0000-00000000000b',name: 'Frustration tags',+ credits_this_month: 0,scanner_type: 'classifier',scanner_config: { prompt: 'Tag this session.', tags: ['rage-click', 'dead-end'], multi_label: true },enabled: false,@@ -71,6 +74,7 @@ const scanners = {scanner({id: '00000000-0000-0000-0000-00000000000c',name: 'Session summary',+ credits_this_month: 5,scanner_type: 'summarizer',scanner_config: { prompt: 'Summarize this session.', length: 'medium' },sampling_rate: 0.05,@@ -79,6 +83,7 @@ const scanners = {scanner({id: '00000000-0000-0000-0000-00000000000d',name: 'Intent score',+ credits_this_month: 320,scanner_type: 'scorer',scanner_config: { prompt: 'Score this session.', scale: { min: 0, max: 10 } },sampling_rate: 1,diff --git a/products/replay_vision/frontend/replay_scanners/ReplayScannersScene.tsx b/products/replay_vision/frontend/replay_scanners/ReplayScannersScene.tsxindex 55fc162847ee..a546fff7d381 100644--- a/products/replay_vision/frontend/replay_scanners/ReplayScannersScene.tsx+++ b/products/replay_vision/frontend/replay_scanners/ReplayScannersScene.tsx@@ -38,7 +38,7 @@ import { IngestionLimitBanner } from '../components/IngestionLimitBanner'import { ReplayVisionFeedbackButton } from '../components/ReplayVisionFeedbackButton'import { ScannerTypeBadge } from '../components/ScannerTypeBadge'import { getReplayVisionDeleteDisabledReason, getReplayVisionEditDisabledReason } from '../utils/accessControl'-import { formatCredits } from '../utils/credits'+import { creditsToUsd, formatCreditCount } from '../utils/credits'import { VisionMetrics } from './components/VisionMetrics'import { VisionUsageTab } from './components/VisionUsageTab'import { type ScannersSorting, SCANNERS_PAGE_SIZE, replayScannersLogic } from './replayScannersLogic'@@ -203,7 +203,10 @@ export function ReplayScannersScene(): JSX.Element {title: 'Spend this period',key: 'credits_this_month',render: (_, scanner) => (- <span className="text-sm tabular-nums">{formatCredits(scanner.credits_this_month)}</span>+ <div className="text-sm tabular-nums">+ <div>{formatCreditCount(scanner.credits_this_month)}</div>+ <div className="text-muted text-xs">≈ {creditsToUsd(scanner.credits_this_month)}</div>+ </div>),sorter: true,},diff --git a/products/replay_vision/frontend/replay_scanners/components/ScannerConfigReadonly.tsx b/products/replay_vision/frontend/replay_scanners/components/ScannerConfigReadonly.tsxindex abcbfc543a73..616a412d80a6 100644--- a/products/replay_vision/frontend/replay_scanners/components/ScannerConfigReadonly.tsx+++ b/products/replay_vision/frontend/replay_scanners/components/ScannerConfigReadonly.tsx@@ -387,7 +387,7 @@ export function ScannerConfigReadonly({ scanner }: { scanner: ReplayScanner }):<span className="tabular-nums">{formatCredits(scanner.estimated_monthly_credits)}{' '}<span className="text-muted">- ({(scanner.estimated_monthly_observations ?? 0).toLocaleString()} observations)+ · {(scanner.estimated_monthly_observations ?? 0).toLocaleString()} observations</span></span>) : (diff --git a/products/replay_vision/frontend/replay_scanners/components/ScannerQualityTab.tsx b/products/replay_vision/frontend/replay_scanners/components/ScannerQualityTab.tsxindex 5c21a2d9368d..a772c677a03f 100644--- a/products/replay_vision/frontend/replay_scanners/components/ScannerQualityTab.tsx+++ b/products/replay_vision/frontend/replay_scanners/components/ScannerQualityTab.tsx@@ -34,7 +34,7 @@ import type {import { visionQuotaLogic } from '../../logics/visionQuotaLogic'import { ObservationLabelControl, ObservationLabelFeedback } from '../../observations/ObservationLabelControl'import { getReplayVisionEditDisabledReason } from '../../utils/accessControl'-import { formatCredits } from '../../utils/credits'+import { formatCreditCount, formatCreditsRange } from '../../utils/credits'import { buildChartDayFormatter, fillLabelDays, versionAccuracyStrip } from '../../utils/labelStats'import { readConfidence } from '../../utils/observation'import { replayScannerLogic } from '../replayScannerLogic'@@ -403,9 +403,9 @@ function ConfigRecommendationPanel({ scannerId }: { scannerId: string }): JSX.El(ratedCount === 0? 'Rate at least one result first': quota?.exhausted && quota.credit_limit !== null- ? `Monthly Replay Vision budget of ${formatCredits(quota.credit_limit)} reached. Resets ${dayjs(quota.period_end).format('MMM D')}.`+ ? `Monthly Replay Vision budget of ${formatCreditCount(quota.credit_limit)} reached. Resets ${dayjs(quota.period_end).format('MMM D')}.`: quota && quota.remaining !== null && plannedTestCredits > quota.remaining- ? `Only ${formatCredits(quota.remaining)} of budget left this period. Lower the test session count.`+ ? `Only ${formatCreditCount(quota.remaining)} of budget left this period. Lower the test session count.`: undefined)}tooltip="Re-runs the scanner with the suggested prompt against your rated sessions, so you can see what would change before applying. Each tested session is charged like a normal observation. Pick how many below."@@ -461,9 +461,9 @@ function ConfigRecommendationPanel({ scannerId }: { scannerId: string }): JSX.El<span>of your {Math.min(evaluationSessionCap, ratedCount)} most useful rated session{Math.min(evaluationSessionCap, ratedCount) === 1 ? '' : 's'}, charging{' '}- {formatCredits(plannedTestCredits)}+ {formatCreditCount(plannedTestCredits)}{quota && quota.remaining !== null && quota.credit_limit !== null- ? ` (${formatCredits(quota.remaining)} of ${formatCredits(quota.credit_limit)} left this period)`+ ? `, ${formatCreditsRange(quota.remaining, quota.credit_limit)} left this period`: ''}.</span>diff --git a/products/replay_vision/frontend/replay_scanners/components/ScannerQuotaForecast.tsx b/products/replay_vision/frontend/replay_scanners/components/ScannerQuotaForecast.tsxindex 736574ec2a00..505fbf83883c 100644--- a/products/replay_vision/frontend/replay_scanners/components/ScannerQuotaForecast.tsx+++ b/products/replay_vision/frontend/replay_scanners/components/ScannerQuotaForecast.tsx@@ -5,7 +5,7 @@ import { LemonCard, Spinner, Tooltip } from '@posthog/lemon-ui'import { LemonLabel } from 'lib/lemon-ui/LemonLabel'import { visionQuotaLogic } from '../../logics/visionQuotaLogic'-import { formatCredits } from '../../utils/credits'+import { creditsToUsd, formatCreditCount } from '../../utils/credits'import {QUOTA_STATUS_STYLES,type QuotaStatus,@@ -57,17 +57,17 @@ export function ScannerQuotaForecast({ scannerId }: Props): JSX.Element | null {const breakdown = (<div className="text-xs space-y-0.5"><div>- Spent this period: <strong>{formatCredits(used)}</strong>+ Spent this period: <strong>{formatCreditCount(used)}</strong></div><div>- Projected from this scanner: <strong>~{formatCredits(projectedCredits ?? 0)}/month</strong>+ Projected from this scanner: <strong>~{formatCreditCount(projectedCredits ?? 0)}/month</strong></div><div>- Projected from other scanners: <strong>~{formatCredits(othersMonthly)}/month</strong>+ Projected from other scanners: <strong>~{formatCreditCount(othersMonthly)}/month</strong></div>{hasCap && (<div>- Monthly limit: <strong>{formatCredits(cap)}</strong>+ Monthly limit: <strong>{formatCreditCount(cap)}</strong></div>)}{resetsOn && <div className="text-muted">Resets {resetsOn}</div>}@@ -92,11 +92,11 @@ export function ScannerQuotaForecast({ scannerId }: Props): JSX.Element | null {{projectedCredits !== null ? (<div className="text-base font-semibold tabular-nums flex items-center gap-2"><span>- ~{formatCredits(projectedCredits)}+ ~{formatCreditCount(projectedCredits)}<span className="text-sm font-normal text-muted">/month</span>{' '}<span className="text-sm font-normal text-muted">- ({(projectedObservations ?? 0).toLocaleString()} observations at{' '}- {formatCredits(scannerEstimate?.credits_per_observation ?? 0)} each)+ (≈ {creditsToUsd(projectedCredits)}) · {(projectedObservations ?? 0).toLocaleString()}{' '}+ observations at {formatCreditCount(scannerEstimate?.credits_per_observation ?? 0)} each</span></span>{scannerEstimateLoading && (diff --git a/products/replay_vision/frontend/replay_scanners/components/VisionMetrics.tsx b/products/replay_vision/frontend/replay_scanners/components/VisionMetrics.tsxindex b47f35e63866..28374383f46b 100644--- a/products/replay_vision/frontend/replay_scanners/components/VisionMetrics.tsx+++ b/products/replay_vision/frontend/replay_scanners/components/VisionMetrics.tsx@@ -11,7 +11,7 @@ import { BaseMathType, ChartDisplayType, InsightLogicProps } from '~/types'import { ScannerTypeBadge } from '../../components/ScannerTypeBadge'import { visionQuotaLogic } from '../../logics/visionQuotaLogic'-import { formatCredits } from '../../utils/credits'+import { creditsToUsd, formatCreditCount } from '../../utils/credits'import { QUOTA_STATUS_STYLES, hasCreditLimit, projectQuota } from '../../utils/quotaProjection'import { replayScannersLogic } from '../replayScannersLogic'import { SCANNER_TYPE_OPTIONS } from '../types'@@ -122,14 +122,18 @@ export function VisionMetrics(): JSX.Element {Estimated spend. You won't be billed during the closed beta.</div><div className="text-3xl font-semibold tabular-nums">- {formatCredits(quota.credits_used)}+ {formatCreditCount(quota.credits_used)}{hasCap && (<span className="text-muted text-lg font-normal">{' / '}- {formatCredits(quota.credit_limit ?? 0)}+ {formatCreditCount(quota.credit_limit ?? 0)}</span>)}</div>+ <div className="text-muted text-sm tabular-nums">+ ≈ {creditsToUsd(quota.credits_used)}+ {hasCap ? ` / ${creditsToUsd(quota.credit_limit ?? 0)}` : ''}+ </div>{hasCap ? (<><Tooltip@@ -137,17 +141,17 @@ export function VisionMetrics(): JSX.Element {<div className="text-xs space-y-0.5"><div>Spent this period:{' '}- <strong>{formatCredits(quota.credits_used)}</strong>+ <strong>{formatCreditCount(quota.credits_used)}</strong></div><div>Projected from enabled scanners:{' '}<strong>- ~{formatCredits(quota.projected_monthly_credits)}/month+ ~{formatCreditCount(quota.projected_monthly_credits)}/month</strong></div><div>Monthly limit:{' '}- <strong>{formatCredits(quota.credit_limit ?? 0)}</strong>+ <strong>{formatCreditCount(quota.credit_limit ?? 0)}</strong></div>{resetsOn && <div className="text-muted">Resets {resetsOn}</div>}</div>@@ -173,7 +177,7 @@ export function VisionMetrics(): JSX.Element {</>) : (<div className="text-xs text-muted mt-2">- No spend limit set: projected ~{formatCredits(quota.projected_monthly_credits)}+ No spend limit set: projected ~{formatCreditCount(quota.projected_monthly_credits)}/month from enabled scanners. Set a billing limit in your billing settings to capspend.</div>diff --git a/products/replay_vision/frontend/replay_scanners/types.ts b/products/replay_vision/frontend/replay_scanners/types.tsindex cc2707e2ce8e..63e6443a6ab0 100644--- a/products/replay_vision/frontend/replay_scanners/types.ts+++ b/products/replay_vision/frontend/replay_scanners/types.ts@@ -12,7 +12,7 @@ import type {UserBasicApi,VisionObservationsRetrieveParams,} from '../generated/api.schemas'-import { formatCredits } from '../utils/credits'+import { formatCreditCount } from '../utils/credits'export type ScannerType = ScannerTypeEnumApi@@ -162,7 +162,7 @@ const MODEL_NAMES: Record<ScannerModelEnumApi, string> = {export const MODEL_OPTIONS: { value: ScannerModelEnumApi; label: string }[] = Object.values(ScannerModelEnumApi).map((value) => ({value,- label: `${MODEL_NAMES[value]} (${formatCredits(OBSERVATION_CREDITS_BY_MODEL[value])}/observation)`,+ label: `${MODEL_NAMES[value]} · ${formatCreditCount(OBSERVATION_CREDITS_BY_MODEL[value])}/observation`,}))diff --git a/products/replay_vision/frontend/utils/credits.test.ts b/products/replay_vision/frontend/utils/credits.test.tsnew file mode 100644index 000000000000..304ba547aad7--- /dev/null+++ b/products/replay_vision/frontend/utils/credits.test.ts@@ -0,0 +1,38 @@+import { creditsToUsd, formatCreditCount, formatCredits, formatCreditsRange } from './credits'++describe('credits formatting', () => {+ it.each([+ [0, '0 credits (≈ $0.00)'],+ [1, '1 credit (≈ $0.01)'],+ [2, '2 credits (≈ $0.02)'],+ [500, '500 credits (≈ $5.00)'],+ [5000, '5,000 credits (≈ $50.00)'],+ // Fractional estimates round to whole credits, and the dollar anchor follows the rounded count.+ [512.4, '512 credits (≈ $5.12)'],+ [512.6, '513 credits (≈ $5.13)'],+ ])('formatCredits(%p) -> %p', (credits, expected) => {+ expect(formatCredits(credits)).toBe(expected)+ })++ it.each([+ [0, '0 credits'],+ [1, '1 credit'],+ [1500, '1,500 credits'],+ ])('formatCreditCount(%p) -> %p', (credits, expected) => {+ expect(formatCreditCount(credits)).toBe(expected)+ })++ it.each([+ [5, '$0.05'],+ [1200, '$12.00'],+ ])('creditsToUsd(%p) -> %p', (credits, expected) => {+ expect(creditsToUsd(credits)).toBe(expected)+ })++ it.each([+ [1200, 5000, '1,200 of 5,000 credits'],+ [1, 1, '1 of 1 credit'],+ ])('formatCreditsRange(%p, %p) -> %p', (used, total, expected) => {+ expect(formatCreditsRange(used, total)).toBe(expected)+ })+})diff --git a/products/replay_vision/frontend/utils/credits.ts b/products/replay_vision/frontend/utils/credits.tsindex 71597630667d..a92eb67c9326 100644--- a/products/replay_vision/frontend/utils/credits.ts+++ b/products/replay_vision/frontend/utils/credits.ts@@ -1,8 +1,29 @@import { humanFriendlyCurrency } from 'lib/utils/numbers'-/** 1 credit = $0.01; all quota amounts arrive from the API as credits and render as dollars. */+/** 1 credit = $0.01. Amounts arrive from the API as integer credits. Credits are the unit we bill, so credits are+ * what we show. The dollar anchor is reserved for the three spend surfaces (the spend meter, the scanner list's+ * spend column, and the cost estimate) — repeating it in every tooltip, banner, and dropdown option is noise.+ * Those three pair `formatCreditCount` with `creditsToUsd` when the dollar gets its own line, or use the inline+ * `formatCredits`. Everywhere else is `formatCreditCount` alone. */export const CREDITS_PER_DOLLAR = 100+/** e.g. 1200 -> "$12.00". */+export function creditsToUsd(credits: number): string {+ return humanFriendlyCurrency(Math.round(credits) / CREDITS_PER_DOLLAR)+}++/** e.g. 500 -> "500 credits", 1 -> "1 credit". */+export function formatCreditCount(credits: number): string {+ const rounded = Math.round(credits)+ return `${rounded.toLocaleString('en-US')} ${Math.abs(rounded) === 1 ? 'credit' : 'credits'}`+}++/** e.g. 500 -> "500 credits (≈ $5.00)", 1 -> "1 credit (≈ $0.01)". */export function formatCredits(credits: number): string {- return humanFriendlyCurrency(credits / CREDITS_PER_DOLLAR)+ return `${formatCreditCount(credits)} (≈ ${creditsToUsd(credits)})`+}++/** A "used of limit" pair that names the unit once, e.g. (1200, 5000) -> "1,200 of 5,000 credits". */+export function formatCreditsRange(used: number, total: number): string {+ return `${Math.round(used).toLocaleString('en-US')} of ${formatCreditCount(total)}`}diff --git a/products/replay_vision/frontend/utils/quotaProjection.test.ts b/products/replay_vision/frontend/utils/quotaProjection.test.tsindex 81078f817fa7..c8b5057d7009 100644--- a/products/replay_vision/frontend/utils/quotaProjection.test.ts+++ b/products/replay_vision/frontend/utils/quotaProjection.test.ts@@ -105,10 +105,10 @@ describe('quotaUx', () => {expect(ux.tooltip).toBeUndefined()})- it('shows a dollar tooltip near the warn threshold but does not block', () => {+ it('shows a remaining-credits tooltip near the warn threshold but does not block', () => {const ux = quotaUx(makeQuota({ credits_used: 8_500, remaining: 1_500 }))expect(ux.disabledReason).toBeUndefined()- expect(ux.tooltip).toContain('$15.00')+ expect(ux.tooltip).toContain('1,500 credits left')})it('returns nothing while usage is well under the threshold', () => {diff --git a/products/replay_vision/frontend/utils/quotaProjection.ts b/products/replay_vision/frontend/utils/quotaProjection.tsindex 078943ca832e..74008dbf24f0 100644--- a/products/replay_vision/frontend/utils/quotaProjection.ts+++ b/products/replay_vision/frontend/utils/quotaProjection.ts@@ -1,7 +1,7 @@import { dayjs } from 'lib/dayjs'import type { VisionQuotaApi } from '../generated/api.schemas'-import { formatCredits } from './credits'+import { formatCreditCount } from './credits'export const QUOTA_WARN_THRESHOLD = 0.85@@ -125,7 +125,7 @@ export function quotaUx(quota: VisionQuotaApi | null): { disabledReason?: stringreturn { disabledReason: `Monthly Replay vision spend limit reached. Resets ${state.resetsOn}.` }}return {- tooltip: `${formatCredits(state.quota.remaining ?? 0)} left this month (resets ${state.resetsOn})`,+ tooltip: `${formatCreditCount(state.quota.remaining ?? 0)} left this month (resets ${state.resetsOn})`,}}