litellm/tests/test_litellm
Ishaan Jaff 6486db3646
fix: improve streaming proxy throughput by fixing middleware and logging bottlenecks (#21501)
* fix(middleware): replace BaseHTTPMiddleware with pure ASGI middleware

BaseHTTPMiddleware wraps streaming responses with receive_or_disconnect
per chunk, blocking the event loop and causing severe throughput
degradation under concurrent streaming load (53% of CPU in profiling).

Converts PrometheusAuthMiddleware to a pure ASGI middleware using the
__call__(scope, receive, send) protocol.

* fix(streaming): remove expensive debug logging and optimize usage stripping

- Remove print_verbose calls that format chunk/response Pydantic objects,
  triggering millions of __repr__ calls (8% of CPU in profiling)
- Guard remaining verbose_logger.debug with isEnabledFor(DEBUG) and use
  lazy %s formatting instead of f-strings
- Replace usage stripping round-trip (model_dump + delete + reconstruct)
  with a _usage_stripped flag, deferring exclusion to serialization time

* fix(proxy): remove per-chunk debug log and use _usage_stripped flag

- Remove verbose_proxy_logger.debug that formatted every streaming chunk
- Honor _usage_stripped flag from streaming handler to exclude usage
  during model_dump_json serialization instead of reconstructing objects

* fix(proxy): remove per-chunk debug log in async_data_generator

Remove verbose_proxy_logger.debug that formatted every streaming chunk,
which triggered expensive Pydantic serialization on the hot path.

* fix indentation and add clarifying comment for usage stripping

* fix: guard calculate_total_usage against None usage in chunks

* fix: store chunk copy to preserve usage for calculate_total_usage
2026-02-18 16:16:49 -08:00
..
a2a_protocol [Fix] A2a Agent Gateway Fixes - A2A agents deployed with localhost/internal URLs in their agent cards (e.g., http://0.0.0.0:8001/) (#20604) 2026-02-06 15:02:34 -08:00
anthropic_interface/exceptions
caching fix(cache): prevent DualCache async batch check-then-act race (#20986) 2026-02-13 18:32:41 +05:30
completion_extras fix(responses-api): return finish_reason='tool_calls' when response.completed contains function_call items (#19745) 2026-02-16 09:19:57 -08:00
containers fix: add missing OpenAI chat completion params to OPENAI_CHAT_COMPLETION_PARAMS (#21360) 2026-02-16 20:31:21 -08:00
enterprise Fixes based on greptile reviews 2026-02-18 12:19:11 +05:30
expected_responses_api_request [Feat] Adds support for server-side compaction on the OpenAI Responses API context_management (#21058) 2026-02-12 10:00:30 -08:00
experimental_mcp_client
google_genai
images
integrations fix(tests): wrap callbacks cleanup in try/finally and resolve merge conflict 2026-02-18 18:50:17 -03:00
interactions
litellm_core_utils fix(token-counter): fix test isolation and encode() return type normalization 2026-02-17 20:07:52 -03:00
llms fix(tests): resolve merge conflict in test_vertex_ai_rerank_transformation.py 2026-02-18 11:31:56 -03:00
passthrough
proxy fix: improve streaming proxy throughput by fixing middleware and logging bottlenecks (#21501) 2026-02-18 16:16:49 -08:00
responses Merge pull request #21326 from BerriAI/litellm_oss_staging_02_16_2026 2026-02-18 17:47:57 +05:30
router_strategy fix(router): remove repeated provider parsing in budget limiter hot path (#21043) 2026-02-12 20:05:55 -08:00
router_utils Merge main into affinity_callback and address deployment affinity review feedback 2026-02-18 10:01:11 -06:00
secret_managers Merge pull request #20481 from Harshit28j/litellm_aws_rotation_fix 2026-02-12 09:36:10 +05:30
test_router
types Add pipeline flow builder UI for guardrail policies (#21188) 2026-02-13 20:06:03 -08:00
vector_stores
__init__.py
conftest.py fix(tests): restore disable_aiohttp_transport and force_ipv4 in isolate_litellm_state 2026-02-17 21:18:49 -03:00
log.txt
readme.md
test_a2a_registry_lookup.py
test_acompletion_session_reuse_e2e.py
test_add_deployment_no_master_key.py
test_aembedding_session_reuse_e2e.py
test_anthropic_beta_headers_filtering.py Make tests run with local beta header mapping json 2026-02-13 22:31:42 +05:30
test_azure_video_router.py
test_claude_haiku_4_5_config.py
test_claude_opus_4_6_config.py Fix au.anthropic.claude opus 4 6 v1 (#20731) 2026-02-16 14:15:37 -08:00
test_constants.py [Release - 02/10/2026] v1.81.10-nightly 2026-02-10 16:26:30 -08:00
test_container_router.py
test_cost_calculation_log_level.py fix(proxy): fix master key rotation Prisma validation errors (#21330) 2026-02-16 15:13:05 -08:00
test_cost_calculator.py Fix Bedrock service_tier cost propagation (#21172) 2026-02-16 20:30:10 -08:00
test_deepseek_model_metadata.py fix(model-info): sync DeepSeek model metadata and add bare-name fallback (#20885) 2026-02-11 12:48:10 +05:30
test_eager_tiktoken_load.py
test_exception_exports.py fix: export PermissionDeniedError from litellm.__init__ 2026-02-11 13:39:19 +01:00
test_exception_header_preservation.py
test_exception_mapping_request_attribute.py
test_filter_out_litellm_params.py
test_gpt_image_cost_calculator.py
test_groq_streaming_encoding.py
test_lazy_imports.py
test_logging.py fix:Parse embedded JSON in the message field of logs (#20366) 2026-02-10 16:13:33 +05:30
test_lowest_latency_zero_tokens.py
test_main.py Fix : test_video_content_handler_uses_get_for_openai 2026-02-17 20:06:08 +05:30
test_model_param_helper.py
test_model_response_normalization.py
test_nested_drop_params.py
test_redis.py
test_responses_api_bridge_non_stream.py
test_responses_id_security.py
test_router_google_genai.py
test_router_model_cost_isolation.py [Fix] prevent shared backend model key from being polluted by per-deployment custom pricing (#20679) 2026-02-09 19:38:44 -08:00
test_router_per_deployment_num_retries.py
test_router_redis_init.py
test_router_silent_experiment.py
test_router.py fix(router): propagate model-level tags from config to SpendLogs (#20769) 2026-02-10 15:52:52 -08:00
test_service_logger.py fix(proxy): fix master key rotation Prisma validation errors (#21330) 2026-02-16 15:13:05 -08:00
test_shared_session_integration.py
test_ssl_verify_unit.py BUMP Enterprise PIP 2026-02-14 13:40:48 -08:00
test_system_message_format_bug.py
test_utils.py fix(tests): add inference_geo to model prices JSON schema 2026-02-18 11:29:31 -03:00
test_uuid_helper.py
test_video_generation.py Fix : test_video_content_handler_uses_get_for_openai 2026-02-17 20:06:08 +05:30
test_xai_responses_auto_routing.py

Testing for litellm/

This directory 1:1 maps the the litellm/ directory, and can only contain mocked tests.

The point of this is to:

  1. Increase test coverage of litellm/
  2. Make it easy for contributors to add tests for the litellm/ package and easily run tests without needing LLM API keys.

File name conventions

  • litellm/proxy/test_caching_routes.py maps to litellm/proxy/caching_routes.py
  • test_<filename>.py maps to litellm/<filename>.py