litellm/tests/unit/llms/custom_httpx
joshua-berri 58d6f30647
fix(anthropic_messages): preserve first-round web search spend logs (#51441)
* fix(anthropic_messages): key the first web search round's spend row by its own upstream reply

A non-streaming /v1/messages request answered through websearch_interception
logged its first model call with that call's usage but the follow-up reply's
id, so both spend rows shared one request_id and the first was dropped by
skip_duplicates. The logged row now takes its id and provider-reported cost
from the same upstream body its usage is parsed from, falling back to the
served id when that body has none.

Refs #49651

* refactor(anthropic_messages): read the upstream reply id after reparsing it

Drop the defensive body helper. transform_response already requires a read
JSON body, so the upstream id and reported cost are now read after it
succeeds, which leaves every existing failure path unchanged. Tests gain
return annotations and use the current Sonnet model name.

Refs #49651

* fix(anthropic_messages): key by the upstream reply only when a follow-up was served

Keying every reparsed /v1/messages row by its upstream reply overrode an id a
post-call deployment hook deliberately replaced. The anthropic agentic
executor now records on the outer logging object that it served a follow-up's
reply, and only then does that call's spend row take its id and reported cost
from its own upstream reply.

Refs #49651

* test(anthropic_messages): pin the agentic follow-up row test to a fixed start time

Refs #49651

---------

Co-authored-by: Joshua Valluru <326636767+joshua-berri@users.noreply.github.com>
2026-11-12 12:01:42 -08:00
..
__init__.py
test_aiohttp_cleanup_closed.py refactor(llms): expose public names for private provider helpers (#45037) 2026-10-07 08:49:25 -07:00
test_aiohttp_handler.py fix(http): diagnose aiohttp connection pool saturation (#49499) 2026-10-31 16:12:30 -07:00
test_aiohttp_so_keepalive.py refactor(llms): expose public names for private provider helpers (#45037) 2026-10-07 08:49:25 -07:00
test_aiohttp_transport.py fix(aiohttp): bill the usage a stream sent before its connection dropped, and deflake the CyberArk override test (#47838) 2026-10-30 21:18:02 -07:00
test_asgi_handler.py
test_async_client_cleanup.py test: move 76 live top-level tests to offline unit and integration coverage (#45352) 2026-10-08 10:33:35 -07:00
test_container_handler.py test: catch regressions in the validation lines #44798 added (#47420) 2026-10-20 01:06:37 +00:00
test_credential_leak_prevention.py
test_gemini_session_leak.py test(unit): stop test modules from putting their own directory on sys.path (#43421) 2026-09-28 12:20:20 -07:00
test_http2_connection_spread.py feat(vertex_ai)!: use HTTP/2 httpx client for search_api vector store (#40631) 2026-10-29 10:31:18 -07:00
test_http_handler.py feat(replicate): add video generation, image generation and text to speech through the predictions API (#51360) 2026-11-12 08:44:50 -08:00
test_llm_http_handler.py fix(anthropic_messages): preserve first-round web search spend logs (#51441) 2026-11-12 12:01:42 -08:00
test_mock_transport.py
test_sse_lines.py fix(streaming): keep merged think tags balanced and split SSE lines only on CR/LF (#48755) 2026-10-28 17:00:29 -07:00