Skip to content

Track usage and estimate cost for calls - #183

Merged
jnu merged 3 commits into
mainfrom
pricing
Jul 10, 2026
Merged

Track usage and estimate cost for calls#183
jnu merged 3 commits into
mainfrom
pricing

Conversation

@jnu

@jnu jnu commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Tracking API usage from responses, and use it to estimate API costs. Both usage and cost estimation must be requested and are not enabled by default on pipeline runs.

These data are not intended to be used in production pipeline runs (since cost is much more accurate and easier to track in the production deployments on Azure), but rather intended to be used to form benchmarks to inform upgrades, particularly model version upgrades.

Comment thread bc2/core/common/openai.py Fixed
Comment on lines +229 to +232
continue
if not _matches_deployment_type(name, deployment_type):
continue
if not _matches_context_tier(name, context_tier):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: _select_unique_price can return a non-deterministic meter when multiple Azure items share the same price, as it returns matches[0] without a stable sort.
Severity: LOW

Suggested Fix

To ensure deterministic results, either modify the OData filter to include isPrimaryMeterRegion eq true when querying the Azure Retail Prices API, which would select the primary meter. Alternatively, if multiple meters must be considered, apply a deterministic sort to the matches list based on a stable key (e.g., meterName) before returning matches[0]. This will guarantee consistent metadata in the cost estimation reports.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: bc2/core/common/azure_pricing.py#L229-L232

Potential issue: The `_select_unique_price` function may exhibit non-deterministic
behavior. When the Azure Retail Prices API returns multiple items with the same price
and unit of measure but different `meterName` values, the function returns the first
element (`matches[0]`) from a list derived from a set. The order is not guaranteed,
leading to inconsistent `meter_name` metadata in the cost estimate report across
different runs for the same operation. While the estimated cost remains correct, the
associated metadata becomes arbitrary, which can cause confusion in reporting and
auditing for benchmarking purposes. The code does not filter for the primary meter
region, which is a common cause for such duplicate-priced items from the API.

Did we get this right? 👍 / 👎 to inform future reviews.

jnu and others added 2 commits July 10, 2026 13:05
…ring sanitization'

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@jnu
jnu merged commit 1061e4b into main Jul 10, 2026
4 of 5 checks passed
@jnu
jnu deleted the pricing branch July 10, 2026 17:10
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.

2 participants