litellm/tests/unit/integrations/arize
Max Azatian 77880a0653
fix(otel)!: leave out span cost when the price lookup failed (#44187)
* fix(otel): leave out span cost when the price lookup failed

A model missing from the price map gets response_cost 0.0 in the standard logging payload, with response_cost_failure_debug_info set. The OpenInference writer (arize, phoenix, langfuse_otel) and the OTel v2 span data copied that 0.0 into llm.cost.total, litellm.cost.total and langfuse.observation.cost_details, so backends showed the call as free. Skip the cost when the lookup failed, except on cache hits, which are free.

* test(otel): keep the guardrail charge on the guardrail span for unpriced calls

* refactor(otel): type the Arize cost writer input and reuse the cache_hit flag

* fix(otel): keep a billed guardrail fee on an unpriced call's Arize span cost

Only the placeholder 0 is left out when the price lookup failed, so a
guardrail fee LiteLLM billed still reaches Arize, Phoenix, Langfuse OTel
and W&B Weave OTel. Adds unit cases for that fee and a malformed cost.

* fix(arize): leave out the span cost on any failed price lookup, matching OTel v2

* fix(logging): clear a stale cost failure flag when a later pricing succeeds

Stream-start pricing on the request model name can fail and set the cost
failure flag even when the final pricing succeeds (OpenRouter usage.cost,
an Azure deployment name priced from the response model). The new span gate
then dropped a real cost. Each pricing now resets the flag, and
uncached_price restores whatever flag it found.

* test(logging): pin the start time in the stale cost flag tests

---------

Co-authored-by: mateo-berri <277851410+mateo-berri@users.noreply.github.com>
2026-10-20 09:48:47 +00:00
..
__init__.py test: move tests/test_litellm integrations and secret_managers into tests/unit (#43194) 2026-09-25 12:57:07 -07:00
test_arize.py test: move whole-unit legacy test files into tests/unit and delete dead skips (#44807) 2026-10-07 05:02:28 +00:00
test_arize_health_check.py test: move tests/test_litellm integrations and secret_managers into tests/unit (#43194) 2026-09-25 12:57:07 -07:00
test_arize_otel_coexistence.py test: move tests/test_litellm integrations and secret_managers into tests/unit (#43194) 2026-09-25 12:57:07 -07:00
test_arize_phoenix.py fix(otel): put the error message on every failed span status (#44185) 2026-10-20 06:35:47 +00:00
test_arize_utils.py fix(otel)!: leave out span cost when the price lookup failed (#44187) 2026-10-20 09:48:47 +00:00