Commit Graph
5930 Commits
Author SHA1 Message Date
shin-bot-litellmandGitHub 31241416d4 feat: add base /scim/v2 endpoint for SCIM resource discovery (#20301)
Add the following SCIM v2 discovery endpoints per RFC 7643/7644:

- GET /scim/v2 - Base resource discovery (ListResponse of ResourceTypes)
- GET /scim/v2/ResourceTypes - List all supported resource types
- GET /scim/v2/ResourceTypes/{id} - Get a specific resource type (User/Group)
- GET /scim/v2/Schemas - List all supported schemas
- GET /scim/v2/Schemas/{uri} - Get a specific schema by URI

These endpoints are required by identity providers (Okta, Azure AD, etc.)
for SCIM resource discovery. Previously, GET /scim/v2 returned 404.

Also adds SCIMResourceType, SCIMSchema, and SCIMSchemaAttribute Pydantic
models to the SCIM types module.

Fixes #20295
2026-02-02 14:27:00 -08:00
yuneng-jiangandGitHub f1227ce5a8 Merge pull request #20111 from BerriAI/litellm_sso_map_teams
[Feature] SSO Config Team Mappings
2026-02-02 14:18:25 -08:00
shin-bot-litellmandGitHub 923b1cfd92 fix: MCP "Session not found" error on VSCode reconnect (#20298)
* fix: strip stale mcp-session-id header to prevent 'Session not found' error loop

When VSCode reconnects to LiteLLM's MCP endpoint after a reload, it sends
a stale mcp-session-id header. The session was already cleaned up, causing
a 404 'Session not found' error. VSCode retries with the same stale ID,
creating an infinite error loop.

Before forwarding requests to the StreamableHTTP session manager, check if
the mcp-session-id header references a valid session. If the session doesn't
exist, strip the header so a new session is created automatically.

Fixes #20292

* refactor: extract stale session handling into _strip_stale_mcp_session_header helper
2026-02-02 14:15:31 -08:00
yuneng-jiang 1f51f067eb Merge remote-tracking branch 'origin' into litellm_sso_map_teams 2026-02-02 12:40:12 -08:00
yuneng-jiangandGitHub b30c17c72d Merge pull request #20210 from BerriAI/litellm_key_block_rev
[Fix] Remove Key Blocking on Login
2026-02-02 12:00:26 -08:00
ryan-crabbeandGitHub 7a6820defa perf: cache _get_relevant_args_to_use_for_logging() at module level (#20077)
* perf: cache _get_relevant_args_to_use_for_logging() as module-level frozenset

The set of valid LLM API parameter names for logging was being rebuilt
on every request from 8 OpenAI SDK type annotations + set operations.
Since these are static TypedDict annotations that never change at
runtime, compute once at import time and store as a class-level
frozenset.

Line profiler: get_standard_logging_model_parameters() dropped from
774ms to 77ms across 12K calls (90% reduction, ~25µs/req saved).

* test: add tests for cached ModelParamHelper logging args

Verify cached frozenset matches dynamic computation and that
prompt content keys (messages, prompt, input) are excluded from
logged model parameters.
2026-02-02 10:54:49 -08:00
Sameer Kankute 7329fa8e7a fix: litellm_oss_staging_01_31_2026_3 failing tests 2026-02-02 18:50:58 +05:30
a513cfdefa fix: Set standard_logging_object for pass-through endpoints (#19887)
Pass-through endpoints (like vLLM classify) were not setting
standard_logging_object because _get_assembled_streaming_response
returns None for non-ModelResponse results.

This caused model_max_budget_limiter.async_log_success_event to raise
ValueError('standard_logging_payload is required').

The fix adds an elif branch in async_success_handler that mirrors the
non-pass-through code path.

Co-authored-by: openhands <openhands@all-hands.dev>
Co-authored-by: Krish Dholakia <krrishdholakia@gmail.com>
2026-02-02 18:25:02 +05:30
Nate TessmanandSameer Kankute d7997db912 fix: Include hidden params in chat response to responses api response transformation (#20084)
* Include hidden_params in chat completion to responses transformation

* add tests
2026-02-02 18:24:21 +05:30
Lovro SederandSameer Kankute 726988aed4 Fix Azure AI Anthropic CountTokens 401 auth error (#20069)
Add x-api-key header to CountTokens handler to match chat completion
authentication. Azure AI Anthropic requires this header per Microsoft's
native API format.
2026-02-02 18:24:06 +05:30
Abdullah Habib BiswasandSameer Kankute ef73f330f1 fix: prevent error when max_fallbacks exceeds available models (#20071) 2026-02-02 18:23:53 +05:30
07bffddbfa fix(bedrock): deduplicate toolResult and toolUse blocks in Converse message transformation (#20049)
Bedrock rejects requests when toolResult or toolUse blocks within a
single message contain duplicate IDs. The Converse message transformer
merges consecutive tool/assistant messages without checking for
duplicate toolUseId values, causing BedrockException errors.

Add _deduplicate_bedrock_content_blocks() — a generalized helper that
removes duplicate blocks by ID, logs a warning for each dropped
duplicate via verbose_logger, and preserves non-tool blocks (e.g.
cachePoint). Apply it at all four merge sites (sync/async × toolResult/
toolUse).

The Anthropic /messages path was fixed in PR #19324; this applies the
equivalent fix to the Bedrock Converse path.

Fixes #20048

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-02 18:23:43 +05:30
c9757cd0d7 fix(guardrails): populate applied_guardrails when Model Armor blocks content (#20034)
Previously, when Model Armor guardrail blocked a request/response,
the `applied_guardrails` field was not populated in the logs because
`add_guardrail_to_applied_guardrails_header()` was called after the
HTTPException was raised.

This fix moves the `add_guardrail_to_applied_guardrails_header()` call
to before the blocking check in all hooks:
- async_pre_call_hook (pre_call mode)
- async_moderation_hook (during_call mode)
- async_post_call_success_hook (post_call mode)
- async_post_call_streaming_iterator_hook (streaming)

This ensures that even when a guardrail blocks content, the guardrail
name is properly recorded in the logs for observability.

Added regression tests to verify applied_guardrails is populated when
content is blocked.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-02 18:21:44 +05:30
Harshit JainandSameer Kankute 6d86808eaf feat: enforce model-level TPM/RPM limits (enforce_model_rate_limits) … (#19230)
* feat: enforce model-level TPM/RPM limits (enforce_model_rate_limits) flag

* fix lint errors
2026-02-02 18:18:46 +05:30
Harshit JainandSameer Kankute a457162517 fix: handle deprecated 'redis_db' arg to prevent crash (#19808)
* fix: handle deprecated 'redis_db' arg to prevent crash

* renamed: changed dir
2026-02-02 18:18:05 +05:30
Cesar GarciaandSameer Kankute 61a84e9fdb fix(anthropic-adapter): truncate tool names exceeding OpenAI's 64-char limit (#20107)
When using LiteLLM's Anthropic /v1/messages endpoint to route requests to
OpenAI models, requests fail if any tool name exceeds OpenAI's 64-character
limit. Anthropic API has no such limit, causing compatibility issues.

Changes:
- Add truncate_tool_name() function using {55-char-prefix}_{8-char-hash} format
- Modify translate_anthropic_tools_to_openai() to truncate and return mapping
- Modify translate_anthropic_tool_choice_to_openai() to truncate tool name
- Restore original tool names in responses using the mapping
- Support tool name restoration in streaming responses
- Add backwards-compatible API (existing methods still work)

The fix only applies when routing Anthropic requests to OpenAI models.
Native Anthropic/Claude requests pass through unchanged.
2026-02-02 18:16:07 +05:30
Harshit JainandSameer Kankute 72e5193451 fix: models loadbalancing billing issue by filter (#18891) (#19220)
* fix: models loadbalancing billing issue by filter (#18891)

* fix: models loadbalancing billing issue by filter

* fix: separate key and team access groups in metadata

* fix: lint issues
2026-02-02 18:14:39 +05:30
Aarish AlamandSameer Kankute 3e04e20205 🐛 Bug Fix #19642 : bug in Vertex AI context caching (#19657)
* add vertex tests

* add uperbound

* add pagination tests
2026-02-02 18:13:34 +05:30
ChesarsandSameer Kankute 3215dc4d4e feat(vertex_ai): add global endpoint support for Qwen MaaS models
Fixes #19788

- Add `supported_regions: ["global"]` to Qwen MaaS models in model_prices_and_context_window.json
- Update `get_supported_regions()` to read directly from `model_cost` dict
- Update `get_complete_vertex_url()` to use `get_vertex_region()` for global-only models
- Update `create_vertex_url()` to generate correct URL for global location (without region prefix)
- Add tests for Qwen global endpoint support
2026-02-02 18:13:10 +05:30
Emerson GomesandSameer Kankute bb5397d9b2 fix: enforce scheme for Azure AI rerank api_base 2026-02-02 18:13:04 +05:30
ChesarsandSameer Kankute 11fd92c21b refactor(image-gen): move thought_signature to provider_specific_fields
Per review feedback, thought_signature should not be a root-level
param on ImageObject as it's not OpenAI compatible. Moved to
provider_specific_fields dict to match the pattern used in chat
completions (Message, Delta, Choices, etc).
2026-02-02 18:12:41 +05:30
ChesarsandSameer Kankute b2463291c7 fix(image-gen): add thought_signature to ImageObject for Gemini 3 Pro
Fixes #17184 - Gemini 3 Pro image preview model returns a thoughtSignature
field required for interactive image editing. This change:

- Adds thought_signature field to ImageObject class
- Updates Gemini and Vertex AI transformations to extract thoughtSignature
- Adds test for thought_signature in response transformation
2026-02-02 18:12:28 +05:30
Sameer KankuteandGitHub 27b4052231 Merge pull request #20244 from BerriAI/litellm_nova_sonic_imp_2_feb
[Feat]Add support for nova sonic Speech to speech model
2026-02-02 18:04:02 +05:30
Sameer Kankute bb363f0307 Fix: test_bedrock_optional_params_embeddings_dimension 2026-02-02 17:49:18 +05:30
Sameer Kankute 01cdc272ec Fix: test_bedrock_optional_params_embeddings_dimension 2026-02-02 17:47:20 +05:30
Sameer Kankute be0bb975c0 Fix test_aaamodel_prices_and_context_window_json_is_valid 2026-02-02 17:46:37 +05:30
Sameer KankuteandGitHub dafa26baa6 Merge pull request #20247 from BerriAI/litellm_smoketest_suite
Add Anthropic caching and context tests
2026-02-02 17:45:25 +05:30
Sameer KankuteandGitHub 19f6640309 Merge pull request #20249 from BerriAI/litellm_add_0_budget_model_bypass2
[Feat] Add support for 0 cost models
2026-02-02 17:45:05 +05:30
Sameer KankuteandGitHub 8d65ac62f7 Merge pull request #20254 from BerriAI/litellm_anthropic_reasoning_content
fix: Map reasoning content to anthropic thinking block(streaming+non-streaming)
2026-02-02 17:43:50 +05:30
Sameer Kankute eee737520f fix: Map reasoning content to anthropic thinking block(streaming+non-streaming) 2026-02-02 16:04:13 +05:30
Sameer KankuteandGitHub 1a7fcfb713 Merge pull request #19881 from jayy-77/feat/user-agent-customization-issue-19017
feat: add User-Agent customization support
2026-02-02 15:01:39 +05:30
Sameer Kankute 1f4222e6b2 Add support for 0 cost models 2026-02-02 13:29:37 +05:30
Sameer Kankute 88cb101d88 Add Anthropic caching and context tests 2026-02-02 13:25:47 +05:30
Sameer Kankute cdeefe85ea Add nova sonic tests 2026-02-02 12:18:43 +05:30
Ishaan Jaffer b7e48f1d9e test fix 2026-01-31 19:08:07 -08:00
Ishaan JafferandCursor 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
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 JafferandCursor 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
Ishaan JafferandCursor 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
yuneng-jiang 2e8732c5e0 remove key blocking 2026-01-31 16:46:17 -08:00
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 671fd848da fix: bedrock-converse-claude-sonnet-4.5 2026-01-31 14:41:02 -08:00
shin-bot-litellmandGitHub e2475f4f9a fix(test): correct prompt_tokens in test_string_cost_values (#20185)
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.
2026-01-31 14:23:10 -08:00
Ishaan Jaffer a4acf81286 fix bedrock-nova-premier 2026-01-31 13:44:09 -08:00
Ishaan Jaffer 2e6659d9cb test_embedding fix 2026-01-31 13:43:53 -08:00
db120c524b fix(test): accept both AuthenticationError and InternalServerError in batch_completion test (#20186)
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>
2026-01-31 13:36:27 -08:00
shin-bot-litellm dff7f83e7c fix(proxy): resolve 'multiple values for keyword argument' in batch cancel and file retrieve
- 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)
2026-01-31 21:26:29 +00:00