Skip to content

: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.

fix(billing): tighten posthog code limit UX (#71444)

Pawel Cebula97605d384aad
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index cd6a76cd72be..bde4de00e211 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -7290,6 +7290,18 @@ snapshots:
hash: v1.k794b7964.83cd21639558407b39daef873aea7990fb596340fddba3ef2368b4ba63ce2e5f.sBCEN34rW_oWprGeVNQQBmQE3pkAuYW0-dAkpPrUn5Q
scenes-other-billing-product--billing-product-platform-addons-trial-used--light:
hash: v1.k794b7964.a3610366ad2be64f9b6ff77176950ce1ff726937f39b0270c50bff9f0c3b9c55.83KQE3ww4YX5WW-n9BfxNXj4nF3BAEnJJtBETXTJjFI
+ scenes-other-billing-product--billing-product-post-hog-code-limit--dark:
+ hash: v1.k794b7964.72b7cc6af966832979cfaa05e80101916cea119086e2efcb2ca203612cc6f5e5.hlEQZYCfx5UZi1nqmU0aQy8SlsDypG9euIdzGXYQF6I
+ scenes-other-billing-product--billing-product-post-hog-code-limit--light:
+ hash: v1.k794b7964.306708a3a4016583fa6a1469629a154713d6344f3df7873518a0bbc7ca697837.w54jEkGxfulwkuLeHqWR_foRLzvSikRlg3gB7rx-KPc
+ scenes-other-billing-product--billing-product-post-hog-code-limit-editing--dark:
+ hash: v1.k794b7964.c6b8093fd29c173e56d0768d2e05b469ad199b62c817333f09e5a9d6d3a78960.J1TyH_H1kZH99IcXYSbbTvHyIw2zsCPoHO8jjuVWXpw
+ scenes-other-billing-product--billing-product-post-hog-code-limit-editing--light:
+ hash: v1.k794b7964.25e30eec15df65f1c599163ecfe18faf9386663bafa8b5b593a762873441f447.KbyAiGy9gSuNGLrbH2ZuNfOPC9OxNIXozHqQusk3RMU
+ scenes-other-billing-product--billing-product-post-hog-code-limit-next-period-capped--dark:
+ hash: v1.k794b7964.4a6d1557af5e90408397a07312429512db04b4158d8b5dc2eb9bf6d6d1ff65e7.4RfNh-7nWb2--TFJEvQ0hH2J7z-AELSsHIvFg3Tea4I
+ scenes-other-billing-product--billing-product-post-hog-code-limit-next-period-capped--light:
+ hash: v1.k794b7964.97841a5168d91bebe5b54c32d1e1c25f0830218d6717112900484691e829329b.VPVdnvFdRu8lgMP3U9HRq43l2KiRMDk2S7xVvjhNxlQ
scenes-other-billing-product--billing-product-temporarily-free--dark:
hash: v1.k794b7964.17457ea2e809235689317d9e0feb224c18f8d5a81c8adf04b314e4d0c7b6f7d4.l_BpJhV7_FHvsDrKy34afdUPZvjK2sjH2OizL4u6SnI
scenes-other-billing-product--billing-product-temporarily-free--light:
diff --git a/frontend/src/scenes/billing/BillingLimit.tsx b/frontend/src/scenes/billing/BillingLimit.tsx
index b4f24726fe12..e1ef44465e54 100644
--- a/frontend/src/scenes/billing/BillingLimit.tsx
+++ b/frontend/src/scenes/billing/BillingLimit.tsx
@@ -15,13 +15,21 @@ import { billingProductLogic } from './billingProductLogic'
export const BillingLimit = ({ product }: { product: BillingProductV2Type }): JSX.Element | null => {
const limitInputRef = useRef<HTMLInputElement | null>(null)
const { billing, billingLoading } = useValues(billingLogic)
- const { isEditingBillingLimit, customLimitUsd, hasCustomLimitSet, currentAndUpgradePlans, billingLimitNextPeriod } =
- useValues(billingProductLogic({ product, billingLimitInputRef: limitInputRef }))
+ const {
+ isEditingBillingLimit,
+ customLimitUsd,
+ hasCustomLimitSet,
+ currentAndUpgradePlans,
+ billingLimitNextPeriod,
+ billingLimitConfig,
+ removingBillingLimitNextPeriod,
+ } = useValues(billingProductLogic({ product, billingLimitInputRef: limitInputRef }))
const { setIsEditingBillingLimit, setBillingLimitInput, submitBillingLimitInput, removeBillingLimitNextPeriod } =
useActions(billingProductLogic({ product }))
const initialBillingLimit = currentAndUpgradePlans?.currentPlan?.initial_billing_limit
const usingInitialBillingLimit = customLimitUsd === initialBillingLimit
+ const hasBillingLimitNextPeriod = billingLimitNextPeriod !== null
if (billing?.billing_period?.interval !== 'month' || !product.subscribed || product.inclusion_only) {
return null
@@ -87,7 +95,7 @@ export const BillingLimit = ({ product }: { product: BillingProductV2Type }): JS
</>
) : (
<div className="flex items-start justify-start gap-2.5">
- <LemonField name="input" className="max-w-52">
+ <LemonField name="input" className="max-w-52" help={billingLimitConfig.help}>
{({ value, onChange, error }) => (
<LemonInput
inputRef={limitInputRef}
@@ -100,6 +108,7 @@ export const BillingLimit = ({ product }: { product: BillingProductV2Type }): JS
prefix={<b>$</b>}
disabled={billingLoading}
min={0}
+ max={billingLimitConfig.max}
step={1}
suffix={<>/ {billing?.billing_period?.interval}</>}
size="small"
@@ -132,6 +141,7 @@ export const BillingLimit = ({ product }: { product: BillingProductV2Type }): JS
size="small"
data-attr={`remove-billing-limit-${product.type}`}
tooltip="Remove billing limit"
+ disabledReason={billingLimitConfig.removalDisabledReason}
onClick={() => {
setBillingLimitInput(null)
submitBillingLimitInput()
@@ -143,7 +153,7 @@ export const BillingLimit = ({ product }: { product: BillingProductV2Type }): JS
</div>
)}
</div>
- {billingLimitNextPeriod ? (
+ {hasBillingLimitNextPeriod ? (
<div className="flex items-center gap-1">
<span className="text-sm xl:text-right">
Your limit for next period: <b>${billingLimitNextPeriod.toLocaleString()}</b>.
@@ -151,6 +161,9 @@ export const BillingLimit = ({ product }: { product: BillingProductV2Type }): JS
<LemonButton
size="small"
status="danger"
+ loading={removingBillingLimitNextPeriod}
+ tooltip="Remove billing limit for next period"
+ disabledReason={billingLimitConfig.removalDisabledReason}
onClick={() => removeBillingLimitNextPeriod(product.type)}
data-attr={`remove-billing-limit-next-period-${product.type}`}
>
@@ -159,6 +172,12 @@ export const BillingLimit = ({ product }: { product: BillingProductV2Type }): JS
</div>
) : null}
</div>
+ {billingLimitConfig.help && !isEditingBillingLimit ? (
+ <div className="text-xs text-secondary mt-2">{billingLimitConfig.help}</div>
+ ) : null}
+ {billingLimitConfig.currentAboveMaxNotice ? (
+ <div className="text-xs text-secondary mt-2">{billingLimitConfig.currentAboveMaxNotice}</div>
+ ) : null}
</div>
</Form>
)
diff --git a/frontend/src/scenes/billing/BillingProduct.stories.tsx b/frontend/src/scenes/billing/BillingProduct.stories.tsx
index 967448cbe6d9..03f7e9167e46 100644
--- a/frontend/src/scenes/billing/BillingProduct.stories.tsx
+++ b/frontend/src/scenes/billing/BillingProduct.stories.tsx
@@ -1,11 +1,14 @@
import { Meta, StoryObj } from '@storybook/react'
+import { within } from '@testing-library/dom'
+import userEvent from '@testing-library/user-event'
import { mswDecorator, useStorybookMocks } from '~/mocks/browser'
import { billingJson } from '~/mocks/fixtures/_billing'
import { makeBillingWithPlatformAddons } from '~/mocks/fixtures/_billing_platform_addons'
import preflightJson from '~/mocks/fixtures/_preflight.json'
-import { BillingProductV2Type } from '~/types'
+import { BillingProductV2Type, BillingType, StartupProgramLabel } from '~/types'
+import { POSTHOG_CODE_BILLING_LIMIT_MAX, POSTHOG_CODE_USAGE_PRODUCT_KEY } from './billingLimitConfig'
import { BillingProduct } from './BillingProduct'
const meta: Meta = {
@@ -31,6 +34,77 @@ export default meta
type Story = StoryObj<{}>
+const BillingProductStoryFrame = ({ children }: { children: JSX.Element }): JSX.Element => (
+ <div className="w-[960px] max-w-full">{children}</div>
+)
+
+const makePostHogCodeUsageBilling = ({
+ currentLimitUsd,
+ nextPeriodLimitUsd,
+}: {
+ currentLimitUsd: number
+ nextPeriodLimitUsd?: number
+}): { billing: BillingType; product: BillingProductV2Type } => {
+ const sourceProduct = billingJson.products.find(
+ (product) => product.type === 'feature_flags'
+ ) as BillingProductV2Type
+ const product: BillingProductV2Type = {
+ ...sourceProduct,
+ name: 'PostHog Code',
+ headline: 'AI coding agents for your PostHog workspace.',
+ description: 'AI coding agents for automating PostHog work.',
+ usage_key: POSTHOG_CODE_USAGE_PRODUCT_KEY,
+ icon_key: 'IconTerminal',
+ docs_url: 'https://posthog.com/docs/posthog-code',
+ subscribed: true,
+ type: POSTHOG_CODE_USAGE_PRODUCT_KEY,
+ current_amount_usd: currentLimitUsd > POSTHOG_CODE_BILLING_LIMIT_MAX ? '3750.00' : '25.00',
+ projected_amount_usd: currentLimitUsd > POSTHOG_CODE_BILLING_LIMIT_MAX ? '4100.00' : '75.00',
+ projected_amount_usd_with_limit: currentLimitUsd > POSTHOG_CODE_BILLING_LIMIT_MAX ? '3750.00' : '75.00',
+ plans: sourceProduct.plans.map((plan) => ({
+ ...plan,
+ initial_billing_limit: 50,
+ })),
+ }
+ const nextPeriodLimits: Record<string, number | null> =
+ nextPeriodLimitUsd === undefined ? {} : { [POSTHOG_CODE_USAGE_PRODUCT_KEY]: nextPeriodLimitUsd }
+
+ return {
+ product,
+ billing: {
+ ...billingJson,
+ startup_program_label: StartupProgramLabel.Startup,
+ products: [product],
+ custom_limits_usd: {
+ [POSTHOG_CODE_USAGE_PRODUCT_KEY]: currentLimitUsd,
+ },
+ next_period_custom_limits_usd: nextPeriodLimits,
+ },
+ }
+}
+
+const renderPostHogCodeUsageBillingProduct = ({
+ currentLimitUsd,
+ nextPeriodLimitUsd,
+}: {
+ currentLimitUsd: number
+ nextPeriodLimitUsd?: number
+}): JSX.Element => {
+ const { billing, product } = makePostHogCodeUsageBilling({ currentLimitUsd, nextPeriodLimitUsd })
+
+ useStorybookMocks({
+ get: {
+ '/api/billing/': billing,
+ },
+ })
+
+ return (
+ <BillingProductStoryFrame>
+ <BillingProduct product={product} />
+ </BillingProductStoryFrame>
+ )
+}
+
export const BillingProductWithoutAddons: Story = {
render: () => {
useStorybookMocks({
@@ -79,6 +153,32 @@ export const BillingProductWithStandalonePricingAddon: Story = {
},
}
+export const BillingProductPostHogCodeLimit: Story = {
+ render: () =>
+ renderPostHogCodeUsageBillingProduct({
+ currentLimitUsd: 50,
+ }),
+}
+
+export const BillingProductPostHogCodeLimitEditing: Story = {
+ render: () =>
+ renderPostHogCodeUsageBillingProduct({
+ currentLimitUsd: 50,
+ }),
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement)
+ await userEvent.click(await canvas.findByText('Edit limit'))
+ },
+}
+
+export const BillingProductPostHogCodeLimitNextPeriodCapped: Story = {
+ render: () =>
+ renderPostHogCodeUsageBillingProduct({
+ currentLimitUsd: 3750,
+ nextPeriodLimitUsd: 3000,
+ }),
+}
+
export const BillingProductTemporarilyFree: Story = {
render: () => {
useStorybookMocks({
diff --git a/frontend/src/scenes/billing/CodeSeatsSection.tsx b/frontend/src/scenes/billing/CodeSeatsSection.tsx
index 9c2838c2e46a..8e284f44b6ea 100644
--- a/frontend/src/scenes/billing/CodeSeatsSection.tsx
+++ b/frontend/src/scenes/billing/CodeSeatsSection.tsx
@@ -76,8 +76,9 @@ export function CodeSeatsSection(): JSX.Element {
</div>
</div>
<LemonBanner type="info" className="mb-4">
- PostHog Code with usage-based billing is launching shortly. New seats, upgrades, and reactivations are
- no longer available. You can still cancel active seats below.
+ PostHog Code with usage-based billing launched on July 16, 2026, and existing seats expire on the same
+ date. New seats, upgrades, and reactivations are no longer available. You can still cancel active seats
+ below.
</LemonBanner>
<LemonTable
loading={orgSeatsLoading}
diff --git a/frontend/src/scenes/billing/billingLimitConfig.ts b/frontend/src/scenes/billing/billingLimitConfig.ts
new file mode 100644
index 000000000000..4701ca7ebdce
--- /dev/null
+++ b/frontend/src/scenes/billing/billingLimitConfig.ts
@@ -0,0 +1,62 @@
+import { BillingProductV2AddonType, BillingProductV2Type, BillingType } from '~/types'
+
+const MAX_BILLING_LIMIT: number = 50000
+
+export const POSTHOG_CODE_USAGE_PRODUCT_KEY = 'posthog_code_usage'
+export const POSTHOG_CODE_BILLING_LIMIT_MAX: number = 3000
+
+export type BillingLimitConfig = {
+ max: number
+ help: string | null
+ removalDisabledReason: string | null
+ maxExceededError: string
+ currentAboveMaxNotice: string | null
+}
+
+type BillingLimitConfigContext = {
+ billing: BillingType | null
+ product: BillingProductV2Type | BillingProductV2AddonType
+ customLimitUsd: number | null
+ billingLimitNextPeriod: number | null
+}
+
+const DEFAULT_BILLING_LIMIT_CONFIG: BillingLimitConfig = {
+ max: MAX_BILLING_LIMIT,
+ help: null,
+ removalDisabledReason: null,
+ maxExceededError: 'Please enter a number less than 50,000',
+ currentAboveMaxNotice: null,
+}
+
+type BillingLimitConfigResolver = (context: BillingLimitConfigContext) => Partial<BillingLimitConfig> | null
+
+const BILLING_LIMIT_CONFIG_BY_PRODUCT: Record<string, BillingLimitConfigResolver> = {
+ [POSTHOG_CODE_USAGE_PRODUCT_KEY]: ({ billing, customLimitUsd, billingLimitNextPeriod }) => {
+ if (!billing?.startup_program_label) {
+ return null
+ }
+
+ return {
+ max: POSTHOG_CODE_BILLING_LIMIT_MAX,
+ help: 'Code billing limits can be set from $0 to $3,000 per month.',
+ removalDisabledReason: "Code billing limits can't be removed. Set the limit to $0 instead.",
+ maxExceededError: "Code billing limits can't exceed $3,000 per month.",
+ currentAboveMaxNotice:
+ customLimitUsd !== null &&
+ customLimitUsd > POSTHOG_CODE_BILLING_LIMIT_MAX &&
+ billingLimitNextPeriod !== null &&
+ billingLimitNextPeriod <= POSTHOG_CODE_BILLING_LIMIT_MAX
+ ? `Current usage is already above the Code billing limit cap, so this period's limit stays at $${customLimitUsd.toLocaleString()}. The $${billingLimitNextPeriod.toLocaleString()} limit starts next period.`
+ : null,
+ }
+ },
+}
+
+export const getBillingLimitConfig = (context: BillingLimitConfigContext): BillingLimitConfig => {
+ const productConfig = BILLING_LIMIT_CONFIG_BY_PRODUCT[context.product.type]?.(context)
+
+ return {
+ ...DEFAULT_BILLING_LIMIT_CONFIG,
+ ...productConfig,
+ }
+}
diff --git a/frontend/src/scenes/billing/billingLogic.tsx b/frontend/src/scenes/billing/billingLogic.tsx
index 63a94bc7859b..8b2b037d6393 100644
--- a/frontend/src/scenes/billing/billingLogic.tsx
+++ b/frontend/src/scenes/billing/billingLogic.tsx
@@ -324,7 +324,7 @@ export const billingLogic = kea<billingLogicType>([
lemonToast.success('Billing limits updated')
actions.loadBilling()
return parseBillingResponse(response)
- } catch (error: any) {
+ } catch (error: unknown) {
lemonToast.error(
'There was an error updating your billing limits. Please try again or contact support.'
)
diff --git a/frontend/src/scenes/billing/billingProductLogic.ts b/frontend/src/scenes/billing/billingProductLogic.ts
index 27e5d1404cd2..26f30cf90288 100644
--- a/frontend/src/scenes/billing/billingProductLogic.ts
+++ b/frontend/src/scenes/billing/billingProductLogic.ts
@@ -22,6 +22,7 @@ import {
} from '~/types'
import { calculateFreeTier, createGaugeItems, isAddonVisible, isProductVariantPrimary } from './billing-utils'
+import { getBillingLimitConfig } from './billingLimitConfig'
import { billingLogic } from './billingLogic'
import type { billingProductLogicType } from './billingProductLogicType'
import { DATA_PIPELINES_CUTOFF_DATE } from './constants'
@@ -134,6 +135,9 @@ export const billingProductLogic = kea<billingProductLogicType>([
reportSurveyDismissed: (surveyID: string) => ({ surveyID }),
setSurveyID: (surveyID: string) => ({ surveyID }),
setBillingProductLoading: (productKey: string | null) => ({ productKey }),
+ setRemovingBillingLimitNextPeriod: (removingBillingLimitNextPeriod: boolean) => ({
+ removingBillingLimitNextPeriod,
+ }),
initiateProductUpgrade: (
product: BillingProductV2Type | BillingProductV2AddonType,
plan: BillingPlanType,
@@ -241,6 +245,13 @@ export const billingProductLogic = kea<billingProductLogicType>([
setBillingProductLoading: (_, { productKey }) => productKey,
},
],
+ removingBillingLimitNextPeriod: [
+ false,
+ {
+ setRemovingBillingLimitNextPeriod: (_, { removingBillingLimitNextPeriod }) =>
+ removingBillingLimitNextPeriod,
+ },
+ ],
comparisonModalHighlightedFeatureKey: [
null as string | null,
{
@@ -351,7 +362,7 @@ export const billingProductLogic = kea<billingProductLogicType>([
return Number(customLimit)
}
const usageKeyLimit = product.usage_key ? billing?.custom_limits_usd?.[product.usage_key] : null
- return usageKeyLimit ? Number(usageKeyLimit) : null
+ return usageKeyLimit === 0 || usageKeyLimit ? Number(usageKeyLimit) : null
},
],
visibleAddons: [
@@ -407,6 +418,17 @@ export const billingProductLogic = kea<billingProductLogicType>([
return product.usage_key ? (billing?.next_period_custom_limits_usd?.[product.usage_key] ?? null) : null
},
],
+ billingLimitConfig: [
+ (s, p) => [s.billing, p.product, s.customLimitUsd, s.billingLimitNextPeriod],
+ (billing, product, customLimitUsd, billingLimitNextPeriod) => {
+ return getBillingLimitConfig({
+ billing,
+ product,
+ customLimitUsd,
+ billingLimitNextPeriod,
+ })
+ },
+ ],
billingGaugeItems: [
(s, p) => [p.product, s.billing, s.billingLimitAsUsage],
(product, billing, billingLimitAsUsage): BillingGaugeItemType[] => {
@@ -772,31 +794,40 @@ export const billingProductLogic = kea<billingProductLogicType>([
}
},
removeBillingLimitNextPeriod: async ({ productType }) => {
+ actions.setRemovingBillingLimitNextPeriod(true)
try {
await api.update('api/billing', { reset_limit_next_period: productType })
lemonToast.success('Billing limit for next period has been removed.')
- } catch (e) {
- console.error(e)
+ } catch (error) {
+ console.error(error)
lemonToast.error(
'There was an error removing your billing limit for next period. Please try again or contact support.'
)
} finally {
+ actions.setRemovingBillingLimitNextPeriod(false)
actions.loadBilling()
}
},
})),
- forms(({ actions, props }) => ({
+ forms(({ actions, props, values }) => ({
billingLimitInput: {
errors: ({ input }) => ({
input:
input === null || Number.isInteger(input)
- ? input > 50000
- ? 'Please enter a number less than 50,000'
+ ? input > values.billingLimitConfig.max
+ ? values.billingLimitConfig.maxExceededError
: undefined
: 'Please enter a whole number',
}),
submit: async ({ input }) => {
- if (props.product.current_amount_usd && input < props.product.current_amount_usd) {
+ const currentAmountUsd = props.product.current_amount_usd
+ ? parseFloat(props.product.current_amount_usd)
+ : null
+ const projectedAmountUsd = props.product.projected_amount_usd
+ ? parseFloat(props.product.projected_amount_usd)
+ : null
+
+ if (input !== null && currentAmountUsd !== null && input < currentAmountUsd) {
LemonDialog.open({
maxWidth: '600px',
title: 'Billing limit warning',
@@ -817,7 +848,7 @@ export const billingProductLogic = kea<billingProductLogicType>([
return
}
- if (props.product.projected_amount_usd && input < props.product.projected_amount_usd) {
+ if (input !== null && projectedAmountUsd !== null && input < projectedAmountUsd) {
LemonDialog.open({
maxWidth: '600px',
title: 'Billing limit warning',
diff --git a/products/tasks/backend/presentation/views/seat_api.py b/products/tasks/backend/presentation/views/seat_api.py
index f76591279f7e..889fc60be2c9 100644
--- a/products/tasks/backend/presentation/views/seat_api.py
+++ b/products/tasks/backend/presentation/views/seat_api.py
@@ -28,7 +28,8 @@ from ee.settings import BILLING_SERVICE_URL
PRO_PLAN_PREFIXES = ("posthog-code-200", "posthog-code-pro-")
RETIRED_SEAT_PRODUCT_MESSAGE = (
"You can no longer create, upgrade, or reactivate PostHog Code seats. "
- "PostHog Code with usage-based billing is launching shortly."
+ "PostHog Code with usage-based billing launched on July 16, 2026, "
+ "and existing seats expire on the same date."
)
RETIRED_SEAT_PRODUCTS = {"posthog_code": RETIRED_SEAT_PRODUCT_MESSAGE}
diff --git a/products/tasks/backend/tests/test_seat_api.py b/products/tasks/backend/tests/test_seat_api.py
index 7356beb5fd10..5619ec635b0a 100644
--- a/products/tasks/backend/tests/test_seat_api.py
+++ b/products/tasks/backend/tests/test_seat_api.py
@@ -262,7 +262,8 @@ class TestSeatAPIRetiredProducts(BaseSeatAPITest):
assert response.json() == {
"error": (
"You can no longer create, upgrade, or reactivate PostHog Code seats. "
- "PostHog Code with usage-based billing is launching shortly."
+ "PostHog Code with usage-based billing launched on July 16, 2026, "
+ "and existing seats expire on the same date."
),
"code": "seat_product_retired",
}