feat(llma): add $ai_tokens_source property to detect token value overrides#444
Merged
andrewm4894 merged 5 commits intomasterfrom Feb 25, 2026
Merged
feat(llma): add $ai_tokens_source property to detect token value overrides#444andrewm4894 merged 5 commits intomasterfrom
andrewm4894 merged 5 commits intomasterfrom
Conversation
When users pass token properties (e.g. $ai_input_tokens) via
posthog_properties, these override the SDK-computed values. This new
$ai_tokens_source property ("sdk" or "passthrough") lets us distinguish
whether token values came from the SDK or were externally injected,
which is critical for diagnosing cost calculation discrepancies.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ce72100053
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Contributor
posthog-python Compliance ReportDate: 2026-02-25 12:32:53 UTC ✅ All Tests Passed!29/29 tests passed Capture Tests✅ 29/29 tests passed View Details
|
andrewm4894
added a commit
to PostHog/posthog-js
that referenced
this pull request
Feb 25, 2026
Adds "sdk" or "passthrough" to $ai_generation events to flag when token properties are externally overridden via posthogProperties. Mirrors the same change in posthog-python (PostHog/posthog-python#444).
Merged
4 tasks
carlos-marchal-ph
approved these changes
Feb 25, 2026
andrewm4894
added a commit
to PostHog/posthog-js
that referenced
this pull request
Feb 25, 2026
…des (#3147) Adds "sdk" or "passthrough" to $ai_generation events to flag when token properties are externally overridden via posthogProperties. Mirrors the same change in posthog-python (PostHog/posthog-python#444).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
$ai_tokens_sourceproperty ("sdk"or"passthrough") to all$ai_generationevents across sync, async, and streaming capture paths$ai_input_tokens,$ai_output_tokens,$ai_total_tokens, etc.) viaposthog_properties, the property is set to"passthrough"-- otherwise"sdk"Test plan
_get_tokens_sourcehelper (10 parameterized cases covering None, empty, unrelated, and each token key)"sdk"value