Commit graph

8121 commits

Author SHA1 Message Date
shin-bot-litellm
9eb71574d8
fix(tests): Fix sendgrid email tests to properly mock httpx client (#20628)
* fix(tests): Fix sendgrid email tests to properly mock httpx client

The tests were potentially hitting the real SendGrid API because the mock
was patching get_async_httpx_client() but the actual client could be cached
or the mock timing could be off.

Fix by directly replacing logger.async_httpx_client after instantiation,
which guarantees the mock is used regardless of caching or initialization
timing issues.

Changes:
- Replace mock_httpx_client fixture with simpler mock_async_client fixture
- Directly inject mock client into logger instance after creation
- Remove respx decorator (no longer needed with direct injection)
- Simplify test structure while maintaining same assertions

* fix(lint): remove unused imports from SendGrid test
2026-02-07 09:19:02 -08:00
Harshit Jain
48b25a00c7
fix tts metrics issues 2026-02-07 09:46:17 +05:30
yuneng-jiang
271877ffb5
Merge pull request #20623 from BerriAI/litellm_user_id_fix
[Fix] /key/list user_id Empty String Edge Case
2026-02-06 18:06:59 -08:00
yuneng-jiang
4d1b5d80ae fixing user_id 2026-02-06 17:55:45 -08:00
Ishaan Jaff
81146472cb
[Feat] MCP Gateway - Allow setting MCP Servers as Private/Public available on Internet (#20607)
* update MCPAuthenticatedUser

* add available_on_public_internet for MCPs

* update claude.md

* init IPAddressUtils

* init available_on_public_internet

* add on REST endpoints

* filter with IP

* TestIsInternalIp

* _extract_mcp_headers_from_request

* init get_mcp_client_ip

* _get_general_settings

* allowed_server_ids

* address PR comments

* get_mcp_server_by_name fix

* fix server

* fix review comments

* get_public_mcp_servers

* address _get_allowed_mcp_servers
2026-02-06 17:51:20 -08:00
michelligabriele
f4a0b80a25
fix(sso): extract user roles from JWT access token for Keycloak compatibility (#20591)
Keycloak (and similar OIDC providers) include role claims in the JWT
access token but not in the UserInfo endpoint response. Previously,
roles were only extracted from UserInfo, causing all SSO users to
default to internal_user_view_only regardless of their actual role.

Changes:
- Extract user roles from JWT access token in process_sso_jwt_access_token()
  when UserInfo doesn't provide them (tries role_mappings first, then
  GENERIC_USER_ROLE_ATTRIBUTE)
- Handle list-type role values in get_litellm_user_role() since Keycloak
  returns roles as arrays (e.g. ["proxy_admin"] instead of "proxy_admin")
- Add 9 new unit tests covering role extraction and list handling
- Update 3 existing tests for new JWT decode behavior

Closes #20407
2026-02-06 16:05:51 -08:00
yuneng-jiang
218373c427
Merge pull request #20205 from BerriAI/litellm_router_search_fix
[Re-issue: Fix] Keys and Teams Router Setting + Allow Override of Router Settings
2026-02-06 15:42:22 -08:00
yuneng-jiang
fd3ca081cc use cached keys and teams for router settings 2026-02-06 15:07:29 -08:00
Ishaan Jaff
b78f4c924c
[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)
* v1 card resolver fix

* fix: is_localhost_or_internal_url

* fix code

* test_fix_agent_card_url_replaces_localhost

* test restruct

* test_a2a_non_streaming

* test agnts

* add exception handling

* init errors

* add localhost retry

* add agent_testing

* test_a2a_non_streaming

* _build_streaming_logging_obj

* code qa fixes

* test_card_resolver_fallback_from_new_to_old_path

* fix linting
2026-02-06 15:02:34 -08:00
michelligabriele
6a213fc3bc
fix(mcp): resolve OAuth2 'Capabilities: none' bug for upstream MCP servers (#20602)
- process_mcp_request() now falls back to OAuth2 passthrough when Authorization header contains a non-LiteLLM token (catches HTTPException and ProxyException 401/403)
- MCPClient._get_auth_headers() adds missing MCPAuth.oauth2 case
2026-02-06 15:00:35 -08:00
yuneng-jiang
400e560ee5 Merge remote-tracking branch 'origin' into litellm_router_search_fix 2026-02-06 14:08:55 -08:00
Harshit Jain
51d565f619
fix conflicts with main- (this PR is from upstream/main) 2026-02-07 03:10:53 +05:30
yuneng-jiang
b859d76cc2
Merge pull request #20553 from BerriAI/litellm_team_soft_budget_email
[Feature] Team Soft Budget Email Alerts
2026-02-06 09:36:16 -08:00
Alexsander Hamir
09fb6d0087
Warn when budget lookup fails; cache won't populate (#20545)
* Warn when budget lookup fails; cache won't populate

- Add _log_budget_lookup_failure helper in auth_checks.py
- Log at WARNING in get_user_object, get_team_object, get_key_object
  when DB lookups fail (schema mismatch, etc.)
- Add schema migration hint for prisma/db errors
- Add dry-run test for _log_budget_lookup_failure

* fix: skip budget lookup failure log for expected user-not-found case

Avoid logging 'cache will not be populated' when the user simply doesn't
exist - not caching is correct behavior in that case. Only log for
unexpected errors (schema, DB, etc.) where the message is meaningful.
2026-02-06 09:24:44 -08:00
Alexsander Hamir
53a1f2d21c
perf(prometheus): parallelize budget metrics, fix caching bug, reduce CPU by ~40% (#20544) 2026-02-06 09:18:24 -08:00
Sameer Kankute
eab7a99800
Merge pull request #20578 from BerriAI/litellm_claude_code_beta_headers
Add unsupported claude code beta headers in json
2026-02-06 19:10:13 +05:30
Sameer Kankute
db8423b799 Fix: test_json_response_nested_json_schema 2026-02-06 18:52:04 +05:30
Sameer Kankute
05ce4c68e5 Fix: test_vertex_ai_partner_models_anthropic_remove_prompt_caching_scope_beta_header 2026-02-06 18:34:57 +05:30
Sameer Kankute
786bd6ebc0 Fix merge conflicts 2026-02-06 18:29:14 +05:30
Sameer Kankute
920fea9520 feat: Add Unsupported Anthropic beta headers for each provider json 2026-02-06 17:44:09 +05:30
Sameer Kankute
bfd21b5e00
Merge branch 'main' into litellm_opus_4.6_thinking 2026-02-06 14:17:40 +05:30
Sameer Kankute
358a081f63 Add compaction support for vertex ai 2026-02-06 12:52:28 +05:30
Sameer Kankute
d0444f402c Add test for compaction in anthropic 2026-02-06 12:52:28 +05:30
yuneng-jiang
3504f05a5c Adding tests + update pyproject 2026-02-05 21:00:05 -08:00
Sameer Kankute
f15dd691b4 Fix anthropic.claude-opus-4-6-v1 for bedrock 2026-02-06 09:28:50 +05:30
Sameer Kankute
186fd2e64e Add adaptive thinking support for anthropic opus 4.6 2026-02-06 09:24:43 +05:30
Kelvin Tran
524970b8d2 feat: add opus 4.5 and 4.6 to use outout_format param 2026-02-05 19:41:15 -08:00
Shivam Rawat
93cf1ef517
Merge pull request #20535 from BerriAI/litellm_move_anthropic_test_script
[Chore] Move anthropic input/output test to right folder
2026-02-05 16:12:08 -08:00
yuneng-jiang
523a36ed53
Merge pull request #20530 from BerriAI/litellm_ui_team_soft_budget
[Feature] Add soft_budget to Team Table + Create/Update Endpoints
2026-02-05 15:52:17 -08:00
shivam
3dc70c3398 moved the test anthropic file 2026-02-05 15:44:24 -08:00
yuneng-jiang
a17efa1c8e Add soft_budget to team table and create update endpoints 2026-02-05 14:43:48 -08:00
Ishaan Jaff
887a907e42
[Fix] Guardrails API - Ensure OpenAI Moderations Guard works with OpenAI Embeddings (#20523)
* init OpenAIEmbeddingsHandler

* init apply_guardrail

* use apply guardrails for OpenAI moderations

* test_embeddings_handler_string_input

* test_openai_moderation_guardrail_apply_guardrail

* fix typing

* test_openai_moderation_responses_api_input_field

* test fixes
2026-02-05 14:40:15 -08:00
Ryan Crabbe
b4b27203fc perf: cache request.url.path in _get_metadata_variable_name (add_litellm_data_to_request)
Cache request.url.path once instead of accessing it 6 times (2 in
assistants check + 4 in LITELLM_METADATA_ROUTES loop). Reduces
per-call time from 47µs to 20µs (-58%).

Also inline the assistants API check to avoid function call overhead.

Adds 8 tests for _get_metadata_variable_name covering all return paths.
2026-02-05 14:09:11 -08:00
shin-bot-litellm
0649720f79
Fix test isolation for test_log_langfuse_v2_handles_null_usage_values (#20475)
Create fresh mock objects within the test instead of reusing mocks
from setUp that have side_effect configured. The setUp's side_effect
on mock_langfuse_client.trace can interfere with return_value settings
when tests try to reset and reconfigure mocks.

Using dedicated mock objects for this test avoids state pollution
from setUp's side_effect configuration and makes the test more
deterministic in parallel execution environments.
2026-02-05 12:57:41 -08:00
shin-bot-litellm
1d92968e17
Fix test isolation for test_watsonx_gpt_oss_prompt_transformation (#20474)
Set cached tokenizer config directly and mock both sync and async
tokenizer functions to avoid race conditions when running with
parallel test execution (-n 16).

The issue was that parallel tests could populate the
litellm.known_tokenizer_config cache between clearing it and
when the code checked it. This caused the sync code path to be
used instead of the async path, bypassing the mocked async functions.

Fix:
1. Set cache directly instead of clearing it
2. Also mock sync versions _get_tokenizer_config and _get_chat_template_file

This ensures the test is deterministic regardless of test execution order.
2026-02-05 12:57:20 -08:00
Peter Dave Hello
e882296fdc Align Claude Opus 4.6 Bedrock metadata and model IDs
Unify follow-up fixes for Opus 4.6 pricing and routing metadata into
a single changeset.

Set long-context-capable Opus 4.6 entries to 1M input tokens where
>200K pricing is defined, align alias and dated capability metadata,
and add Bedrock Converse v1 IDs with and without :0 suffixes.

Keep regional endpoint pricing at a 10% premium over global entries
and mirror all cost-map changes in the backup file used for local
loading and offline fallback behavior.

Extend Opus 4.6 regression tests to verify metadata parity, Bedrock
regional pricing parity across :0 and non-:0 IDs, and converse model
registration in constants and runtime model sets.
2026-02-06 03:48:10 +08:00
Peter Dave Hello
dbd4bb5cf4
Add Claude Opus 4.6 (#20508)
Add Claude Opus 4.6 entries for Anthropic, Bedrock Converse, and Vertex AI.

Align pricing and capability metadata with Anthropic docs, including
long-context rates, above-200k prompt-caching rates, prefill removal,
and tool-use system prompt token counts.

Register the Bedrock Converse model ID in constants and add targeted
tests to validate model map values and converse registration.
2026-02-05 11:33:44 -08:00
Ishaan Jaff
d2bd029fa4
[Fix] 404 Not Found on /api/event_logging/batch endpoint (#20504)
* fix typing

* add event_logging_batch

* TestEventLoggingBatchEndpoint
2026-02-05 10:58:08 -08:00
Sameer Kankute
a21b625a59
Merge pull request #20105 from qiniu/fix/vertex-gemini-streaming-content-filter
Fix Vertex AI Gemini streaming content_filter handling
2026-02-05 16:48:48 +05:30
Harshit Jain
2f134a03e3
Fix authorization issues, same alias; verified working 2026-02-05 14:14:20 +05:30
Sameer Kankute
453d1bd5e1
Merge branch 'main' into litellm_oss_staging_02_04_2026 2026-02-05 12:19:03 +05:30
Sameer Kankute
5422a5962e Fix test_route_a2a_model_bypasses_router 2026-02-05 09:47:05 +05:30
Ishaan Jaff
2a3843aa57
[Fix] inconsistent response format in anthropic.messages.acreate() when using non anthropic providers (#20442)
* _translate_openai_content_to_anthropic

* test_response_format_consistency

* test fixes unit tests

* test fix

* fix: use dict access for anthropic content blocks in tests (#20447)

The translate_openai_response_to_anthropic method returns dicts, not objects.
Changed .type/.text/.thinking attribute access to dict ['key'] access.

---------

Co-authored-by: shin-bot-litellm <shin-bot-litellm@berri.ai>
2026-02-04 16:37:40 -08:00
Ishaan Jaff
6a73e5bd37
Revert "fix(a2a): use text/event-stream SSE format for message/stream endpoin…" (#20446)
This reverts commit 0209b214ac.
2026-02-04 16:08:22 -08:00
shin-bot-litellm
0209b214ac
fix(a2a): use text/event-stream SSE format for message/stream endpoint (#20365)
* fix(a2a): use text/event-stream SSE format for message/stream endpoint

The A2A gateway's streaming response was using application/x-ndjson
Content-Type and raw NDJSON body format. The A2A protocol spec requires
text/event-stream with SSE framing (data: ...\n\n).

The official a2a-sdk client validates the Content-Type header and raises
SSEError when it doesn't contain text/event-stream.

Changes:
- Changed media_type from application/x-ndjson to text/event-stream
- Updated response body to use SSE framing (data: prefix + \n\n suffix)
- Added tests validating Content-Type and SSE body format

Fixes #20278

* Potential fix for code scanning alert no. 4045: Information exposure through an exception

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>

* test(a2a): add manual SSE format validation script

Adds a manual test script that:
1. Starts a real A2A agent on port 10001
2. Starts LiteLLM proxy with the agent registered
3. Makes a streaming request to the proxy's A2A gateway
4. Validates Content-Type header is text/event-stream
5. Validates body uses SSE framing (data: ...\n\n)

Run: python tests/a2a_manual/test_a2a_sse_manual.py

---------

Co-authored-by: shin-bot-litellm <shin-bot-litellm@users.noreply.github.com>
Co-authored-by: Ishaan Jaff <ishaanjaffer0324@gmail.com>
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
2026-02-04 16:07:17 -08:00
yuneng-jiang
a16faa9e0a
Merge pull request #20394 from BerriAI/litellm_spend_fix_2
[Fix] Unique Constraint on Daily Tables + Logging When Updates Fail
2026-02-04 09:42:46 -08:00
Kris Xia
bfabb39fc6
fix: Fix Vertex AI Gemini streaming content_filter handling
- Add promptFeedback.blockReason check in chunk_parser
- Return content_filter finish_reason when blocked
- Extract content filter logic into _check_prompt_level_content_filter() method
- Update unit tests to reflect simplified implementation

Signed-off-by: Kris Xia <xiajiayi0506@gmail.com>
2026-02-04 21:11:47 +08:00
Sameer Kankute
a86e501632
Merge pull request #20407 from BerriAI/litellm_key_mcp_permissions
Add Key info endpoint object permission data
2026-02-04 17:56:05 +05:30
Sameer Kankute
b2feedc469
Merge pull request #20318 from BerriAI/litellm_oss_staging_02_03_2026
feat(guardrails): implement team-based isolation guardrails mgmnt (#1…
2026-02-04 17:49:30 +05:30
Sameer Kankute
54b5c7d2cd Fix: litellm/tests/test_litellm/proxy/guardrails/guardrail_hooks/test_grayswan.py 2026-02-04 17:35:26 +05:30