Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

feat(web): gate AI usage billing UI behind the enable-ai-usage-billing PostHog flag (#7483)

Will Hutchinson3a38ea82fa4c
diff --git a/apps/web/src/components/app/Layout.tsx b/apps/web/src/components/app/Layout.tsx
index 9a585cfa0f..760e047740 100644
--- a/apps/web/src/components/app/Layout.tsx
+++ b/apps/web/src/components/app/Layout.tsx
@@ -45,7 +45,7 @@ import { useIsAuthenticated } from '@core/auth';
import { UserCardDrawer } from '@core/component/UserCardDrawer';
import { useAiUsageLimitState } from '@core/constant/AiUsageLimitState';
import {
- DEV_MODE_ENV,
+ enableAiUsageBilling,
enableDatabases,
enableReminders,
} from '@core/constant/featureFlags';
@@ -271,9 +271,11 @@ function LayoutInner(props: RouteSectionProps) {
<Paywall />
</Suspense>
</Show>
- <Show when={DEV_MODE_ENV && usageLimitOpen()}>
- <AiUsageLimitDialog />
- </Show>
+ <ShowFeatureFlag flag={enableAiUsageBilling}>
+ <Show when={usageLimitOpen()}>
+ <AiUsageLimitDialog />
+ </Show>
+ </ShowFeatureFlag>
<div class="max-h-full grow flex">
<ItemDndProvider>
<Show when={isSidebarVisible()}>
diff --git a/apps/web/src/features/gtm-invite/InviteOfferPanel.tsx b/apps/web/src/features/gtm-invite/InviteOfferPanel.tsx
index 825fb92607..4952d88344 100644
--- a/apps/web/src/features/gtm-invite/InviteOfferPanel.tsx
+++ b/apps/web/src/features/gtm-invite/InviteOfferPanel.tsx
@@ -1,6 +1,8 @@
-import { PLAN_FEATURES, PLANS } from '@app/features/paywall/plans';
+import { PLANS, planFeatures } from '@app/features/paywall/plans';
import { SkipButton } from '@app/features/setup/flow/shared';
import { useAnalytics } from '@app/lib/analytics/analytics-context';
+import { useFeatureFlag } from '@app/lib/analytics/posthog';
+import { enableAiUsageBilling } from '@core/constant/featureFlags';
import ArrowRight from '@phosphor/arrow-right.svg';
import Check from '@phosphor/check.svg';
import type { GtmInviteOffer } from '@service-auth/generated/schemas/gtmInviteOffer';
@@ -22,6 +24,7 @@ export function InviteOfferPanel(props: {
onContinueFree: () => void;
}) {
const analytics = useAnalytics();
+ const aiUsageBilling = useFeatureFlag(enableAiUsageBilling);
onMount(() => {
analytics.track('gtm_invite_offer_viewed', {
@@ -55,7 +58,7 @@ export function InviteOfferPanel(props: {
</span>
</div>
<ul class="flex flex-col gap-2">
- <Index each={PLAN_FEATURES}>
+ <Index each={planFeatures(aiUsageBilling().enabled)}>
{(feature) => (
<li class="flex items-center justify-between gap-2 text-xs">
<span class="flex items-center gap-1.5 text-ink-muted">
diff --git a/apps/web/src/features/paywall/plans.ts b/apps/web/src/features/paywall/plans.ts
index 7e43afa519..0ca889b6cf 100644
--- a/apps/web/src/features/paywall/plans.ts
+++ b/apps/web/src/features/paywall/plans.ts
@@ -1,5 +1,3 @@
-import { DEV_MODE_ENV } from '@core/constant/featureFlags';
-
export type PlanTier = 'free' | 'premium' | 'max';
export type Plan = {
tier: PlanTier;
@@ -54,13 +52,14 @@ export const PLAN_BY_TIER: Record<PlanTier, Plan> = {
interface PlanFeature {
label: string;
values: Record<PlanTier, string>;
- devOnly?: boolean;
+ /** Shown only while the `enable-ai-usage-billing` flag is on. */
+ aiUsageBilling?: boolean;
}
-const planFeatures: PlanFeature[] = [
+const PLAN_FEATURE_ROWS: PlanFeature[] = [
{
label: 'AI usage included',
- devOnly: true,
+ aiUsageBilling: true,
values: {
free: 'Limited',
premium: '$40 / mo',
@@ -77,7 +76,7 @@ const planFeatures: PlanFeature[] = [
},
{
label: 'Beyond included',
- devOnly: true,
+ aiUsageBilling: true,
values: {
free: '—',
premium: 'Credits or usage billing',
@@ -94,6 +93,13 @@ const planFeatures: PlanFeature[] = [
},
];
-export const PLAN_FEATURES = planFeatures.filter(
- (feature) => !feature.devOnly || DEV_MODE_ENV
-);
+/**
+ * The plan comparison rows. The AI usage rows (included allowance and what
+ * covers usage beyond it) appear only while AI usage billing is on; callers
+ * read `enableAiUsageBilling` and pass its value.
+ */
+export function planFeatures(aiUsageBilling: boolean) {
+ return PLAN_FEATURE_ROWS.filter(
+ (feature) => !feature.aiUsageBilling || aiUsageBilling
+ );
+}
diff --git a/apps/web/src/features/settings/Billing.test.tsx b/apps/web/src/features/settings/Billing.test.tsx
index d8a1c70948..c54dfadcbc 100644
--- a/apps/web/src/features/settings/Billing.test.tsx
+++ b/apps/web/src/features/settings/Billing.test.tsx
@@ -1,4 +1,4 @@
-import type { PlanTier } from '@app/features/paywall/plans';
+import { type PlanTier, planFeatures } from '@app/features/paywall/plans';
import { PERMISSION_IDS } from '@core/constant/permissions';
import {
cleanup,
@@ -7,20 +7,13 @@ import {
screen,
waitFor,
} from '@solidjs/testing-library';
-import type { JSX } from 'solid-js';
-import {
- afterEach,
- beforeAll,
- beforeEach,
- describe,
- expect,
- it,
- vi,
-} from 'vitest';
+import { type JSX, Show } from 'solid-js';
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+import { Billing } from './Billing';
const state = vi.hoisted(() => ({
tier: 'premium' as PlanTier,
- dev: false,
+ aiUsageBilling: false,
summarySuccess: true,
unlimited: false,
toastSuccess: vi.fn(),
@@ -28,9 +21,22 @@ const state = vi.hoisted(() => ({
}));
vi.mock('@core/constant/featureFlags', () => ({
- get DEV_MODE_ENV() {
- return state.dev;
- },
+ enableAiUsageBilling: { key: 'enable-ai-usage-billing', override: undefined },
+}));
+vi.mock('@app/lib/analytics/posthog', () => ({
+ useFeatureFlag: () => () => ({
+ enabled: state.aiUsageBilling,
+ payload: undefined,
+ loading: false,
+ }),
+ ShowFeatureFlag: (props: {
+ children: JSX.Element;
+ fallback?: JSX.Element;
+ }) => (
+ <Show when={state.aiUsageBilling} fallback={props.fallback}>
+ {props.children}
+ </Show>
+ ),
}));
vi.mock('@app/lib/analytics/analytics-context', () => ({
useAnalytics: () => ({ track: vi.fn() }),
@@ -89,102 +95,104 @@ vi.mock('@ui', () => ({
afterEach(cleanup);
-describe.each([false, true])('Billing with DEV_MODE_ENV=%s', (dev) => {
- let Billing: typeof import('./Billing').Billing;
- let PLAN_FEATURES: typeof import('@app/features/paywall/plans').PLAN_FEATURES;
-
- beforeAll(async () => {
- state.dev = dev;
- vi.resetModules();
- ({ Billing } = await import('./Billing'));
- ({ PLAN_FEATURES } = await import('@app/features/paywall/plans'));
- });
-
- beforeEach(() => {
- state.tier = 'premium';
- state.summarySuccess = true;
- state.unlimited = false;
- state.toastSuccess.mockClear();
- state.changePlan.mockClear();
- });
-
- it.each<PlanTier>(['free', 'premium', 'max'])(
- 'keeps %s subscription controls and gates usage UI and copy on dev',
- (tier) => {
- state.tier = tier;
- const { container } = render(() => <Billing />);
-
- expect(screen.getByRole('heading', { name: 'Billing' })).toBeTruthy();
- expect(screen.queryByTestId('usage-meter') !== null).toBe(
- dev && tier !== 'free'
- );
- expect(screen.queryByTestId('usage-controls') !== null).toBe(
- dev && tier !== 'free'
- );
- expect(container.textContent?.includes('of AI usage')).toBe(dev);
- if (!dev) {
- expect(container.textContent).not.toMatch(
- /AI usage|Add credits|Usage billing|included AI|out of credits/i
+describe.each([false, true])(
+ 'Billing with enable-ai-usage-billing=%s',
+ (aiUsageBilling) => {
+ beforeEach(() => {
+ state.aiUsageBilling = aiUsageBilling;
+ state.tier = 'premium';
+ state.summarySuccess = true;
+ state.unlimited = false;
+ state.toastSuccess.mockClear();
+ state.changePlan.mockClear();
+ });
+
+ it.each<PlanTier>(['free', 'premium', 'max'])(
+ 'keeps %s subscription controls and gates usage UI and copy on the flag',
+ (tier) => {
+ state.tier = tier;
+ const { container } = render(() => <Billing />);
+
+ expect(screen.getByRole('heading', { name: 'Billing' })).toBeTruthy();
+ expect(screen.queryByTestId('usage-meter') !== null).toBe(
+ aiUsageBilling && tier !== 'free'
);
+ expect(screen.queryByTestId('usage-controls') !== null).toBe(
+ aiUsageBilling && tier !== 'free'
+ );
+ expect(container.textContent?.includes('of AI usage')).toBe(
+ aiUsageBilling
+ );
+ if (!aiUsageBilling) {
+ expect(container.textContent).not.toMatch(
+ /AI usage|Add credits|Usage billing|included AI|out of credits/i
+ );
+ }
+ expect(
+ screen.getByRole('button', {
+ name: tier === 'free' ? 'Upgrade now' : 'Manage',
+ })
+ ).toBeTruthy();
}
- expect(
- screen.getByRole('button', {
- name: tier === 'free' ? 'Upgrade now' : 'Manage',
- })
- ).toBeTruthy();
- }
- );
-
- it('gates usage-billing rows in the plan comparison on dev', () => {
- const labels = PLAN_FEATURES.map((feature) => feature.label);
- expect(labels.includes('AI usage included')).toBe(dev);
- expect(labels.includes('Beyond included')).toBe(dev);
- expect(labels).toContain('AI Agent');
- expect(labels).toContain('Storage');
- });
+ );
- it('does not read a pending billing summary', () => {
- state.summarySuccess = false;
- render(() => <Billing />);
- expect(screen.queryByTestId('usage-meter')).toBeNull();
- expect(screen.getByRole('button', { name: 'Manage' })).toBeTruthy();
- });
+ it('gates usage-billing rows in the plan comparison on the flag', () => {
+ const labels = planFeatures(aiUsageBilling).map(
+ (feature) => feature.label
+ );
+ expect(labels.includes('AI usage included')).toBe(aiUsageBilling);
+ expect(labels.includes('Beyond included')).toBe(aiUsageBilling);
+ expect(labels).toContain('AI Agent');
+ expect(labels).toContain('Storage');
+ });
+
+ it('does not read a pending billing summary', () => {
+ state.summarySuccess = false;
+ render(() => <Billing />);
+ expect(screen.queryByTestId('usage-meter')).toBeNull();
+ expect(screen.getByRole('button', { name: 'Manage' })).toBeTruthy();
+ });
- it('keeps unlimited plans free of credit controls', () => {
- state.unlimited = true;
- render(() => <Billing />);
- expect(screen.queryByTestId('usage-controls')).toBeNull();
- expect(
- screen.queryByText(
- 'Your enterprise plan includes unlimited AI usage.'
- ) !== null
- ).toBe(dev);
- });
+ it('keeps unlimited plans free of credit controls', () => {
+ state.unlimited = true;
+ render(() => <Billing />);
+ expect(screen.queryByTestId('usage-controls')).toBeNull();
+ expect(
+ screen.queryByText(
+ 'Your enterprise plan includes unlimited AI usage.'
+ ) !== null
+ ).toBe(aiUsageBilling);
+ });
+
+ it.each<PlanTier>(['free', 'premium'])(
+ 'does not offer Max purchases from the %s plan',
+ (tier) => {
+ state.tier = tier;
+ render(() => <Billing />);
+
+ expect(screen.queryByRole('button', { name: 'Get Max' })).toBeNull();
+ expect(
+ screen.queryByRole('button', { name: 'Upgrade to Max' })
+ ).toBeNull();
+ }
+ );
- it.each<PlanTier>(['free', 'premium'])(
- 'does not offer Max purchases from the %s plan',
- (tier) => {
- state.tier = tier;
+ it('keeps the current Max plan visible and allows a Premium downgrade', async () => {
+ state.tier = 'max';
render(() => <Billing />);
+ expect(screen.getByRole('heading', { name: 'Max plan' })).toBeTruthy();
expect(screen.queryByRole('button', { name: 'Get Max' })).toBeNull();
expect(
screen.queryByRole('button', { name: 'Upgrade to Max' })
).toBeNull();
- }
- );
-
- it('keeps the current Max plan visible and allows a Premium downgrade', async () => {
- state.tier = 'max';
- render(() => <Billing />);
-
- expect(screen.getByRole('heading', { name: 'Max plan' })).toBeTruthy();
- expect(screen.queryByRole('button', { name: 'Get Max' })).toBeNull();
- expect(screen.queryByRole('button', { name: 'Upgrade to Max' })).toBeNull();
- fireEvent.click(screen.getByRole('button', { name: 'Switch to Premium' }));
- await waitFor(() =>
- expect(state.changePlan).toHaveBeenCalledWith({ plan: 'premium' })
- );
- });
-});
+ fireEvent.click(
+ screen.getByRole('button', { name: 'Switch to Premium' })
+ );
+ await waitFor(() =>
+ expect(state.changePlan).toHaveBeenCalledWith({ plan: 'premium' })
+ );
+ });
+ }
+);
diff --git a/apps/web/src/features/settings/Billing.tsx b/apps/web/src/features/settings/Billing.tsx
index 41286ab932..d750efd8b0 100644
--- a/apps/web/src/features/settings/Billing.tsx
+++ b/apps/web/src/features/settings/Billing.tsx
@@ -1,8 +1,9 @@
import { PLAN_BY_TIER, type PlanTier } from '@app/features/paywall/plans';
import { useAnalytics } from '@app/lib/analytics/analytics-context';
+import { ShowFeatureFlag, useFeatureFlag } from '@app/lib/analytics/posthog';
import { useHasPaidAccess } from '@core/auth';
import { toast } from '@core/component/Toast/Toast';
-import { DEV_MODE_ENV } from '@core/constant/featureFlags';
+import { enableAiUsageBilling } from '@core/constant/featureFlags';
import { PERMISSION_IDS } from '@core/constant/permissions';
import { usePermissions, useUserId } from '@core/context/user';
import { plural } from '@core/util/string';
@@ -22,12 +23,16 @@ import { createMemo, For, Match, Show, Switch } from 'solid-js';
import { AiUsageControls, AiUsageMeter } from './AiUsage';
import { SettingsCard, SettingsPage, SettingsSection } from './primitives';
-const BILLING_PLAN_FEATURES: Record<PlanTier, string[]> = {
- free: ['Access to Haiku', 'MCP access', '5 GB storage'],
- premium: [
+/** Plan bullet points; the "$N of AI usage" line only with AI usage billing on. */
+const BILLING_PLAN_FEATURES: Record<
+ PlanTier,
+ (aiUsageBilling: boolean) => string[]
+> = {
+ free: () => ['Access to Haiku', 'MCP access', '5 GB storage'],
+ premium: (aiUsageBilling) => [
'All agents',
'All models',
- ...(DEV_MODE_ENV ? ['$40 of AI usage each month'] : []),
+ ...(aiUsageBilling ? ['$40 of AI usage each month'] : []),
'No watermark',
'AI projections',
'Multiple email inboxes',
@@ -35,23 +40,26 @@ const BILLING_PLAN_FEATURES: Record<PlanTier, string[]> = {
'Teams',
'1 TB storage',
],
- max: [
+ max: (aiUsageBilling) => [
'Everything in Premium',
- ...(DEV_MODE_ENV ? ['$200 of AI usage each month'] : []),
+ ...(aiUsageBilling ? ['$200 of AI usage each month'] : []),
'Priority support',
],
};
-const PlanFeatures = (props: { tier: PlanTier }) => (
- <For each={BILLING_PLAN_FEATURES[props.tier]}>
- {(label) => (
- <li class="flex items-center gap-2">
- <CheckIcon class="size-3 text-success" />
- <span class="text-ink-muted text-xs">{label}</span>
- </li>
- )}
- </For>
-);
+const PlanFeatures = (props: { tier: PlanTier }) => {
+ const aiUsageBilling = useFeatureFlag(enableAiUsageBilling);
+ return (
+ <For each={BILLING_PLAN_FEATURES[props.tier](aiUsageBilling().enabled)}>
+ {(label) => (
+ <li class="flex items-center gap-2">
+ <CheckIcon class="size-3 text-success" />
+ <span class="text-ink-muted text-xs">{label}</span>
+ </li>
+ )}
+ </For>
+ );
+};
/** "3 Premium seats, 1 Max seat" for a team's members. */
function describeSeatPlans(members: TeamMember[]): string {
@@ -72,10 +80,10 @@ function describeSeatPlans(members: TeamMember[]): string {
const PlanPrice = (props: { tier: PaidPlan }) => (
<p class="text-ink-extra-muted text-xs">
${PLAN_BY_TIER[props.tier].price} per seat / month
- <Show when={DEV_MODE_ENV}>
+ <ShowFeatureFlag flag={enableAiUsageBilling}>
{' '}
· includes ${PLAN_BY_TIER[props.tier].aiIncluded} of AI usage
- </Show>
+ </ShowFeatureFlag>
</p>
);
@@ -86,6 +94,7 @@ export const Billing = () => {
const userId = useUserId();
const team = useCurrentTeamQuery();
const summary = useAiBillingSummaryQuery();
+ const aiUsageBilling = useFeatureFlag(enableAiUsageBilling);
const changePlan = useChangePlanMutation();
const checkout = useCreateCheckoutSessionMutation();
@@ -143,7 +152,7 @@ export const Billing = () => {
analytics.track('plan_changed', { plan });
toast.success(
plan === 'max'
- ? DEV_MODE_ENV
+ ? aiUsageBilling().enabled
? 'Upgraded to Max. Your larger AI allowance applies right away.'
: 'Upgraded to Max.'
: 'Switched to Premium.'
@@ -254,7 +263,12 @@ export const Billing = () => {
</SettingsSection>
<Show
- when={DEV_MODE_ENV && hasPaid() && summary.isSuccess && summary.data}
+ when={
+ aiUsageBilling().enabled &&
+ hasPaid() &&
+ summary.isSuccess &&
+ summary.data
+ }
>
{(snapshot) => (
<SettingsSection
@@ -337,7 +351,9 @@ export const Billing = () => {
</Match>
{/*
<Match when={tier() === 'premium'}>
- <SettingsSection title={DEV_MODE_ENV ? 'Need more AI?' : 'Upgrade'}>
+ <SettingsSection
+ title={aiUsageBilling().enabled ? 'Need more AI?' : 'Upgrade'}
+ >
<SettingsCard>
<section class="flex flex-col gap-4 p-4">
<header class="flex items-center gap-2">
@@ -384,7 +400,11 @@ export const Billing = () => {
Switch to Premium
</button>{' '}
($40 per seat / month
- <Show when={DEV_MODE_ENV}> with $40 of AI usage</Show>).
+ <ShowFeatureFlag flag={enableAiUsageBilling}>
+ {' '}
+ with $40 of AI usage
+ </ShowFeatureFlag>
+ ).
</p>
</SettingsSection>
</Match>
diff --git a/apps/web/src/features/setup/flow/PlanStep.tsx b/apps/web/src/features/setup/flow/PlanStep.tsx
index f28de7522f..9dc3808b5f 100644
--- a/apps/web/src/features/setup/flow/PlanStep.tsx
+++ b/apps/web/src/features/setup/flow/PlanStep.tsx
@@ -2,11 +2,13 @@ import { InviteOfferPanel } from '@app/features/gtm-invite/InviteOfferPanel';
import {
type PaidPlanTier,
PLAN_BY_TIER,
- PLAN_FEATURES,
PLANS,
type PlanTier,
+ planFeatures,
} from '@app/features/paywall/plans';
import { useAnalytics } from '@app/lib/analytics/analytics-context';
+import { useFeatureFlag } from '@app/lib/analytics/posthog';
+import { enableAiUsageBilling } from '@core/constant/featureFlags';
import ArrowRight from '@phosphor/arrow-right.svg';
import Check from '@phosphor/check.svg';
import { useUserInfoQuery } from '@queries/auth/user-info';
@@ -146,6 +148,7 @@ function PlanPicker(props: {
onDecideLater: () => void;
}) {
const selected = () => props.selected;
+ const aiUsageBilling = useFeatureFlag(enableAiUsageBilling);
return (
<div class="flex flex-col gap-6">
<div class="grid grid-cols-1 sm:grid-cols-2 gap-3">
@@ -187,7 +190,7 @@ function PlanPicker(props: {
</span>
</div>
<ul class="flex flex-col gap-2">
- <Index each={PLAN_FEATURES}>
+ <Index each={planFeatures(aiUsageBilling().enabled)}>
{(feature) => (
<li class="flex items-center justify-between gap-2 text-xs">
<span class="text-ink-muted">{feature().label}</span>
diff --git a/apps/web/src/lib/core/component/AI/component/input/ModelSelector.test.tsx b/apps/web/src/lib/core/component/AI/component/input/ModelSelector.test.tsx
index 916c7334c6..dab9985123 100644
--- a/apps/web/src/lib/core/component/AI/component/input/ModelSelector.test.tsx
+++ b/apps/web/src/lib/core/component/AI/component/input/ModelSelector.test.tsx
@@ -14,11 +14,16 @@ import { createSignal, type JSX } from 'solid-js';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { type ModelOption, ModelSelector } from './ModelSelector';
-const state = vi.hoisted(() => ({ dev: false, mobile: false }));
+const state = vi.hoisted(() => ({ aiUsageBilling: false, mobile: false }));
vi.mock('@core/constant/featureFlags', () => ({
- get DEV_MODE_ENV() {
- return state.dev;
- },
+ enableAiUsageBilling: { key: 'enable-ai-usage-billing', override: undefined },
+}));
+vi.mock('@app/lib/analytics/posthog', () => ({
+ useFeatureFlag: () => () => ({
+ enabled: state.aiUsageBilling,
+ payload: undefined,
+ loading: false,
+ }),
}));
vi.mock('@core/mobile/isMobile', () => ({ isMobile: () => state.mobile }));
vi.mock('@components/app/mobile/MobileDrawer', () => {
@@ -41,7 +46,7 @@ vi.mock('@components/app/mobile/MobileDrawer', () => {
});
beforeEach(() => {
- state.dev = false;
+ state.aiUsageBilling = false;
state.mobile = false;
});
afterEach(cleanup);
@@ -128,19 +133,19 @@ describe('ModelSelector: availability', () => {
});
it.each([
- { dev: false, mobile: false },
- { dev: true, mobile: false },
- { dev: false, mobile: true },
- { dev: true, mobile: true },
+ { aiUsageBilling: false, mobile: false },
+ { aiUsageBilling: true, mobile: false },
+ { aiUsageBilling: false, mobile: true },
+ { aiUsageBilling: true, mobile: true },
])(
- 'gates usage multipliers on dev ($dev), mobile=$mobile',
- ({ dev, mobile }) => {
- state.dev = dev;
+ 'gates usage multipliers on enable-ai-usage-billing ($aiUsageBilling), mobile=$mobile',
+ ({ aiUsageBilling, mobile }) => {
+ state.aiUsageBilling = aiUsageBilling;
state.mobile = mobile;
const { container } = render(() => (
<ModelSelector models={ALL_PAID} onSelect={() => {}} />
));
- expect(container.textContent?.includes('× usage')).toBe(dev);
+ expect(container.textContent?.includes('× usage')).toBe(aiUsageBilling);
}
);
diff --git a/apps/web/src/lib/core/component/AI/component/input/ModelSelector.tsx b/apps/web/src/lib/core/component/AI/component/input/ModelSelector.tsx
index cb4b6b2370..ae1114d14c 100644
--- a/apps/web/src/lib/core/component/AI/component/input/ModelSelector.tsx
+++ b/apps/web/src/lib/core/component/AI/component/input/ModelSelector.tsx
@@ -1,3 +1,4 @@
+import { useFeatureFlag } from '@app/lib/analytics/posthog';
import { MobileDrawer } from '@components/app/mobile/MobileDrawer';
import {
DEFAULT_MODEL,
@@ -8,7 +9,7 @@ import {
PAID_MODELS,
} from '@core/component/AI/constant';
import type { TModel } from '@core/component/AI/types';
-import { DEV_MODE_ENV } from '@core/constant/featureFlags';
+import { enableAiUsageBilling } from '@core/constant/featureFlags';
import { isMobile } from '@core/mobile/isMobile';
import { virtualKeyboardVisible } from '@core/mobile/virtualKeyboard';
import CheckIcon from '@phosphor/check.svg';
@@ -50,6 +51,7 @@ const MODEL_DESCRIPTION: Record<TModel, string> = {
export function ModelSelector(props: ModelSelectorProps) {
const [open, setOpen] = createSignal(false);
+ const aiUsageBilling = useFeatureFlag(enableAiUsageBilling);
const model = () => props.selectedModel ?? DEFAULT_MODEL;
const options = () =>
props.models && props.models.length > 0 ? props.models : ALL_AVAILABLE;
@@ -102,7 +104,11 @@ export function ModelSelector(props: ModelSelectorProps) {
{MODEL_PRETTYNAME[option.id]}
</span>
{/* Decorative: the item's accessible name stays the model. */}
- <Show when={DEV_MODE_ENV && modelUsageHint(option.id)}>
+ <Show
+ when={
+ aiUsageBilling().enabled && modelUsageHint(option.id)
+ }
+ >
{(hint) => (
<span
aria-hidden="true"
@@ -193,7 +199,10 @@ export function ModelSelector(props: ModelSelectorProps) {
{MODEL_PRETTYNAME[option.id]}
</span>
<Show
- when={DEV_MODE_ENV && modelUsageHint(option.id)}
+ when={
+ aiUsageBilling().enabled &&
+ modelUsageHint(option.id)
+ }
>
{(hint) => (
<span class="text-xs text-ink-extra-muted">
diff --git a/apps/web/src/lib/core/constant/featureFlags.ts b/apps/web/src/lib/core/constant/featureFlags.ts
index cf889f1040..3fd70477b2 100644
--- a/apps/web/src/lib/core/constant/featureFlags.ts
+++ b/apps/web/src/lib/core/constant/featureFlags.ts
@@ -784,6 +784,20 @@ export const enableDictation = defineFlag({
default: onInDev,
});
+/**
+ * AI usage billing UI: the Billing settings usage meter, credit packs and
+ * usage-billing controls, the out-of-credits dialog, the "$N of AI usage"
+ * plan copy, and the model picker's usage multipliers. Presentation only:
+ * backend quota admission and settlement are gated separately by
+ * `ENABLE_AI_USAGE_ENFORCEMENT` and `ENABLE_AI_USAGE_BILLING`. On in dev;
+ * production follows PostHog. Override with VITE_ENABLE_AI_USAGE_BILLING.
+ */
+export const enableAiUsageBilling = defineFlag({
+ key: 'enable-ai-usage-billing',
+ env: 'ENABLE_AI_USAGE_BILLING',
+ default: onInDev,
+});
+
/**
* Automatic in-app feature tours on desktop views (`features/tours`). Follows
* PostHog everywhere, including the local dev server; set
diff --git a/docs/AGENT_GUIDE/ai-chat.md b/docs/AGENT_GUIDE/ai-chat.md
index ff8cb08d4e..75972d0387 100644
--- a/docs/AGENT_GUIDE/ai-chat.md
+++ b/docs/AGENT_GUIDE/ai-chat.md
@@ -457,7 +457,8 @@ than treating it as approval or repeatedly sending the prompt.
Automatic chat naming is admitted independently. If naming is denied or validation
is unavailable, the successful chat continues with its existing/default title.
Usage meters, credit controls, out-of-credit dialogs, and model usage multipliers
-are hidden outside frontend development mode. Normal paid-model access rules
+are shown only when the `enable-ai-usage-billing` PostHog flag is on (default on
+in frontend development builds). Normal paid-model access rules
still apply everywhere. Backend enforcement does not depend on those frontend
controls, and enabling it does not enable credit collection; that needs
`ENABLE_AI_USAGE_BILLING`. There is no new upgrade prompt in this rollout.
diff --git a/docs/AI_QUOTA_ENFORCEMENT.md b/docs/AI_QUOTA_ENFORCEMENT.md
index 354f02718b..df4806efd4 100644
--- a/docs/AI_QUOTA_ENFORCEMENT.md
+++ b/docs/AI_QUOTA_ENFORCEMENT.md
@@ -86,9 +86,12 @@ together. Settlement without `ENABLE_AI_USAGE_ENFORCEMENT` finds nothing to
settle, because only counted rows are chargeable.
The frontend is not tied to this flag. The usage meter, credit packs,
-usage-billing controls, the out-of-credits dialog, and model usage multipliers
-keep their existing development-mode gate (`DEV_MODE_ENV`), so they show on
-`dev.macro.com` and local dev builds regardless of backend settlement.
+usage-billing controls, the out-of-credits dialog, the "$N of AI usage" plan
+copy, and model usage multipliers are gated by the frontend's
+`enable-ai-usage-billing` PostHog flag (`enableAiUsageBilling` in
+`apps/web/src/lib/core/constant/featureFlags.ts`). It defaults on in
+development builds and follows PostHog elsewhere, independent of backend
+settlement; `VITE_ENABLE_AI_USAGE_BILLING` overrides it locally.
## Public failure contracts