-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[NA] [BE] Video: Add Cost Tracking for Video Models #3995
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds cost tracking support for video generation models (OpenAI Sora and Google Veo3). The implementation introduces video-specific pricing calculations based on video duration in seconds, extending the existing cost calculation framework.
Key Changes:
- Adds video output price field to ModelPrice record
- Implements video generation cost calculator using duration-based pricing
- Updates cost service to detect and handle video generation models
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| CostServiceTest.java | Adds test coverage for video generation cost calculation using duration |
| SpanCostCalculator.java | Implements videoGenerationCost method for duration-based pricing |
| ModelPrice.java | Extends record with videoOutputPrice field |
| CostService.java | Updates model price parsing to handle video generation mode and pricing |
| ModelCostData.java | Adds fields for video pricing and mode identification |
apps/opik-backend/src/main/java/com/comet/opik/domain/cost/CostService.java
Outdated
Show resolved
Hide resolved
Backend Tests Results 284 files 284 suites 50m 33s ⏱️ Results for commit 60cc926. |
|
✅ Test environment is now available! Access Information
The deployment has completed successfully and the version has been verified. |
| BigDecimal videoOutputPrice = Optional.ofNullable(modelCost.outputCostPerVideoPerSecond()) | ||
| .map(BigDecimal::new) | ||
| .orElse(BigDecimal.ZERO); | ||
| String mode = Optional.ofNullable(modelCost.mode()).orElse("text_generation"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we know the possible values here?
| BiFunction<ModelPrice, Map<String, Integer>, BigDecimal> calculator = SpanCostCalculator::defaultCost; | ||
| if (cacheCreationInputTokenPrice.compareTo(BigDecimal.ZERO) > 0 | ||
| || cacheReadInputTokenPrice.compareTo(BigDecimal.ZERO) > 0) { | ||
| calculator = PROVIDERS_CACHE_COST_CALCULATOR.getOrDefault(provider, | ||
| SpanCostCalculator::textGenerationCost); | ||
| } else if (inputPrice.compareTo(BigDecimal.ZERO) > 0 || outputPrice.compareTo(BigDecimal.ZERO) > 0) { | ||
| calculator = SpanCostCalculator::textGenerationCost; | ||
| } | ||
| if ("video_generation".equalsIgnoreCase(mode) && videoOutputPrice.compareTo(BigDecimal.ZERO) > 0) { | ||
| calculator = SpanCostCalculator::videoGenerationCost; | ||
| } else | ||
| if (cacheCreationInputTokenPrice.compareTo(BigDecimal.ZERO) > 0 | ||
| || cacheReadInputTokenPrice.compareTo(BigDecimal.ZERO) > 0) { | ||
| calculator = PROVIDERS_CACHE_COST_CALCULATOR.getOrDefault(provider, | ||
| SpanCostCalculator::textGenerationCost); | ||
| } else | ||
| if (inputPrice.compareTo(BigDecimal.ZERO) > 0 || outputPrice.compareTo(BigDecimal.ZERO) > 0) { | ||
| calculator = SpanCostCalculator::textGenerationCost; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make it a factory?
Details
This PR adds cost tracking support for video generation models (OpenAI Sora and Google Veo3). The implementation introduces video-specific pricing calculations based on video duration in seconds, extending the existing cost calculation framework.
Key Changes:
Change checklist
Issues
Testing
n.a see #3993 for SDK testing to push trace for cost.
Documentation
n.a
Example