Commit graph

31442 commits

Author SHA1 Message Date
Yuneng Jiang
b36e15e06c
chore: fixes 2026-04-04 23:41:20 -07:00
Ishaan Jaffer
ad40eeba2b fix: use async Redis write for cooldown on async call paths
litellm fires both failure_handler (sync) and async_failure_handler for
every call. deployment_callback_on_failure was doing a blocking Redis SET
via _set_cooldown_deployments() on every failure, including from async
request paths — stalling the event loop.

Changes:
- CooldownCache.async_add_deployment_to_cooldown(): new method using
  await self.cache.async_set_cache()
- async_set_cooldown_deployments(): async counterpart to
  _set_cooldown_deployments(), calls the new async cache method
- async_deployment_callback_on_failure(): now also handles cooldown
  writes via await async_set_cooldown_deployments()
- deployment_callback_on_failure(): skips the cooldown write for async
  callers (detected via CallTypes flags in litellm_params) to avoid the
  double Redis write; sync callers keep the existing sync path
- async_routing_strategy_pre_call_checks(): swapped to
  await async_set_cooldown_deployments()
2026-03-19 20:15:41 -07:00
Ishaan Jaffer
4032af34c9 add DD Tracing 2026-03-18 11:02:27 -07:00
yuneng-jiang
27f78084dc
Merge pull request #23882 from Harshit28j/litellm_silent_metrics_v2_patched
patch dev
2026-03-17 12:47:06 -07:00
Harshit28j
a5a6070328 fix: prometheus model_id 2026-03-17 07:16:43 +05:30
Ishaan Jaffer
fd21f55160 refactor(proxy): move DDSpanTagger to its own file litellm/proxy/dd_span_tagger.py 2026-03-17 04:04:05 +05:30
Ishaan Jaffer
4bc8ca12db refactor(proxy): consolidate DD APM tag helpers into DDSpanTagger class 2026-03-17 04:04:05 +05:30
Ishaan Jaffer
916c773df7 feat(proxy): add key_alias, key_hash, requested_model tags to DD APM spans 2026-03-17 04:03:58 +05:30
Harshit28j
f6915872fa fix: ensure metadata isolation for silent model metrics 2026-03-17 01:29:23 +05:30
Harshit28j
777fc5a297 fix: test coverage 2026-03-17 01:29:23 +05:30
Harshit28j
8e852de117 fix: req changes by greptile on test coverage 2026-03-17 01:29:23 +05:30
Harshit28j
162796f532 fix: ensure metadata isolation in silent experiment to prevent metric collision 2026-03-17 01:29:23 +05:30
Harshit28j
70de83a6d8 fix: silent metrics race condition 2026-03-17 01:29:07 +05:30
Harshit Jain
5a547aa857 fix: handles edge case which are blocked by Lock 2026-03-03 07:39:16 +05:30
Ishaan Jaffer
539e9b9524 docs: add in_flight_requests to prometheus metrics and latency troubleshooting 2026-02-27 18:04:15 -08:00
Ishaan Jaffer
03500799be refactor: clean class with static methods, add tests, fix sentinel pattern 2026-02-27 18:04:05 -08:00
Ishaan Jaffer
a9d1ff35b3 feat: add in_flight_requests metric to /health/backlog + prometheus 2026-02-27 18:04:05 -08:00
Ishaan Jaffer
1e936df2b4 _add_dd_apm_tags_for_litellm_call_id 2026-02-26 12:10:15 -08:00
Ishaan Jaff
bbf2c4fd0c [Feat] Add control for setting upperbound on chunk processing time (#22209)
* add LITELLM_MAX_STREAMING_DURATION_SECONDS

* add add LITELLM_MAX_STREAMING_DURATION_SECONDS

* fix: address Greptile review - rename constant, add sync check, add tests

- Rename MAX_STREAMING_CHUNK_DURATION_S → MAX_STREAMING_DURATION_S (misleading "CHUNK")
- Add _check_max_streaming_duration to SyncResponsesAPIStreamingIterator.__next__
- Add 8 unit tests covering both CustomStreamWrapper and ResponsesAPI paths
- Fix pre-existing pyright errors in streaming_handler.py

Made-with: Cursor

* add add LITELLM_MAX_STREAMING_DURATION_SECONDS

Made-with: Cursor
2026-02-26 11:49:42 -08:00
Ishaan Jaffer
699911dfc5 test(router): add regression test for FallbackStreamWrapper _hidden_params preservation 2026-02-24 12:04:55 -08:00
Ishaan Jaffer
de414859f2 fix(router): preserve _hidden_params in FallbackStreamWrapper so x-litellm-overhead-duration-ms is emitted for streaming requests 2026-02-24 12:04:39 -08:00
Ishaan Jaffer
9873ad62fa feat(prometheus): add opt-in stream label to litellm_proxy_total_requests_metric
Set prometheus_emit_stream_label: true in litellm_settings to emit a
stream label (True/False/None) on litellm_proxy_total_requests_metric.

Opt-in to avoid breaking cardinality on existing deployments.
2026-02-24 12:03:22 -08:00
Ishaan Jaffer
bf7e636b95 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.
2026-02-24 12:00:57 -08:00
Ishaan Jaffer
8e46335e16 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
2026-02-24 12:00:57 -08:00
Ishaan Jaffer
2d20d609ad 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
2026-02-24 12:00:02 -08:00
Ishaan Jaffer
7a233d5f06 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.
2026-02-24 12:00:02 -08:00
Ishaan Jaffer
437d504ef0 fix indentation and add clarifying comment for usage stripping 2026-02-24 11:59:46 -08:00
Ishaan Jaffer
a70414d646 fix: guard calculate_total_usage against None usage in chunks 2026-02-24 11:59:15 -08:00
Ishaan Jaffer
dfe719fa7e fix: store chunk copy to preserve usage for calculate_total_usage 2026-02-24 11:59:15 -08:00
michelligabriele
20d3cbfdeb fix: revert httpx client caching that caused closed client errors
AsyncHTTPHandler.__del__ was closing httpx clients still in use by
AsyncOpenAI/AsyncAzureOpenAI due to independent cache lifecycles.
Restores standalone httpx client creation for OpenAI/Azure providers.
2026-02-04 18:45:08 -08:00
shin-bot-litellm
8da3a93e6e docs: Update v1.81.6 release notes - focus on Logs v2 with Tool Call Tracing
- Updated title to highlight Logs v2 feature
- Simplified Key Highlights to focus on Logs v2 / tool call tracing
- Rewrote Logs v2 description with improved language style
- Removed Claude Agents SDK and RAG API from key highlights section
- TODO: Add image (logs_v2_tool_tracing.png)
2026-02-01 03:27:06 +00:00
Ishaan Jaffer
b7e48f1d9e test fix 2026-01-31 19:08:07 -08:00
Ishaan Jaffer
466e6bdcf1 fix(test): make test_proxy_failure_metrics resilient to missing proxy-level metrics
- Check for both litellm_proxy_failed_requests_metric_total and the deprecated litellm_llm_api_failed_requests_metric_total
- The proxy-level failure hook may not always be called depending on where the exception occurs
- Simplify total_requests check to only verify key fields

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-01-31 18:46:27 -08:00
Ishaan Jaffer
92c8e00520 test_proxy_success_metrics 2026-01-31 18:36:22 -08:00
Ishaan Jaffer
faff9d1dc5 test_proxy_failure_metrics 2026-01-31 18:10:17 -08:00
Ishaan Jaffer
35e29c2bcd Revert "Merge pull request #18790 from BerriAI/litellm_key_team_routing_3"
This reverts commit ae26d8e68a, reversing
changes made to 864e8c6543.
2026-01-31 17:58:46 -08:00
shin-bot-litellm
0c006794f1
litellm_fix_mapped_tests_core: fix test isolation and mock injection issues (#20209)
* litellm_fix_mapped_tests_core: fix test isolation and mock injection issues

## Problem
Four tests in litellm_mapped_tests_core were failing:
1. test_register_model_with_scientific_notation - KeyError due to test isolation issues
2. test_search_uses_registry_credentials - Mock not being called due to incorrect patch path
3. test_send_email_missing_api_key - Real API calls despite mocking
4. test_stream_transformation_error_sync - Mock not effective, real API called

## Solution

### test_register_model_with_scientific_notation
- Use unique model name to avoid conflicts with other tests
- Clear LRU caches before test to prevent stale data
- Clean up model_cost entry after test

### test_search_uses_registry_credentials
- Use patch.object() on the actual base_llm_http_handler instance
- String-based patching for instance methods can fail; direct object patching is more reliable

### test_send_email_missing_api_key
- Directly inject mock HTTP client into logger instance
- This bypasses any caching issues that could cause the fixture mock to be ineffective

### test_stream_transformation_error_sync
- Patch litellm.completion directly instead of the handler module's litellm reference
- This ensures the mock is effective regardless of import order

## Regression
These tests were affected by LRU caching added in #19606 and HTTP client caching.

* fix(test): use patch.object for container API tests to fix mock injection

## Problem
test_retrieve_container_basic tests were failing because mocks weren't
being applied correctly. The tests used string-based patching:
  patch('litellm.containers.main.base_llm_http_handler')

But base_llm_http_handler is imported at module level, so the mock wasn't
intercepting the actual handler calls, resulting in real HTTP requests
to OpenAI API.

## Solution
Use patch.object() to directly mock methods on the imported handler
instance. Import base_llm_http_handler in the test file and patch like:
  patch.object(base_llm_http_handler, 'container_retrieve_handler', ...)

This ensures the mock is applied to the actual object being used,
regardless of import order or caching.

* fix(test): add missing Prometheus metric labels to test_proxy_failure_metrics

Add client_ip, user_agent, model_id labels to expected metric patterns.
These labels were added in PRs #19717 and #19678 but test wasn't updated.

* fix(test_resend_email): use direct mock injection for all email tests

Extend the mock injection pattern used in test_send_email_missing_api_key
to all other tests in the file:
- test_send_email_success
- test_send_email_multiple_recipients

Instead of relying on fixture-based patching and respx mocks which can
fail due to import order and caching issues, directly inject the mock
HTTP client into the logger instance. This ensures mocks are always used
regardless of test execution order.

* fix(test): use patch.object for image_edit and vector_store tests

- test_image_edit_merges_headers_and_extra_headers: import base_llm_http_handler
  and use patch.object instead of string path patching
- test_search_uses_registry_credentials: import module and patch via
  module.base_llm_http_handler to ensure we patch the right instance

---------

Co-authored-by: Ishaan Jaff <ishaanjaffer0324@gmail.com>
2026-01-31 17:53:54 -08:00
Ishaan Jaffer
bb3c2a92a0 fix(test): update test_prometheus with masked user_id and missing labels
- Update expected user_id from 'default_user_id' to '*******_user_id' (PII masking)
- Add missing client_ip, user_agent, model_id labels (from PRs #19717, #19678)
- Update label order to match Prometheus alphabetical sorting

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-01-31 17:51:27 -08:00
shin-bot-litellm
93a0631ea3
docs: fix dead links in v1.81.6 release notes (#20218)
- Fix /docs/search/index -> /docs/search (404 error)
- Fix /cookbook/ -> GitHub cookbook URL (404 error)

Co-authored-by: shin-bot-litellm <shin-bot-litellm@users.noreply.github.com>
2026-01-31 17:46:56 -08:00
Ishaan Jaffer
8a57ee5efb docs fix 2026-01-31 17:34:25 -08:00
Ishaan Jaffer
3a3576dfb4 fix: update test_prometheus to expect masked user_id in metrics
The user_id field 'default_user_id' is being masked to '*******_user_id'
in prometheus metrics for privacy. Updated test expectations to match
the actual behavior.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-01-31 17:26:37 -08:00
Ishaan Jaffer
01b96f1272 fixes 2026-01-31 17:15:53 -08:00
Ishaan Jaffer
ecb725f189 fix: delete_file 2026-01-31 16:29:31 -08:00
Ishaan Jaffer
0c785b333b test_chat_completion_low_budget 2026-01-31 16:18:54 -08:00
shin-bot-litellm
37a45a3295
litellm_fix_mapped_tests_core: clear client cache and fix isinstance checks (#20196)
## 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>
2026-01-31 15:42:17 -08:00
Ishaan Jaffer
427d8f4377 bump: version 1.81.5 → 1.81.6 2026-01-31 15:31:35 -08:00
yuneng-jiang
0bf471b071
Merge pull request #20198 from BerriAI/spend_logs_docs
[Doc] Fixing Image
2026-01-31 15:28:50 -08:00
Ishaan Jaffer
d897c5e022 fix team budget checks 2026-01-31 15:28:33 -08:00
yuneng-jiang
93dfac78ed doc fix 2026-01-31 15:27:21 -08:00
Ishaan Jaffer
94d5036a25 fix fake-openai-endpoint 2026-01-31 15:26:16 -08:00