Commit graph

29986 commits

Author SHA1 Message Date
yuneng-jiang
30f02edb71 remove debugging statements 2026-01-05 16:24:26 -08:00
yuneng-jiang
1b7b42628d Add/update for router_settings in keys / teams 2026-01-05 16:19:42 -08:00
Eric84626
f59e9cef55
Merge branch 'main' into main 2026-01-06 06:57:25 +08:00
YutaSaito
8d40335684
Merge pull request #18670 from BerriAI/litellm_fix_async_client
fix: ensure_async_clients_test error
2026-01-06 07:38:15 +09:00
Yuta Saito
a8092ab4c4 fix: ensure_async_clients_test error 2026-01-06 07:13:13 +09:00
YutaSaito
100f617a8f
Merge pull request #18668 from BerriAI/litellm_feat_noma_mcp_guardrail
[feat] add support MCP guardrail to noma
2026-01-06 07:01:57 +09:00
Yuta Saito
e5b06effda fix: correct incorrect type annotation 2026-01-06 06:38:33 +09:00
YutaSaito
0e9c5739ff
Merge pull request #18669 from BerriAI/litellm_doc_mcp_resources
[docs] mention MCP prompt/resources types in overview
2026-01-06 06:30:54 +09:00
Yuta Saito
bdd95314a7 docs: mention MCP prompt/resources types in overview 2026-01-06 06:29:37 +09:00
Yuta Saito
4eecf59f86 feat: add support MCP guardrail to noma 2026-01-06 06:15:56 +09:00
yuneng-jiang
7937c8674b
Merge pull request #18666 from BerriAI/litellm_keys_create_hour_fix
[Fix] Use timedelta to Calculate Key Expiry on Generate
2026-01-05 12:57:53 -08:00
Akiva Kraines
31430156c7 refactor: Remove incomplete wildcard validation per maintainer feedback
Per maintainer feedback, removed the wildcard validation logic as it doesn't cover
all auth mechanisms (Google, AWS, etc.).

Keeping only the core improvements:
- Enhanced error messages showing deployment/credential used
- Debug logging for pattern-matched deployments

The validation logic needs more work to handle all provider auth mechanisms properly.
2026-01-05 22:26:46 +02:00
yuneng-jiang
c7345e4bfd Use timedelta to calculate key expiry 2026-01-05 12:24:34 -08:00
Urain Ahmad Shah
bf33e639ef
Fix User Invite & Key Generation Email Notification Logic (#18524)
* Fix email notification

* Update email notification tests

* moved test file
2026-01-06 01:35:52 +05:30
drorIvry
b6a64ff99a
feature/ add qualifire guardrails (#18594)
* init guardrails

* init guardrails

* some fixes

* some fixes

* ruff

* some fixes

* some fixes

* some fixes

* some fixes

* some fixes

* some fixes

* docs
2026-01-06 01:34:43 +05:30
Cesar Garcia
0e601d0bfe
Fix: Map Gemini cached_tokens to Langfuse cache_read_input_tokens (#18614)
* Fix: Map Gemini cached_tokens to Langfuse cache_read_input_tokens

Fixes #18520

## Problem
Langfuse integration was not capturing cached tokens from Gemini models.
Gemini returns cached tokens in `usage.prompt_tokens_details.cached_tokens`,
but Langfuse only read from top-level `usage.cache_read_input_tokens`
(which only Anthropic populates).

## Solution
Updated langfuse.py to check both locations:
1. First check top-level cache_read_input_tokens (for Anthropic)
2. Then check prompt_tokens_details.cached_tokens (for Gemini, OpenAI, others)

This ensures all providers' cached tokens are properly reported to Langfuse.

## Changes
- Modified litellm/integrations/langfuse/langfuse.py (lines 742-761)
- Added 3 unit tests in tests/test_litellm/integrations/langfuse/test_gemini_cached_tokens.py
- All existing Langfuse tests still pass (11/11)

## Testing
- test_cached_tokens_extraction: Verifies Gemini cached_tokens extraction
- test_cached_tokens_not_present: Backward compatibility (no cached_tokens)
- test_cached_tokens_is_zero: Edge case when cached_tokens = 0

* Refactor: Extract cache token logic into helper function

Address review feedback from @officer47p

- Created _extract_cache_read_input_tokens() helper function
- Reduces code bloat in _log_langfuse_v2 method
- Improves testability and reusability
- All tests still passing (11/11)
2026-01-06 01:34:09 +05:30
Alexsander Hamir
85a357c7e5
fix: extend case normalization to ALL guardrail types (not just tool_permission) (#18664)
This extends the previous fix to handle capitalized fields across ALL guardrail types,
including Presidio, Azure, Lakera, Bedrock, etc.

Discovery:
- Database investigation revealed the issue affects multiple guardrail types
- Found 4 affected guardrails in staging: 3 Presidio + 1 Azure
- All had default_action: 'Deny' causing the same validation failures
- The initial fix only covered ToolPermissionGuardrailConfigModel

Root Cause (Deeper):
- LitellmParams inherits from 13+ different guardrail config models
- Models use ConfigDict(extra="allow") allowing any field to be set
- Users can set default_action/on_disallowed_action on ANY guardrail type
- Only ToolPermissionGuardrailConfigModel was validating these fields

Solution:
- Added field validators to LitellmParams class (parent of all guardrails)
- Validators run for ALL guardrail types: Presidio, Azure, Bedrock, Lakera, etc.
- Added comprehensive tests covering multiple guardrail types

Changes:
- litellm/types/guardrails.py:
  * Added @field_validator for default_action in LitellmParams
  * Added @field_validator for on_disallowed_action in LitellmParams
  * Added normalization in LitellmParams.__init__ as backup
  * Imported field_validator from pydantic

- tests/test_litellm/types/test_guardrails_case_normalization.py:
  * New test file with 7 tests covering multiple guardrail types
  * Tests verify Presidio, Azure, Tool Permission, Lakera, Bedrock
  * All tests passing

Impact:
- Previous fix: Only tool_permission guardrails protected
- This fix: ALL guardrail types now protected (13+ types)
- Handles both new writes and existing database records
- Tested against actual database with Presidio/Azure guardrails

Testing:
- 7 new cross-guardrail tests (all passing)
- 27 existing tool_permission tests (all passing)
- Verified fix works for real database records
2026-01-05 11:59:00 -08:00
Cesar Garcia
22ae1628e1
Add libsndfile to database Docker image for audio processing (#18612)
The litellm-database Docker image was missing the libsndfile system
library, which is required by the soundfile Python package for audio
file processing. This caused failures when using audio transcription
endpoints that attempt to calculate audio duration.

This adds libsndfile to the runtime dependencies in Dockerfile.database,
consistent with Dockerfile.alpine which already includes this library.
2026-01-06 01:23:30 +05:30
FlibbertyGibbitz
3f4a9d8d08
fix(router): Validate routing_strategy at startup to fail fast with helpful error. (#18624)
Invalid routing_strategy values (e.g., "simple" instead of "simple-shuffle") previously failed silently, causing confusing "No deployments available" errors downstream. This change adds upfront validation in routing_strategy_init() to:

- Check if the provided strategy matches valid string values or RoutingStrategy enum
- Raise a clear ValueError listing valid options if invalid
- Fail fast at startup instead of at request time

Fixes behavior reported in #11330 where users had to debug cryptic errors.

Valid strategies: simple-shuffle, least-busy, usage-based-routing, latency-based-routing, cost-based-routing, usage-based-routing-v2

Co-authored-by: Flibbert E. Gibbitz <flibbertygibbitz@runelabs.ai>
2026-01-06 01:22:09 +05:30
Shivam Rawat
8c21fcb957
added the option of adding langsmith tenant id in the env (#18623) 2026-01-06 01:19:27 +05:30
Krish Dholakia
b5aa7d1838
feat: Add api_key to GenericGuardrailAPI and set x-api-key header (#18647)
Co-authored-by: Cursor Agent <cursoragent@cursor.com>
2026-01-06 01:05:51 +05:30
Alexsander Hamir
0b0a9abd90
fix: normalize case for tool permission guardrail fields to prevent validation errors (#18662)
This fixes a critical issue where capitalized values in tool_permission guardrail
configurations (e.g., "Deny" instead of "deny") caused Pydantic validation errors
during proxy startup, leading to repeated initialization failures and latency issues.

Problem:
- Users could save guardrails with capitalized values through UI/API
- Data was written to database without validation (e.g., default_action: "Deny")
- On proxy startup, loading from DB triggered strict Pydantic validation
- ValidationError caused guardrail initialization to fail in a retry loop
- This resulted in startup delays and repeated error logging

Root Cause:
- Write path had no case normalization
- Read path enforced strict lowercase Literal validation
- Asymmetry between write and read caused latent data corruption

Solution:
Added field validators to normalize case before Pydantic validation:

1. ToolPermissionRule.decision ("allow"/"deny")
   - Normalizes decision field in rules array

2. ToolPermissionGuardrailConfigModel.default_action ("allow"/"deny")
   - Normalizes default fallback action

3. ToolPermissionGuardrailConfigModel.on_disallowed_action ("block"/"rewrite")
   - Normalizes disallowed tool behavior

4. ToolPermissionGuardrail.__init__ normalization
   - Defensive normalization for direct instantiation
   - Ensures normalization regardless of code path

Impact:
- Prevents validation errors during guardrail initialization
- Eliminates startup retry loops and latency issues
- Handles existing database records with capitalized values
- Accepts case-insensitive input from all sources (UI, API, direct calls)
- Fully backward compatible with existing lowercase configurations

Testing:
- Added 3 comprehensive tests for case-insensitive handling
- All 27 existing tests still pass
- Tests verify normalization across all affected fields

Files Changed:
- litellm/types/proxy/guardrails/guardrail_hooks/tool_permission.py
  Added @field_validator decorators for case normalization
- litellm/proxy/guardrails/guardrail_hooks/tool_permission.py
  Added runtime normalization in __init__ method
- tests/test_litellm/proxy/guardrails/guardrail_hooks/test_tool_permission.py
  Added case-insensitive validation tests
2026-01-05 11:24:19 -08:00
Nik
13db8e10dc feat: add display_name, model_vendor, and model_version metadata 2026-01-05 11:01:36 -08:00
Chesars
229d280141 feat(ui): add custom proxy base URL support to Playground
Add ability to configure a custom proxy base URL in the Playground UI,
enabling control plane/data plane architecture where:
- Control Plane: Has UI but LLM APIs disabled (DISABLE_LLM_API_ENDPOINTS=true)
- Data Plane: Has LLM APIs but UI disabled

Changes:
- Add "Custom Proxy Base URL" input field in Playground settings
- Persist custom URL in sessionStorage for user convenience
- Modify getProxyBaseUrl() to check sessionStorage first
- All API calls now route to custom URL when configured

This allows users to run the UI on control plane and point API
calls to a separate data plane endpoint.
2026-01-05 15:36:32 -03:00
Alexsander Hamir
3b847e0d9d
refactor: migrate utils.py lazy imports to registry pattern (#18657)
* refactor: migrate utils.py lazy imports to registry pattern

- Refactored utils.py __getattr__ to use cached registry pattern (similar to __init__.py)
- Added UTILS_MODULE_NAMES tuple and _UTILS_MODULE_IMPORT_MAP to _lazy_imports_registry.py
- Added _get_utils_globals() helper function to _lazy_imports.py
- Added _lazy_import_utils_module() handler function for utils module lazy imports
- Updated _get_lazy_import_registry() to include utils module lazy imports
- Removed redundant _get_utils_globals() from utils.py (now in _lazy_imports.py)
- Added comprehensive tests for utils module lazy imports in test_lazy_imports.py

This refactoring:
- Reduces code duplication (from 670+ lines to ~10 lines in __getattr__)
- Improves maintainability (new lazy imports just need registry entry)
- Maintains consistency with __init__.py lazy import pattern
- All existing functionality preserved and tested

* Fix NameError: get_coroutine_checker not defined in check_coroutine function

* Fix lazy loading for get_coroutine_checker in function_setup and check_coroutine

- Add lazy loading for get_coroutine_checker at start of function_setup to ensure all calls use lazy-loaded version
- Fix check_coroutine function to use lazy loading pattern via getattr
- All direct calls to get_coroutine_checker() now properly use lazy import mechanism
2026-01-05 09:55:48 -08:00
Alexsander Hamir
4d3eb013b4
feat: lazy load DatadogLLMObsInitParams to reduce import time (#18658)
- Added DatadogLLMObsInitParams to TYPES_NAMES in _lazy_imports_registry.py
- Added import map entry for DatadogLLMObsInitParams in _TYPES_IMPORT_MAP
- Moved DatadogLLMObsInitParams import from module level to TYPE_CHECKING block in __init__.py
- Follows existing lazy import patterns for type classes
- Automatically tested by existing test_types_lazy_imports() function
2026-01-05 09:33:35 -08:00
orgersh92
d8d10f5e25
lasso-guardrail-api docs (#18652) 2026-01-05 20:58:26 +05:30
Ishaan Jaffer
f752ec3eaf fix 2026-01-05 20:25:39 +05:30
Ishaan Jaff
2b3b16c86c
[Feat] Litellm UI allow selecting many models for cost estimator (#18653)
* LiteLLM Cost Estimate

* fix - multi model selector

* v2 of report

* fixes

* export fix
2026-01-05 20:19:59 +05:30
Ishaan Jaff
bf1c5bef59
[UI] Add view for estimating costs across requests (#18645)
* add estimate_cost endpoint

* TestCostEstimateEndpoint

* fix estimate_cost

* add /cost/estimate to spend tracking routes

* fix code QA checks

* fixes endpoint

* v0 cost estimator

* v0 cost estimator

* formatNumberWithCommas

* fix admin view

* docs

* docs fix + export PDF/CSV

* fixes for export
2026-01-05 19:19:58 +05:30
Sameer Kankute
d0a26dd4bc
Merge pull request #18644 from BerriAI/litellm_fix_mapped_tests_05012026
Fix mapped tests 05012026
2026-01-05 17:53:17 +05:30
Sameer Kankute
d3107ac61a revert litellm/litellm/llms/gemini/interactions/transformation.py 2026-01-05 17:37:01 +05:30
Sameer Kankute
3c60b930e2
Merge pull request #18635 from BerriAI/litellm_completions_api_summary_param
(feat) Add mapping for reasoning effort to summary param of responses API
2026-01-05 17:36:21 +05:30
Sameer Kankute
30096ffe5c
Merge pull request #18637 from BerriAI/litellm_gemini_api_base_auth_fix
fix: auth header for custom api base in generate Content request
2026-01-05 17:35:47 +05:30
Sameer Kankute
23fa88f64e
Merge pull request #18638 from BerriAI/litellm_fix_custom_llm_providers_ui_testing
fix: Add custom llm provider to get_llm_provider when sent via UI
2026-01-05 17:34:50 +05:30
Sameer Kankute
2d7f0a1351 fix: test_create_simple_string_input 2026-01-05 17:15:12 +05:30
Sameer Kankute
c0f74c994a Fix: test_transform_request_image_extraction 2026-01-05 17:02:54 +05:30
Sameer Kankute
935824e4f9 Fix : test_sap_chat[False] 2026-01-05 16:56:22 +05:30
Costa Tsaousis
196509cbb1
feat(mcp): parallelize tool fetching from multiple MCP servers (#18627)
* feat(mcp): parallelize tool fetching from multiple MCP servers

Replace sequential tool fetching with asyncio.gather() to reduce
client timeouts when using multiple MCP servers.

Changes:
- mcp_server_manager.py: list_tools() now fetches tools in parallel
- server.py: _get_tools_from_mcp_servers() now fetches tools in parallel

Real-world impact (7 MCP servers example):
- Sequential: ~4.5+ seconds (exceeds typical 5-second client timeouts)
- Parallel: ~1.2 seconds (max of all servers)

Fixes #18626

* fix: copy oauth2_headers to avoid shared dict mutation in parallel tasks
2026-01-05 16:54:24 +05:30
Ishaan Jaff
7f4dba2a01
[Feat] Add Cost Estimator for AI Gateway (#18643)
* add estimate_cost endpoint

* TestCostEstimateEndpoint

* fix estimate_cost

* add /cost/estimate to spend tracking routes

* fix code QA checks

* fixes endpoint
2026-01-05 16:51:23 +05:30
Sameer Kankute
840617de73 fix: tests.test_litellm.interactions.test_gemini_interactions.TestGeminiInteractions 2026-01-05 16:41:24 +05:30
Matt Greathouse
b24156079f
Add gemini-3-flash on openrouter (#18247) 2026-01-05 16:37:23 +05:30
Sameer Kankute
d590c820c2 Fix: TypeError: Object of type function is not JSON serializable 2026-01-05 16:32:21 +05:30
Sameer Kankute
28c7659d3d
Potential fix for code scanning alert no. 3954: Clear-text logging of sensitive information
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
2026-01-05 16:06:10 +05:30
YutaSaito
165d5f3af1
Merge pull request #18640 from BerriAI/litellm_fix_cloudzero_integration_test
tests: mock LiteLLM_UserTable for CloudZero export
2026-01-05 17:41:22 +09:00
YutaSaito
d5e4a43be3
Merge pull request #18639 from BerriAI/litellm_feat_mcp_global_mode
[feat] mcp global mode
2026-01-05 17:34:06 +09:00
Yuta Saito
bdc35b4cd2 tests: mock LiteLLM_UserTable for CloudZero export 2026-01-05 17:23:04 +09:00
Yuta Saito
ef2f76e5a5 fix: npm build error 2026-01-05 17:06:02 +09:00
Yuta Saito
7213f4a690 chore: lint 2026-01-05 16:57:39 +09:00
Yuta Saito
fee9553c51 feat: add allow_all_keys doc 2026-01-05 16:56:19 +09:00