: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(llma): correct gemini-3-pro-image cost undercounted 10x (#59179)
Carlos Marchal7258905f7b62
diff --git a/nodejs/src/ingestion/ai/costs/provider-matching.test.ts b/nodejs/src/ingestion/ai/costs/provider-matching.test.tsindex efe3548f9a5d..35105d78f266 100644--- a/nodejs/src/ingestion/ai/costs/provider-matching.test.ts+++ b/nodejs/src/ingestion/ai/costs/provider-matching.test.ts@@ -453,6 +453,21 @@ describe('resolveModelCostForProvider()', () => {expect(result!.provider).toBe('deepinfra-turbo')})+ it('partial matches against the canonical alias key, not just the raw provider name', () => {+ const costs = createMockCosts({+ default: { prompt_token: 0.000001, completion_token: 0.00001 },+ 'google-ai-studio-global': { prompt_token: 0.000002, completion_token: 0.000012 },+ 'google-vertex-global': { prompt_token: 0.000003, completion_token: 0.000014 },+ })++ const result = resolveModelCostForProvider(costs, 'gemini', 'gemini-3-pro-image-preview')++ expect(result).toBeDefined()+ expect(result!.provider).toBe('google-ai-studio-global')+ expect(result!.cost.prompt_token).toBe(0.000002)+ expect(result!.cost.completion_token).toBe(0.000012)+ })+it('does not partially match when exact match exists', () => {const costs = createMockCosts({openai: { prompt_token: 0.00001, completion_token: 0.00002 },diff --git a/nodejs/src/ingestion/ai/costs/provider-matching.ts b/nodejs/src/ingestion/ai/costs/provider-matching.tsindex daa8f11d0513..7f013ad19405 100644--- a/nodejs/src/ingestion/ai/costs/provider-matching.ts+++ b/nodejs/src/ingestion/ai/costs/provider-matching.ts@@ -156,16 +156,22 @@ export const resolveModelCostForProvider = (}}- // Try partial matching- const partialMatchKey: string | undefined = Object.keys(providerCosts).find((key: string) =>- key.includes(normalizedProvider)- )-- if (partialMatchKey) {- const partialMatch: ResolvedModelCost | undefined = findProviderMatch(partialMatchKey)-- if (partialMatch) {- return partialMatch+ // Search against the canonical key too so regional-only cost records+ // (e.g. `google-ai-studio-global`) still match when the event uses an alias like `gemini`.+ const partialMatchSearches: string[] =+ canonicalKey === normalizedProvider ? [normalizedProvider] : [canonicalKey, normalizedProvider]++ for (const search of partialMatchSearches) {+ const partialMatchKey: string | undefined = Object.keys(providerCosts).find((key: string) =>+ key.includes(search)+ )++ if (partialMatchKey) {+ const partialMatch: ResolvedModelCost | undefined = findProviderMatch(partialMatchKey)++ if (partialMatch) {+ return partialMatch+ }}}}