You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Streamed calls: Imp.Usage can't see them, and they carry no estimated_cost #262
What's true now (0.7.0). Two gaps in how usage is recorded for streamed calls. Both were found in the 0.7.0 release fact-check.
Imp.Usage doesn't see streamed calls. A streamed call runs in a separate process (Imp.Streaming.start_program_stream), so Imp.Usage.track/1 wrapped around Imp.collect/3, or around a streamed Imp.call, returns %{}. That's true even when the stream succeeds. Separately, with track_usage, Imp.Predict.call drops its frame on error (lib/imp/predict.ex:93-97), so a failed call's usage never reaches the caller. The usage is on the run's :model_response events and nowhere else.
A streamed call has no estimate.estimated_cost is nil because Imp takes ReqLLM's metadata-handle usage only when no chunk reported any (put_handle_value(:usage, …, :when_missing), lib/imp/clients/req_llm.ex ~2226). The handle does carry priced usage (cost, total_cost and the rest). Merging those priced fields into the chunk usage gives a streamed call the same cost/estimated_cost as the non-streamed call. That was checked with a temporary patch, since reverted.
Target.
Imp.Usage.track reports streamed calls, successful or failed, the same way it reports non-streamed ones.
A streamed call gets estimated_cost when ReqLLM priced it.
Done when.
A test of Imp.Usage.track around Imp.collect records a streamed call's usage and cost, and the same for a stream that failed after usage arrived. Both fail on 0.7.0.
A streamed OpenRouter call through LocalHTTP has cost equal to the provider's figure and estimated_cost equal to the catalog figure.
Triage, 2026-10-08: still open. On main (b736d00), Imp.Predict.call still drops the usage frame on error (lib/imp/predict.ex:93-97). The priced usage on the stream handle is still merged only :when_missing (lib/imp/clients/req_llm.ex:2299). #255 predates this issue and did not cover either gap.
This bears on resident cost accounting. A host that counts spend from Imp.Usage misses streamed and failed calls, and GroveResearch/delven#29 already found that turns cut off at the deadline are recorded as $0.
Activity
deepfates commentedon Oct 8, 2026
Triage, 2026-10-08: still open. On main (b736d00),
Imp.Predict.callstill drops the usage frame on error (lib/imp/predict.ex:93-97). The priced usage on the stream handle is still merged only:when_missing(lib/imp/clients/req_llm.ex:2299). #255 predates this issue and did not cover either gap.This bears on resident cost accounting. A host that counts spend from
Imp.Usagemisses streamed and failed calls, and GroveResearch/delven#29 already found that turns cut off at the deadline are recorded as $0.Count streamed calls in Imp.Usage and give them an estimated cost
Count streamed calls in Imp.Usage and give them an estimated cost (#289)