From b8f0369f633d0ef7dd25b295603836eb21e9e4b9 Mon Sep 17 00:00:00 2001 From: saravanakumardb1 Date: Sun, 31 May 2026 15:58:35 -0700 Subject: [PATCH] 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. --- agent-queue/agent-queue.sh | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/agent-queue/agent-queue.sh b/agent-queue/agent-queue.sh index d9d7dec..4a26bfa 100755 --- a/agent-queue/agent-queue.sh +++ b/agent-queue/agent-queue.sh @@ -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.