Repository navigation
fix(observability): use genai_prices_cost API for outbound cost logging - #5
Merged
Merged
Conversation
…ogging
``_extract_usage_fields`` was importing ``get_cost_calculator`` from
``fireflyframework_agentic.observability.cost`` -- a symbol that does
not exist on the current agentic main (the module exports
``CostContext`` + ``genai_prices_cost`` now; the calculator-style
helper was retired when the resolver chain split into
``cost/resolvers.py``).
The import lived inside a broad ``try / except: pass`` (cost telemetry
is opt-in), so the symbol error was swallowed silently. The visible
symptom: every ``outbound_call`` log line was missing the ``cost_usd=``
field, and the response's ``usage.total_cost_usd`` always came back
as zero. The pricing unit test continued to pass because it already
uses the new API.
Switch to the same surface the test uses:
cost = genai_prices_cost(CostContext(
model=...,
input_tokens=...,
output_tokens=...,
cache_creation_tokens=...,
cache_read_tokens=...,
))
Verified live against the docker compose stack with
``claude-sonnet-4-6`` on the escritura PDF: every ``outbound_call``
now carries ``cost_usd=…`` and a full run reports the real total
(~\$0.98 for a cache-creation pass; subsequent runs within the
5-minute cache TTL drop an order of magnitude via ``cache_read``).
ancongui
added a commit
that referenced
this pull request
May 31, 2026
…ogging (#5) ``_extract_usage_fields`` was importing ``get_cost_calculator`` from ``fireflyframework_agentic.observability.cost`` -- a symbol that does not exist on the current agentic main (the module exports ``CostContext`` + ``genai_prices_cost`` now; the calculator-style helper was retired when the resolver chain split into ``cost/resolvers.py``). The import lived inside a broad ``try / except: pass`` (cost telemetry is opt-in), so the symbol error was swallowed silently. The visible symptom: every ``outbound_call`` log line was missing the ``cost_usd=`` field, and the response's ``usage.total_cost_usd`` always came back as zero. The pricing unit test continued to pass because it already uses the new API. Switch to the same surface the test uses: cost = genai_prices_cost(CostContext( model=..., input_tokens=..., output_tokens=..., cache_creation_tokens=..., cache_read_tokens=..., )) Verified live against the docker compose stack with ``claude-sonnet-4-6`` on the escritura PDF: every ``outbound_call`` now carries ``cost_usd=…`` and a full run reports the real total (~\$0.98 for a cache-creation pass; subsequent runs within the 5-minute cache TTL drop an order of magnitude via ``cache_read``). Co-authored-by: ancongui <andres.contreras@soon.es>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Outbound logging was importing a retired
get_cost_calculatorsymbol fromfireflyframework_agentic.observability.cost; the ImportError got swallowed by the surrounding try/except, so everyoutbound_callline came back withoutcost_usd=and the response's aggregatedusage.total_cost_usdalways read zero. Switch to the current API (CostContext+genai_prices_cost), the same surface the existing pricing test already exercises. Verified live againstclaude-sonnet-4-6on the docker stack: each call now logs the real cost (~$0.98 total per cache-creation pass; subsequent runs within the 5-min TTL drop ~10x via cache_read).