Repository navigation
fix(openai): multiply image cost by number of images returned - #1974
todkarsant wants to merge 2 commits into
Conversation
common_image_logic computed the per-image cost but set it on the span without multiplying by len(response.data). Requests with n > 1 reported 1/n of the actual cost. Fixes openlit#1933
Reviewer's GuideImplementationCompute image operation cost by multiplying the per-image price by the actual number of images returned.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
PR Summary by QodoFix OpenAI image cost for multi-image responses
AI Description
Merge Risk
|
Code Review by Qodo🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)
Great, no issues found!Qodo reviewed your code and found no material issues that require reviewTip of the day💡 Did you know, you can turn on the rule miner and Qodo learns your standards from review history |
Linked issuesChecked at commit 38e24c0 #1933 Bug: OpenAI image spans price only one image when `n > 1` · 1 of 1 met
|
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="sdk/python/src/openlit/instrumentation/openai/utils.py" line_range="2009" />
<code_context>
scope._kwargs.get("quality", "standard"),
)
+ image_count = len(scope._response_dict.get("data", []) or [])
+ cost = per_image_cost * max(image_count, 1)
# Common Span Attributes
</code_context>
<issue_to_address>
**Empty results show image charges**
When a successful image response has missing, null, or empty `data`, `max(image_count, 1)` charges for one image, so the span and cost metric report a positive charge despite zero images being returned.
Calculate `cost` using `image_count` without a minimum of one.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 1 finding to address first, and if the image count or per-image price is wrong, the SDK will emit an incorrect total cost in telemetry for those requests. Reverting stops future misreporting, but already-emitted span data remains and may need correction or recomputation.
Blocking findings: sdk/python/src/openlit/instrumentation/openai/utils.py:2009
Summary
common_image_logiccomputed the per-image cost but set it directly on the span without multiplying bylen(response.data)n > 1reported1/nof the actual cost on both the span and thegen_ai.usage.costmetricFixes #1933
Summary by Sourcery
Bug Fixes: