Skip to content

Conversation

@tatoalo
Copy link
Contributor

@tatoalo tatoalo commented Nov 4, 2025

Problem

PostHog AI team needs to support billing certain LLM generations based on centralized logic that will live in the posthog/hogai repository.

The core idea is simple, add a $ai_billable metadata property that would be signaling, at generation time, wether we should flag it as billable or not.

Changes

  • billable field throughout the LangChain callback handler
  • Metadata extraction
  • Event property capture

Tests

  • unit tests
  • integration tests locally with posthog repo

@tatoalo tatoalo self-assigned this Nov 4, 2025
@tatoalo tatoalo marked this pull request as ready for review November 4, 2025 17:41
@tatoalo tatoalo requested a review from a team November 4, 2025 17:42
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

CHANGELOG.md Outdated
@@ -1,3 +1,7 @@
# 6.7.15 - 2025-11-04

- feat(ph-ai): ai_billing metadata per-generation
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

syntax: Typo: should be ai_billable not ai_billing to match the actual property name used in the code ($ai_billable).

Suggested change
- feat(ph-ai): ai_billing metadata per-generation
- feat(ph-ai): ai_billable metadata per-generation
Prompt To Fix With AI
This is a comment left during a code review.
Path: CHANGELOG.md
Line: 3:3

Comment:
**syntax:** Typo: should be `ai_billable` not `ai_billing` to match the actual property name used in the code (`$ai_billable`).

```suggestion
- feat(ph-ai): ai_billable metadata per-generation
```

How can I resolve this? If you propose a fix, please make it concise.

Copy link
Contributor

@skoob13 skoob13 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we make it useful for customers and for us?

More details: https://github.com/PostHog/posthog/pull/40881/files#r2493990657

@tatoalo tatoalo force-pushed the feat/ph-ai/posthogai-pricing-metadata branch from c56b79b to edc5a47 Compare November 6, 2025 17:41
@tatoalo tatoalo force-pushed the feat/ph-ai/posthogai-pricing-metadata branch from edc5a47 to 72aeea6 Compare November 6, 2025 17:45
@tatoalo tatoalo requested a review from a team November 6, 2025 17:45
Comment on lines 425 to 426
if billable := metadata.get("posthog_ai_billable"):
generation.billable = billable
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still don't understand why we don't allow setting a dictionary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would we need it to be? Previously I did that but I don't see a big reason, we are still looking into the metadata but populating the single field on the client side. Having a dict would either be for all metadata or I don't see a point introducing it for this field honestly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Taking the current path, we add our internal implementation details to the SDK, which has little value and is limiting for customers. You can achieve the desired result by allowing a dictionary to be passed in LangChain's metadata, so anyone else who wants to set similar data, but not the billing props, won't have the same problem you're currently having.

@tatoalo tatoalo requested a review from skoob13 November 10, 2025 12:46
@tatoalo tatoalo force-pushed the feat/ph-ai/posthogai-pricing-metadata branch 2 times, most recently from 3b1874a to 99e4f12 Compare November 10, 2025 18:21
chore(ph-ai): posthog props

chore: fix tests

chore: stuff
@tatoalo tatoalo force-pushed the feat/ph-ai/posthogai-pricing-metadata branch from 99e4f12 to 9c6ec03 Compare November 10, 2025 18:22
@tatoalo tatoalo requested a review from skoob13 November 10, 2025 18:29
Copy link
Contributor

@skoob13 skoob13 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks good. Left a nit, which is up to you.

Copy link
Member

@Twixes Twixes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generalized version looks good

@Twixes Twixes changed the title feat(ph-ai): ai_billable metadata per-generation feat(ph-ai): PostHog properties dict in GenerationMetadata Nov 10, 2025
@tatoalo tatoalo enabled auto-merge (squash) November 11, 2025 17:54
@tatoalo tatoalo merged commit 898654a into master Nov 11, 2025
11 checks passed
@tatoalo tatoalo deleted the feat/ph-ai/posthogai-pricing-metadata branch November 11, 2025 17:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants