## Problem
Tests using mocked HTTP clients were hitting real APIs because:
1. HTTP client cache was returning previously cached real clients
2. isinstance checks failed due to module identity issues from sys.path
### Tests affected:
- test_send_email_missing_api_key
- test_send_email_multiple_recipients (resend & sendgrid)
- test_search_uses_registry_credentials
- test_vector_store_create_with_simple_provider_name
- test_vector_store_create_with_provider_api_type
- test_vector_store_create_with_ragflow_provider
- test_image_edit_merges_headers_and_extra_headers
- test_retrieve_container_basic (container API tests)
## Solution
1. Add clear_client_cache fixture (autouse=True) to clear
litellm.in_memory_llm_clients_cache before each test
2. Fix isinstance checks to use type name comparison
(avoids module identity issues from sys.path.insert)
## Why not disable_aiohttp_transport
The default transport is aiohttp, so tests should work with it.
Clearing the cache ensures mocks are used instead of cached real clients.
## Regression
PR #19829 (commit f95572e3ed) added @respx.mock but cached clients
from earlier tests were being reused, bypassing the mocks.
Co-authored-by: shin-bot-litellm <shin-bot-litellm@users.noreply.github.com>
The test had prompt_tokens=1000 but the sum of token details was 1150
(text=700 + audio=100 + cached=200 + cache_creation=150).
This triggered the double-counting detection logic which recalculated
text_tokens to 550, causing the assertion to fail.
Fixed by setting prompt_tokens=1150 to match the sum of details.
The test uses an invalid API key to verify that batch_completion returns
exceptions rather than raising them. However, depending on network conditions,
the error may be:
- AuthenticationError: API properly rejected the invalid key
- InternalServerError: Connection error occurred before API could respond
Both are valid outcomes for this test case.
Co-authored-by: shin-bot-litellm <shin-bot-litellm@users.noreply.github.com>
- batch_endpoints.py: Pop batch_id from data before creating CancelBatchRequest
to avoid duplicate batch_id when data already contains it from earlier cast
- files_endpoints.py: Pop file_id from data before calling afile_retrieve
to avoid duplicate file_id when data was initialized with {"file_id": file_id}
- test_claude_agent_sdk.py: Disable bedrock-nova-premier test as it requires
an inference profile for on-demand throughput (AWS limitation)
Fixes: e2e_openai_endpoints tests (test_batches_operations, test_file_operations)
Fixes: proxy_e2e_anthropic_messages_tests (nova-premier model skip)
The proxy now adds metadata to the request body during processing.
Updated test to compare fields individually and strip metadata from
body comparison.
Fixes litellm_proxy_unit_testing_part2 CI failure.
- Add test_router_acancel_batch.py with mock test for router.acancel_batch()
- Add _acancel_batch to ignored list (internal helper tested via public API)
Fixes CI failure in check_code_and_doc_quality job
hosted_vllm no longer uses the OpenAI client, so these tests
that mock the OpenAI client are not applicable to hosted_vllm.
Removes hosted_vllm from:
- test_openai_compatible_custom_api_base
- test_openai_compatible_custom_api_video
This fixes the failing litellm_mapped_enterprise_tests (metrics/logging) job.
Recent commits added new labels to several Prometheus metrics (model_id, client_ip, user_agent)
but the test assertions weren't fully updated to expect these new labels.
Tests fixed:
- test_async_post_call_failure_hook
- test_async_log_failure_event
- test_increment_token_metrics
- test_log_failure_fallback_event
- test_set_latency_metrics
- test_set_llm_deployment_success_metrics
Labels added to test assertions:
- model_id for token metrics (litellm_tokens_metric, litellm_input_tokens_metric, litellm_output_tokens_metric)
- model_id for latency metrics (litellm_llm_api_latency_metric)
- model_id for remaining requests/tokens metrics
- model_id for fallback metrics
- model_id for overhead latency metric
- client_ip and user_agent for deployment failure/total/success responses
- client_ip and user_agent for proxy failed/total requests metrics
* Add async_post_call_response_headers_hook to CustomLogger (#20070)
Allow CustomLogger callbacks to inject custom HTTP response headers
into streaming, non-streaming, and failure responses via a new
async_post_call_response_headers_hook method.
* async_post_call_response_headers_hook
---------
Co-authored-by: michelligabriele <gabriele.michelli@icloud.com>