fix opencode pricing
Merged
KA
2mo ago+10651+10651+01234567890123456789012345678901234567890123456789-32-32-01234567890123456789
Greptile Summary
This PR centralizes pricing computation into a shared module and adds health check functionality for OpenCode sessions. The main changes extract hardcoded pricing logic from engineer.py into a new pricing.py module with support for multiple models (Claude Sonnet/Opus/Haiku 4.5 and Google Gemini models).
Key changes:
- Created
pricing.pywithcalculate_cost()function andMODEL_PRICINGdictionary - Added health check endpoint call in
opencode_engineer.pyto verify server status before creating sessions - Enhanced UI to display session summaries with token breakdown and costs
- Added OpenCode API documentation files for reference
Critical issue found:
- The
calculate_cost()function accesses pricing dictionary keys directly using bracket notation (pricing["cache_creation"]), which will throw aKeyErrorfor models likegoogle-gemini-3-flashthat don't have all pricing fields defined (missingcache_creation,cache_read,reasoning)
Confidence Score: 2/5
- This PR contains a critical bug that will cause runtime failures for certain models
- The pricing calculation has a KeyError bug that will crash when using Google Gemini models or any future models without complete pricing fields. While the overall refactoring approach is good, this bug must be fixed before merging.
- Pay close attention to
src/reverse_api/pricing.py- thecalculate_cost()function needs to use.get()with defaults instead of direct key access
Important Files Changed
| Filename | Overview |
|---|---|
| src/reverse_api/pricing.py | New pricing module with critical KeyError bug for models missing optional pricing fields |
| src/reverse_api/opencode_engineer.py | Added health check, pricing calculation fallback, and session summary display |
| src/reverse_api/opencode_ui.py | Enhanced UI with health check, model info display, and improved session summary formatting |
| src/reverse_api/engineer.py | Refactored to use shared pricing module for cost calculation |