Skip to content

fix(observability): use genai_prices_cost API for outbound cost logging - #5

Merged
ancongui merged 1 commit into
mainfrom
fix/cost-resolver-api
May 14, 2026
Merged

ancongui merged 1 commit into
mainfrom
fix/cost-resolver-api

Conversation

@ancongui

Copy link
Copy Markdown
Contributor

Outbound logging was importing a retired get_cost_calculator symbol from fireflyframework_agentic.observability.cost; the ImportError got swallowed by the surrounding try/except, so every outbound_call line came back without cost_usd= and the response's aggregated usage.total_cost_usd always read zero. Switch to the current API (CostContext + genai_prices_cost), the same surface the existing pricing test already exercises. Verified live against claude-sonnet-4-6 on 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).

…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
ancongui merged commit b815823 into main May 14, 2026
4 checks passed
@ancongui
ancongui deleted the fix/cost-resolver-api branch May 14, 2026 21:58
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant