Skip to content

fix: price AI usage by configured provider type - #27836

Merged
ssncferreira merged 1 commit into
mainfrom
ssncf/price-configured-provider-type
Aug 4, 2026
Merged

fix: price AI usage by configured provider type#27836
ssncferreira merged 1 commit into
mainfrom
ssncf/price-configured-provider-type

Conversation

@ssncferreira

@ssncferreira ssncferreira commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Problem

AI Gateway records the aibridge provider on each interception, which is the upstream wire format and only ever anthropic, openai, or copilot. Prices are matched on exact provider and model equality, so a provider configured as Azure, Bedrock, Google, OpenRouter, or Vercel is priced as if it were native OpenAI or Anthropic, matching either the wrong price or no price at all.

Changes

  • Resolve the configured provider type from ai_providers by provider name, which is unique among live providers, and key the price lookup on it instead of the aibridge provider. No schema change is needed.
  • Label unpriced_token_usage_records_total with the same provider value used for the lookup, so it names a provider an operator actually configured.
  • Treat a provider that cannot be resolved as unpriced, consistent with how a missing price is handled today.

Closes https://linear.app/codercom/issue/AIGOV-570/resolve-ai-model-prices-using-the-configured-provider-type
Depends on the follow-up that extends the shipped price book to the remaining provider types: https://linear.app/codercom/issue/AIGOV-571/ship-prices-for-all-ai-governance-provider-types

Note

Initially generated by Claude Opus 5, modified and reviewed by @ssncferreira

Copy link
Copy Markdown
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown

Docs preview

Check off each page once it's been reviewed. If a page changes in a later push, its checkbox clears automatically so it gets a fresh look. Pages not yet wired into the docs navigation aren't listed here.

@ssncferreira
ssncferreira force-pushed the ssncf/price-configured-provider-type branch from 18afbe8 to 03d3f3e Compare August 4, 2026 11:45
@ssncferreira
ssncferreira force-pushed the ssncf/price-configured-provider-type branch from 03d3f3e to 7396a58 Compare August 4, 2026 11:45
@linear-code

linear-code Bot commented Aug 4, 2026

Copy link
Copy Markdown

AIGOV-570

@ssncferreira
ssncferreira marked this pull request as ready for review August 4, 2026 11:52

@johnstcn johnstcn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I worry about the number of times this will be hit in practice. But we can monitor on dogfood and adjust if needed.

// The interception records one of three upstream wire formats. Prices are
// keyed on the configured provider type, the provider actually serving the
// request, resolved by provider name. Names are unique among live providers.
provider, err := s.store.GetAIProviderByName(ctx, intc.ProviderName)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is going to be called on every interception?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Per token usage, but this is done async when we receive a response from the upstream provider. Additionally, we have other queries like the ones for effective group resolution: budget.ResolveUserEffectiveGroup that also happen here, and are generally heavier than this.

@ssncferreira
ssncferreira merged commit db88ec3 into main Aug 4, 2026
42 checks passed
@ssncferreira
ssncferreira deleted the ssncf/price-configured-provider-type branch August 4, 2026 13:44
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 4, 2026
@ssncferreira ssncferreira added backport/v2.36 Backport PR targeting release/2.36 cherry-pick and removed backport/v2.36 Backport PR targeting release/2.36 cherry-pick labels Aug 13, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants