Skip to content

fix(aio): match Bedrock pricing by inference profile - #74380

Merged
trunk-io[bot] merged 2 commits into
PostHog:masterfrom
gouveags:fix/bedrock-inference-profile-pricing
Jul 30, 2026
Merged

fix(aio): match Bedrock pricing by inference profile#74380
trunk-io[bot] merged 2 commits into
PostHog:masterfrom
gouveags:fix/bedrock-inference-profile-pricing

Conversation

@gouveags

Copy link
Copy Markdown
Contributor

Problem

Bedrock events can use a generic $ai_provider while the raw model contains routing information, such as us.anthropic... or a full inference-profile ARN.

After model lookup found the catalog row, provider resolution only used the generic Bedrock provider. It could therefore fall back to the first matching catalog entry instead of the existing regional entry. This can price a US inference profile using Global-equivalent rates.

Closes #74366

This is separate from #71323. That PR corrected Anthropic cache-write pricing after a provider price is selected. This PR corrects the provider selection itself.

Changes

  • Inspect the raw model when the provider is a generic Bedrock alias.
  • Use the raw inference-profile prefix to select an exact catalog provider, or the only regional provider sharing that prefix.
  • Use the AWS region from a full inference-profile ARN when the catalog has an exact regional provider.
  • Keep an explicit provider authoritative.
  • Preserve the current fallback for unknown prefixes, missing catalog entries, unprefixed models, and non-Bedrock providers.
  • Apply the same resolution to both cost lookup paths.

The matcher does not hardcode model names or prices. It only selects among provider rows already present in the catalog.

Note

A profile prefix changes selection only when the matched catalog row contains an exact provider key or one unambiguous regional match. Otherwise, the existing fallback remains unchanged.

How did you test this code?

  • Ran the matcher and provider Jest suites: 2 suites and 131 tests passed.
  • Added regressions for raw US and Global profile IDs, full inference-profile ARNs, explicit-provider precedence, missing regional rows, provider aliases, and non-Bedrock providers.
  • Ran six runtime probes against the real catalog: raw US and Global IDs, an exact ARN region, a missing regional row, an explicit provider override, and a non-Bedrock provider.
  • ESLint and Prettier passed for both changed files.
  • git diff --check passed.

I did not run the full PostHog stack or the full monorepo test suite.

👉 Stay up-to-date with PostHog coding conventions for a smoother review.

Automatic notifications

  • Publish to changelog?
  • Alert Sales and Marketing teams?

Docs update

No docs update. This corrects provider selection for an existing event shape; it adds no fields, configuration, or workflow.

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

I directed the work and used Codex sub-agents and GitHub CLI for research, regression-first tests, implementation, validation, and review. Skills invoked: development-workflow, create-pr, and the repository's /writing-tests skill. No public agent session link is available.

The implementation keeps the existing pricing catalog as the source of truth. It avoids model-specific pricing rules, preserves explicit-provider precedence, and retains the existing fallback when the routing information cannot identify a catalog provider safely.

@trunk-io

trunk-io Bot commented Jul 28, 2026

Copy link
Copy Markdown

😎 Merged successfully - details.

@rafaeelaudibert
rafaeelaudibert requested a review from a team July 28, 2026 21:38
@gouveags
gouveags marked this pull request as ready for review July 28, 2026 21:38
@gouveags

Copy link
Copy Markdown
Contributor Author

@richardsolomou I found this while following the Bedrock pricing path from #71323. The fix keeps the catalog as the source of truth and only uses the raw profile ID when it maps safely to an existing provider row. Would you mind taking a look when you have time?

@gouveags

Copy link
Copy Markdown
Contributor Author

@greptileai review

@pr-assigner-resolver-posthog
pr-assigner-resolver-posthog Bot requested a review from a team July 28, 2026 21:39
@greptile-apps

greptile-apps Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Reviews (1): Last reviewed commit: "fix(aio): match Bedrock pricing by infer..." | Re-trigger Greptile

@gouveags

Copy link
Copy Markdown
Contributor Author

@rafaeelaudibert The PostHog × Tractian meetup in São Paulo was a major catalyst for this contribution. It was great meeting you there, and everyone at MOVEdot is genuinely excited to start contributing back to PostHog. I hope this is the first of many!

Copy link
Copy Markdown
Member

@gouveags loved meeting y'all there! We'd love to get your contributions in.

I can help routing requests to the right teams if GitHub doesn't do it automatically :)

@Radu-Raicea
Radu-Raicea removed the request for review from a team July 29, 2026 12:59
@gouveags

Copy link
Copy Markdown
Contributor Author

/trunk merge

@trunk-io

trunk-io Bot commented Jul 30, 2026

Copy link
Copy Markdown

An error occurred while submitting your PR to the queue: Only users that are a part of this repo's Trunk organization or have write permissions to the repo can submit a PR to the queue

@gouveags

Copy link
Copy Markdown
Contributor Author

Can you guys help with the merge? @richardsolomou or @rafaeelaudibert

@trunk-io
trunk-io Bot merged commit d803311 into PostHog:master Jul 30, 2026
180 checks passed
@deployment-status-posthog

deployment-status-posthog Bot commented Jul 30, 2026

Copy link
Copy Markdown

Deploy status

Environment Status Deployed At Workflow
dev ✅ Deployed 2026-07-30 15:01 UTC Run
prod-us ✅ Deployed 2026-07-30 15:15 UTC Run
prod-eu ✅ Deployed 2026-07-30 15:19 UTC Run

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.

US Bedrock inference-profile events use Global token rates

3 participants