You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With langchain-google-genai (2.1.7 and later, including 4.5.2), usage_metadata.output_tokens already includes the thinking tokens (candidates_token_count + thoughts_token_count), and output_token_details.reasoning repeats them. CallbackHandler._parse_usage_model forwards both unchanged, as $ai_output_tokens and $ai_reasoning_tokens.
Cost ingestion (mustAddReasoningCost in nodejs/src/ingestion/pipelines/ai/costs/output-costs.ts) adds $ai_reasoning_tokens on top of $ai_output_tokens for gemini-2.5-* and gemini-3* models, because the Gemini wrapper reports output as candidates only. Thinking tokens from LangChain Gemini events are therefore priced twice.
Example (from the langchain-google-genai docstring): 49 candidate tokens + 777 thinking tokens, output_tokens: 826. PostHog prices 1603 output tokens instead of 826.
Thinking is on by default for Gemini 2.5 / 3, so this affects every such LangChain or LangGraph call.
Expected
$ai_output_tokens for these events matches what the Gemini wrapper sends (candidates only), with $ai_reasoning_tokens still reported.
Activity
posthog commentedon Nov 24, 2026
PostHog self-driving picked up this issue. Status: Research is done.
Somebody may already be working on it, so ask before you start a fix.
Report (team access only): https://us.posthog.com/project/2/inbox/reports/01a20c86-e1dd-77ad-810b-e9b5c950398a?link_source=github_comment