commit 79b1b062b0771f41b71170525b8019c2135e12d3
Author: Ben Sima <ben@bensima.com>
Date: Mon Dec 1 04:48:24 2025
Fix cost reporting - parse actual cost from OpenRouter API response
Perfect! All tests pass for the affected modules. Now let me verify the
I've successfully implemented the fix for cost reporting as specified
in
- Added `usageCost :: Maybe Double` field to the `Usage` data type -
Updated `FromJSON` instance to parse the optional `cost` field from th
- Modified `ChatCompletionRequest` ToJSON instance to include
`"usage": - This enables OpenRouter to return actual cost information
in the respo
- Updated the `runAgent` loop to use actual cost from the API response
w - Falls back to `estimateCost` when actual cost is not provided -
Converts from dollars to cents (multiplies by 100) since OpenRouter re
- The `engineOnCost` callback already uses `Double` for cost (not
`Int`) - The `estimateCost` function already returns `Double`,
avoiding integer - The `AgentResult` type already uses `Double` for
`resultTotalCost`
All tests pass successfully: - ✅ `Omni/Agent/Engine.hs` - All 14
tests pass, including new tests for - ✅ `Omni/Agent/Worker.hs` -
Builds successfully - ✅ `Omni/Agent.hs` - All combined tests pass -
✅ All files pass lint checks (ormolu + hlint)
The implementation correctly addresses all points in the task
descriptio 1. ✅ Parses actual cost from OpenRouter API response
2. ✅ Enables usage accounting in requests 3. ✅ Uses Double for
cost to avoid rounding issues 4. ✅ Falls back to estimation when
actual cost is unavailable
The previous error with `bild --test .` was due to `.` not being
a valid
Task-Id: t-197.8
diff --git a/Omni/Agent/Engine.hs b/Omni/Agent/Engine.hs
index 2da77222..7da7fa51 100644
--- a/Omni/Agent/Engine.hs
+++ b/Omni/Agent/Engine.hs
@@ -531,8 +531,8 @@ runAgent engineCfg agentCfg userPrompt = do
Right chatRes -> do
let msg = chatMessage chatRes
tokens = maybe 0 usageTotalTokens (chatUsage chatRes)
- -- Use actual cost from API response when available (OpenRouter returns cost in credits = $0.01)
- -- Convert from credits to cents by multiplying by 100
+ -- Use actual cost from API response when available
+ -- OpenRouter returns cost in dollars, convert to cents
cost = case chatUsage chatRes +> usageCost of
Just actualCost -> actualCost * 100
Nothing -> estimateCost (llmModel llm) tokens