Commit Graph
924 Commits
Author SHA1 Message Date
Ishaan Jaffer 0bf3d1f226 test_aaaaazure_tenant_id_auth 2025-10-25 12:26:06 -07:00
Ishaan Jaffer e6b61213ca test_completion_azure_deployment_id 2025-10-25 12:26:06 -07:00
Ishaan Jaffer 762053a8e9 test_model_function_invoke 2025-10-25 12:26:06 -07:00
Ishaan Jaffer 6350c20d9f test_azure_streaming_and_function_calling 2025-10-25 12:19:26 -07:00
Ishaan Jaffer cff70ece5a test_azure_astreaming_and_function_calling 2025-10-25 12:18:53 -07:00
Ishaan Jaffer 214c10f6ef test_completion_cost_databricks_embedding 2025-10-25 11:47:03 -07:00
Ishaan Jaffer e227e8c8a0 mv test_whisper 2025-10-25 11:31:55 -07:00
Ishaan Jaffer 74106589d0 test_completion_azure_ai_gpt_4o_with_flexible_api_base 2025-10-25 11:30:51 -07:00
Ishaan Jaffer ec6c166548 _add_azure_related_dynamic_params 2025-10-25 11:11:36 -07:00
Ishaan Jaffer 0bedf1c0a7 fix tests 2025-10-25 10:19:24 -07:00
Alexsander HamirandGitHub 8c5118195d fix: replace deprecated gemini-1.5-pro-preview-0514 with gemini-2.5-flash-lite in function calling test (#15852) 2025-10-23 11:48:58 -07:00
Ishaan JaffandGitHub 73a23a6c78 [Feat] Add Azure AVA TTS integration (#15749)
* add AzureBaseIssueTokenHandler

* add BaseTextToSpeechConfig

* async_text_to_speech_handler

* add AzureAVATextToSpeechConfig

* add get_provider_text_to_speech_config

* add AzureAVATextToSpeechConfig

* fixes for base_llm_http_handler

* fix transform_text_to_speech_request

* test_azure_ava_tts_async

* test_azure_ava_tts_async

* fix TextToSpeechRequestData

* fix transform_text_to_speech_request

* add text_to_speech_handler in LLMHttpHandler

* remove old file

* fix transform_text_to_speech_request

* fix dispatch_text_to_speech

* fix azure TTS

* fix AVA TTS

* fix transform

* fix linting

* ci/cd - use one job for audio testing

* fix tests

* fix llm http handler debugging

* unit tests azure tts

* docs Azure speech

* docs fix

* docs azure AVA

* docs azure AVA

* fix handlers

* test_async_realtime_uses_max_size_parameter
2025-10-20 16:52:23 -07:00
Sameer KankuteandGitHub 1fb798f81d (Bug) Fix JSON serialization error in Helicone logging by removing OpenTelemetry span from metadata (#15728)
* remove span object from helicon metadata

* Add test
2025-10-20 08:53:22 -07:00
f55745fc5e [Fix] Forward anthropic-beta headers to Bedrock, VertexAI (#15700)
* [Fix] Forward anthropic-beta headers to Bedrock and other cross-provider scenarios (#15623)

* add_provider_specific_headers_to_request

* fix add_provider_specific_headers_to_request

* test_provider_specific_header_multi_provider

* test_provider_specific_header_in_request

---------

Co-authored-by: Jack Venberg <jack.venberg@rover.com>
2025-10-18 16:26:32 -07:00
b1b96ff3cf [Perf] Alexsander fixes round 2 - Oct 18th (#15695)
* perf(router): Optimize prompt management model check with early exit

Add early return for models without '/' to avoid expensive get_model_list()
calls for 99% of standard model requests (gpt-4, claude-3, etc).

- Refactor _is_prompt_management_model() with "/" check before model lookup
- Add unit tests to verify optimization doesn't break detection

* perf(caching): optimize Redis batch cache operations and reduce unnecessary queries

This commit introduces several performance optimizations to the Redis caching layer:

**DualCache Improvements (dual_cache.py):**

1. Increase batch cache size limit from 100 to 1000
   - Allows for larger batch operations, reducing Redis round-trips

2. Throttle repeated Redis queries for cache misses
   - Update last_redis_batch_access_time for ALL queried keys, including those
     with None values
   - Prevents excessive Redis queries for frequently-accessed non-existent keys

3. Add early exit optimization
   - Short-circuit when redis_result is None or contains only None values
   - Avoids unnecessary processing when no cache hits are found

4. Optimize key lookup performance
   - Replace O(n) keys.index() calls with O(1) dict lookup via key_to_index mapping
   - Reduces algorithmic complexity in batch operations

5. Streamline cache updates
   - Combine result updates and in-memory cache updates in single loop
   - Only cache non-None values to avoid polluting in-memory cache

**CooldownCache Improvements (cooldown_cache.py):**

1. Enhanced early return logic
   - Check if all values in results are None, not just if results is None
   - Prevents unnecessary iteration when no valid cooldown data exists

These changes significantly improve Redis caching performance, especially for:
- High-throughput batch operations
- Scenarios with frequent cache misses
- Large-scale deployments with many concurrent requests

* fix: remove unnecessary test

* refactor: move default_max_redis_batch_cache_size to constants

- Add DEFAULT_MAX_REDIS_BATCH_CACHE_SIZE constant (default: 1000)
- Update DualCache to use constant from constants.py
- Document new environment variable in config_settings.md

* fix: only use in memory cache when set

* fix(router): improve prompt management model detection with smart early return

The previous early return optimization in _is_prompt_management_model() was
checking if the model name parameter contained '/' and returning False if it
didn't. This broke detection for model aliases (e.g., 'chatbot_actions') that
don't have '/' in their name but map to prompt management models
(e.g., 'langfuse/openai-gpt-3.5-turbo').

Changed the early return logic to only exit early when:
- Model name contains '/' AND
- The prefix is NOT a known prompt management provider

This maintains the performance optimization for 99% of direct model calls
(avoiding expensive get_model_list lookups) while correctly handling:
- Direct prompt management calls (e.g., 'langfuse/model')
- Model aliases without '/' (e.g., 'chatbot_actions')
- Regular models with/without '/' (e.g., 'gpt-3.5-turbo', 'openai/gpt-4')

Fixes test: test_router_prompt_management_factory

* perf(router): optimize _pre_call_checks with shallow copy (1400x faster)

Replace deepcopy with list() in _pre_call_checks - runs on every request.
Only pops from list, never modifies deployment dicts, so shallow copy is safe.

Performance: 1400x faster on hot path
Impact: 2-5x overall throughput improvement for routing workloads
Tests: Added regression test to ensure no mutation + filtering works

* perf(router): replace deepcopy with shallow copy for default deployment

Replace expensive copy.deepcopy() with shallow copy for default_deployment
in _common_checks_available_deployment() hot path.

Changes:
- Use dict.copy() for top-level deployment dict
- Use dict.copy() for nested litellm_params dict
- Only the 'model' field is modified, so deep recursion is unnecessary

Impact:
- 100x+ faster for default deployment path (every request when used)
- deepcopy recursively traverses entire object tree
- Shallow copy only copies two dict levels (exactly what's needed)

Test coverage:
- Added regression test to verify deployment isolation
- Ensures returned deployments don't mutate original default_deployment
- Validates multiple concurrent requests get independent copies

* perf(router): remove unnecessary dict copy in completion hot paths

Remove unnecessary deployment['litellm_params'].copy() in _completion
and _acompletion functions. The dict is only read and spread into a new
dict, never modified, making the defensive copy wasteful.

Changes:
- Remove .copy() in _completion (sync hot path)
- Remove .copy() in _acompletion (async hot path)

Impact:
- Every completion request (highest traffic endpoints)
- Eliminates unnecessary dict allocation and copy on every call
- Dict spreading already creates new dict, so no mutation possible

Test coverage:
- Added tests verifying deployment params unchanged after calls
- Tests both sync and async completion paths
- Validates optimization doesn't introduce mutations

* perf(router): optimize deployment filtering in pre-call checks

Replace O(n²) list pop pattern with O(n) set-based filtering in
_pre_call_checks() to improve routing performance under high load.

Changes:
- Use set() instead of list for invalid_model_indices tracking
- Replace reversed list.pop() loop with single-pass list comprehension
- Eliminate redundant list→set conversion overhead

Impact:
- Hot path optimization: runs on every request through the router
- ~2-5x faster filtering when many deployments fail validation
- Most beneficial with 50+ deployments per model group or high
  invalidation rates (rate limits, context window exceeded)

Technical details:
Old: O(k²) where k = invalid deployments (pop shifts remaining elements)
New: O(n) single pass with O(1) set membership checks

* add: memory profiler

feat(proxy): Add configurable GC thresholds and enhance memory debugging endpoints

- Add PYTHON_GC_THRESHOLD env var to configure garbage collection thresholds
- Add POST /debug/memory/gc/configure endpoint for runtime GC tuning
- Enhance memory debugging endpoints with better structure and explanations
- Add comprehensive router and cache memory tracking
- Include worker PID in all debug responses for multi-worker debugging

* refactor: reduce complexity in get_memory_details endpoint

Extract 6 helper functions from get_memory_details to fix linter
error PLR0915 (too many statements). Improves maintainability
while preserving functionality.

* fix(router): remove incorrect early exit in _is_prompt_management_model

Removes early exit optimization that checked model_name prefix instead
of the actual litellm_params model. This incorrectly returned False for
custom model aliases that map to prompt management providers.

Example: "my-langfuse-prompt/test_id" -> "langfuse_prompt/actual_id"

The method now correctly checks the underlying model's prefix.

Fixes test_is_prompt_management_model_optimization

* fix(proxy): add explicit type annotations to debug_utils dictionaries

Resolved 6 mypy type errors in proxy/common_utils/debug_utils.py by adding
explicit Dict[str, Any] annotations to dictionary variables where mypy was
incorrectly inferring narrow types. This allows the dictionaries to accept
different value types (strings, nested dicts) for error handling and various
return structures.

Fixed:
- Line 246: caches dictionary in get_memory_summary()
- Line 371: cache_stats dictionary in _get_cache_memory_stats()
- Line 439: litellm_router_memory dictionary in _get_router_memory_stats()

* fix(proxy): fix Python 3.8 compatibility in debug_utils type annotations

- Replace tuple[...], list[...] with Tuple[...], List[...] from typing
- Replace Dict | None with Optional[Dict] for Python 3.8 compatibility
- Add missing imports: List, Optional, Tuple to typing imports

Fixes TypeError: 'type' object is not subscriptable in Python 3.8

---------

Co-authored-by: AlexsanderHamir <alexsanderhamirgomesbaptista@gmail.com>
2025-10-18 11:12:00 -07:00
Ishaan Jaffer 732618f55f test_together_ai_embedding 2025-10-11 09:33:19 -07:00
Krish DholakiaandGitHub 12a1d081ee Merge branch 'main' into litellm_dev_09_11_2025_p1 2025-10-08 19:02:58 -07:00
CopilotGitHubcopilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>ishaan-jaff
4226314096 Add native Responses API support for litellm_proxy provider (#15347)
* Initial plan

* Add native Responses API support for litellm_proxy provider

Co-authored-by: ishaan-jaff <29436595+ishaan-jaff@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: ishaan-jaff <29436595+ishaan-jaff@users.noreply.github.com>
2025-10-08 18:31:26 -07:00
Ishaan JaffandGitHub 2f42c806cb [Fix] x-litellm-cache-key header not being returned on cache hit (#15348)
* fix: x-cache-key

* test_cache_key_in_hidden_params_acompletion

* fix: remove_cache_control_flag_from_messages_and_tools
2025-10-08 18:10:43 -07:00
Krish DholakiaandGitHub ad2270fe13 Merge pull request #14764 from daily-kim/litellm_fix_bearer_capitalization
Fix: Authorization header to use correct "Bearer" capitalization
2025-10-03 22:02:46 -07:00
Ishaan JaffandGitHub 10d6d72ae3 [Feat] VertexAI - Support googlemap grounding in vertex ai (#15179)
* add VertexToolName

* test_vertex_tool_params

* fix: working maps grounding

* test_gemini_google_maps_tool_simple

* test_vertex_ai_map_google_maps_tool_with_location

* fix  # noqa: PLR0915

* _extract_google_maps_retrieval_config

* fixes for linting

* docs: **Google Maps**
2025-10-03 16:07:51 -07:00
Ishaan Jaffer f1578b49e2 vertex_httpx_mock_post 2025-09-29 18:25:54 -07:00
Alexsander HamirandGitHub d4830e34e5 fix: remove router inefficiencies (from O(M*N) to O(1)) - 62.5% faster P99 latency (#15046)
* fix: remove redundant deep copy

set_model_list already does the deep copy at the beginning of the call.

* fix: remove unused model_list arguments

The `model_list` parameter was being passed to classes that did not use it.

* fix: reduce per-request memory and time from O(N×M) to O(N)

No need to create a whole array for a simple look up.

* add: missing test

* fix: remove unused parameter
2025-09-29 15:49:46 -07:00
Ishaan Jaffer 6d74f33043 test azure instruct 2025-09-27 15:01:25 -07:00
Ishaan Jaffer a6ea8a5984 test_openai_stream_options_call 2025-09-27 15:01:25 -07:00
Ishaan Jaffer 5077e36f1b test_completion_azure 2025-09-27 15:01:25 -07:00
Ishaan Jaffer 73c32c01a4 test_chat_azure_stream 2025-09-27 15:01:25 -07:00
Krish DholakiaandGitHub f9331ac43e Merge branch 'main' into litellm_ci_cd_linting_fixes_09_29_2025_p2 2025-09-27 14:15:27 -07:00
Krrish Dholakia 77670fa419 fix: fix test 2025-09-27 14:14:40 -07:00
Ishaan Jaffer b97e56252d test_openai_azure_embedding_optional_arg 2025-09-27 14:03:23 -07:00
Ishaan Jaffer 0efb0e2990 test_completion_gemini 2025-09-27 14:00:01 -07:00
Ishaan Jaffer cb2e63621b test_aaparallel_function_call 2025-09-27 13:59:36 -07:00
Ishaan Jaffer 5d04625baa test_aaaaazure_tenant_id_auth 2025-09-27 13:59:17 -07:00
Ishaan Jaffer 04cc292c3f test_completion_base64 2025-09-27 13:58:54 -07:00
Ishaan Jaffer 8223586d1b test_exception_bubbling_up 2025-09-27 13:58:31 -07:00
Ishaan Jaffer 0d786787e0 test_router_mock_request_with_mock_timeout_with_fallbacks 2025-09-27 13:57:43 -07:00
Ishaan Jaffer 81282d14b5 test_async_embedding_openai 2025-09-27 13:03:17 -07:00
Ishaan Jaffer bb4b7fdd00 test_gemini_pro_function_calling_httpx 2025-09-27 12:43:06 -07:00
Ishaan Jaffer 30a3795e78 test_vertex_ai_stream 2025-09-27 12:42:37 -07:00
Ishaan Jaffer 6aa35ec999 test text-embedding-ada-002 2025-09-27 12:41:35 -07:00
Ishaan Jaffer c27beb74b9 test fix 2025-09-27 12:40:34 -07:00
Ishaan Jaffer 919d680e18 test_completion_azure_function_calling_stream 2025-09-27 12:38:18 -07:00
Ishaan Jaffer 9a35d760cf test_async_custom_handler_stream 2025-09-27 12:37:56 -07:00
Ishaan Jaffer 02cc9133a5 test_async_chat_azure_stream 2025-09-27 12:37:36 -07:00
Ishaan Jaffer 9c028c03fb test_bad_request_error_contains_httpx_response 2025-09-27 12:35:59 -07:00
Ishaan Jaffer 973d4b71e7 test_embedding_caching_azure 2025-09-27 12:34:49 -07:00
Ishaan Jaffer 2ba34d22bd test_router_mock_request_with_mock_timeout_with_fallbacks 2025-09-27 12:27:54 -07:00
Ishaan Jaffer 99314221e1 test_router_azure_acompletion 2025-09-27 12:27:34 -07:00
Ishaan Jaffer 4b06d6d6d6 test_provider_budgets_e2e_test 2025-09-27 12:26:40 -07:00
Ishaan Jaffer f7213bacfe test_async_custom_handler_embedding_optional_param 2025-09-27 12:18:17 -07:00