PostHog / PostHog/posthog

feat(billing): generic partner billing provider for marketplace partners

Open
#57,482 1 comment 0 reactions 1 assignee View on GitHub

@MattBro is already working on this.

Since May 4, 2026.

enhancement
Dominant language
Python
Stars
39.9k
Forks
3.4k
Avg merge
7h 27m
Merged PRs (30d)
222

Description

Problem

Partner platforms increasingly want to front the billing relationship for their users — they receive invoices and usage from PostHog, collect from their users on their own billing infrastructure, and pay PostHog out-of-band per the marketplace contract. This is the "Vercel for Platforms" pattern.

Vercel uses this model today via a one-off VercelClient in the billing service. As more partners ask for the same shape, we need to lift the Vercel-specific implementation into a generic MarketplaceBillingProviderClient abstraction so adding the next partner is config + a registration flag, not net-new infrastructure.

Goal

A single BillingProviderClient shape any marketplace partner can plug into:

  • Wire up via partner's CIMD registration (or admin) by setting provisioning_billing_provider on the OAuthApplication
  • On Customer creation during agentic provisioning, stamp the right provider on the customer record (immutable, matches existing Vercel contract)
  • Billing pipeline dispatches every per-customer invoice and usage submission through that provider's client

Scope

  • Core abstraction — extract MarketplaceBillingProviderClient base from VercelClient. Re-implement Vercel as an instance of the generic shape, no behavior change for Vercel.
  • Generic invoice submission webhook — child issue, see sub-issues.
  • Generic usage submission webhook — child issue, see sub-issues.
  • Provisioning-side wiringprovisioning_billing_provider: str = "" field on OAuthApplication. Partner registration sets it. Customer creation reads it and stamps Customer.billing_provider.
  • OrganizationIntegration — extensible kind so each new partner has a place to store auth credentials.

Open architectural decision: auth scheme

The biggest unresolved call. PostHog needs to authenticate to the partner's API on every invoice/usage submission. Three reasonable shapes, all already in use somewhere in the PostHog integration ecosystem:

Option How it works Pros Cons
A. OAuth / Bearer (Vercel today) Partner issues access tokens at install time; PostHog stores them in OrganizationIntegration and refreshes as needed Matches Vercel; partner stays in standard OAuth ergonomics Heaviest install ceremony; partner has to host an OAuth server
B. Long-lived API key Partner generates an API key in their admin, gives it to PostHog at provisioning-app registration time; key stored encrypted in OrganizationIntegration Lightest lift on both sides; matches how most SaaS partners issue credentials Key rotation has to be handled manually; no scope hierarchy
C. HMAC outbound PostHog signs each request with a shared secret; partner verifies. Same shape as our inbound HMAC for Stripe-style provisioning Cleanest replay/integrity story; constant-time verification on partner side; no token management Partners that don't already speak HMAC have to build it

Initial lean: B — long-lived API key — for the first new partner. Lowest lift, easy to rotate when needed, degrades cleanly to a slot future partners can fill in. Doesn't preclude offering A or C later as additional supported schemes per partner.

Tracking the decision here rather than splitting to its own issue because the answer determines a chunk of the base class API. Open to input.

First concrete user

Insforge — YC backend-as-a-service for AI coding agents (~25k devs). Met 2026-05-01. They want PostHog to feel native inside their platform with Insforge fronting the billing relationship. They'll be the first partner using the generic shape end-to-end. They want invoice + usage submission so they can show real-time usage in their own UI. Spec for the Insforge-specific surface is internal.

Reference

  • Existing Vercel client: billing/billing_providers/clients/vercel.py
  • Existing Vercel formatter: billing/billing_providers/formatters/vercel.py
  • billing/notes/billing_providers/README.md
  • Provisioning side: posthog/models/oauth.py (provisioning_* fields), ee/api/agentic_provisioning/views.py (Customer creation)

RFC reference

RFC #1077 — Self-serve agentic provisioning platform (merged). Doesn't cover billing-provider integration explicitly; this issue is the natural follow-on for partners that want partner-mediated billing in addition to provisioning.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.