feat(agent-queue): approximate Devin run cost from tokens (model price map)

Devin's export has tokens but no USD cost; estimate cost_usd from a per-model
$/1M price map (Opus/Sonnet/Haiku) and flag usage_estimated so the dashboard
shows it as approx.
This commit is contained in:
saravanakumardb1 2026-05-31 15:58:35 -07:00
parent c2dbbaf188
commit b8f0369f63

View File

@ -1260,8 +1260,23 @@ parse_usage() {
[[ "${dti:-0}" -gt 0 ]] && echo "tokens_in=$dti"
[[ "${dto:-0}" -gt 0 ]] && echo "tokens_out=$dto"
[[ "${dtc:-0}" -gt 0 ]] && echo "tokens_cached=$dtc"
# NOTE: Devin's export carries token counts but not USD cost; cost_usd is
# left unset (the dashboard shows tokens + model; cost stays blank).
# Devin's export has tokens but no USD cost. Approximate it from a model
# price map ($/1M tokens: input/output/cache-read) and flag it as estimated
# (the dashboard renders it as "approx"). Rates are indicative, edit here.
local pin pout pcache
case "$dmodel" in
*Opus*) pin=15; pout=75; pcache=1.5;;
*Sonnet*) pin=3; pout=15; pcache=0.3;;
*Haiku*) pin=0.8; pout=4; pcache=0.08;;
*) pin=""; pout=""; pcache="";;
esac
if [[ -n "$pin" ]]; then
local dcost
dcost=$(awk -v i="${dti:-0}" -v o="${dto:-0}" -v c="${dtc:-0}" -v pi="$pin" -v po="$pout" -v pc="$pcache" \
'BEGIN{printf "%.4f",(i*pi+o*po+c*pc)/1000000}')
echo "cost_usd=$dcost"
echo "usage_estimated=true"
fi
fi
;;
copilot) : ;; # TODO: GitHub Copilot CLI usage format not yet documented here.