Commit Graph

2249 Commits

Author SHA1 Message Date
Krish Dholakia df49b24bc0 Azure - responses api bridge - respect responses/ + Gemini - generate content bridge - handle kwargs + litellm params containing stream (#12224)
* fix(main.py): handle router custom azure model name for responses api bridge

* fix(responses/handler): ensure azure model name is stripped before sending to provider

Fixes model name error

* fix(google_genai/main.py): handle stream=true being set in kwargs

* docs: cleanup icons from sidebar

* fix(test-litellm.yml): add google-genai to test litellmyml

* fix(main.py): strip 'responses/' from bridge

* fix(main.py): fix linting errors

* fix(types/openai.py): allow item to be none

handle azure streaming response

* fix(base.py): allow extra fields + handle azure item = none value in response output item added event

* fix(main.py): correctly handle removing responses/

* test(test_main.py): add unit tests
2025-07-02 13:53:52 -07:00
Cole McIntosh 2c60c316ec Fix: Initialize JSON logging for all loggers when JSON_LOGS=True (#12206)
When JSON_LOGS=True is set, error logs were not being formatted as JSON despite
the configuration. This was because the logging initialization code configured
individual loggers but failed to properly initialize all loggers with the JSON
formatter.

This fix ensures that when json_logs is enabled, the _initialize_loggers_with_handler()
function is called to:
- Configure all loggers (root, LiteLLM, Router, Proxy) with JSON formatter
- Disable logger propagation to prevent duplicate entries
- Set up exception handlers for JSON formatting

Fixes LIT-267
2025-07-02 12:18:28 -07:00
Krish Dholakia 6717d67f3b fix(streaming_handler.py): store finish reason, even if is_finished is false - allows storing early gemini finish reasons (#12250)
Fixes https://github.com/BerriAI/litellm/issues/12249
2025-07-02 12:09:41 -07:00
Nathan Brake c2dbc9c64b fix: mistral transform_response handling for empty string content (#12202)
* Enhance Mistral API: Add support for parallel tool calls and refine name handling in tool messages. Plus, introduce a new test for parallel tool calls in the Mistral model.

* tests

* make mypy happy

* Refine name handling in Mistral chat transformation: clarify conditions for removing the 'name' field based on message role and content.

* handle mistral returning '' instead of None
2025-07-01 22:31:50 -07:00
Krish Dholakia 22d28f5853 Batches - support batch retrieve with target model Query Param + Anthropic - completion bridge, yield content_block_stop chunk (#12228)
* fix(batches_endpoints/endpoints.py): support passing target model names for batch list as a query param

Fixes issue where cloud run fails calls because GET can't contain request body

* test(test_openai_batches_endpoints.py): add unit test

* docs(managed_batches.md): update docs

* feat(spend_tracking_utils.py): support STORE_PROMPTS_IN_SPEND_LOGS env var

ensures prompt is stored in spend logs

* fix(streaming_iterator.py): fix anthropic - completion streaming iterator to yield content block stop

ensures claude code renders messages

* test: skip local test
2025-07-01 22:13:48 -07:00
Jugal D. Bhatt d322e772f0 Litellm add sentry scrubbing (#12210)
* add sentry scrubbing

* add new constants

* remove_unused_import

* sentry scrubbing test

* added unit test
2025-07-01 20:42:36 -07:00
Ishaan Jaff 7471a30dcd Revert "Fix: Preserve full path structure for Gemini custom api_base (#12215)" (#12227)
This reverts commit f47254ecab.
2025-07-01 20:41:39 -07:00
Ishaan Jaff 4b4e2dfde4 test base email 2025-07-01 20:33:21 -07:00
Ishaan Jaff 66fafa3a7f [Feat] Polish - add better error validation when users configure prometheus metrics and labels to control cardinality (#12182)
* self._pretty_print_invalid_metric_error

* docs prometheus.md

* test prom validation checks

* update metric name

* fix _pretty_print_validation_errors

* fix linting

* test prometheus

* test fixes - prometheus
2025-07-01 20:17:17 -07:00
Samuel Boyd a5c2475ecf OpenMeter integration error handling fix (#12147)
* fix - tuple was never falsy so never triggered the exception

* test - add test suite for openmeter integration

* refactor - move tests for openmeter integration
2025-07-01 18:12:54 -07:00
Ishaan Jaff 4e7115bc34 Bug Fix - responses api fix got multiple values for keyword argument 'litellm_trace_id' (#12225)
* fix - handling trace id arg on responses api

* test_async_response_api_handler_merges_trace_id_without_error

* test_anthropic_with_responses_api
2025-07-01 18:12:22 -07:00
Ishaan Jaff a6527e5010 [Feat] Add litellm-proxy cli login for starting to use litellm proxy (#12216)
* add handlers for auth commands

* add login, logout, whoami

* refactor auth

* add CLI Authentication Flow

* add SSO sign in constants

* add itellm-session-token

* fixes for managing state with cli

* use locally stored context for cli session

* add litellm banner + interactive shell

* update main.py

* update auth to show commands

* fix ui sso render

* add TestCLISSOCallbackFunction

* update banner.py

* remove file

* fix cli sso success

* TestTokenUtilities

* fix code qa

* fix execute_command

* fix cli_sso_callback

* fix import

* Authentication using CLI
2025-07-01 18:11:19 -07:00
Jason Roberts cc480f94c9 Fix/move panw prisma airs test file location per feedback on PR #12116 (#12175)
* Move PANW Prisma AIRS test per feedback on PR #12116

- Move test to tests/test_litellm/proxy/guardrails/guardrail_hooks/

* Remove test file from old location
2025-07-01 18:08:04 -07:00
Zayd 7ef590df84 Passes through extra_ properties on "custom" llm provider (#12185)
* Passes through headers on "custom" llm provider

* add test

* adds extra_body support for custom llm providers
2025-07-01 18:07:38 -07:00
Ciprian Tomoiaga b3b4c65ac4 Fix default parameters for ollama-chat (#12201) 2025-07-01 17:59:04 -07:00
Cole McIntosh f47254ecab Fix: Preserve full path structure for Gemini custom api_base (#12215)
* Fix: Preserve full path structure for Gemini custom api_base (Fixes #11959)

This fix addresses an issue where custom api_base URLs (like Cloudflare AI Gateway)
were not working correctly with Google AI Studio (Gemini) models.

The problem was that the _check_custom_proxy method was simply appending the endpoint
to the custom base URL, resulting in malformed URLs like:
https://gateway.ai.cloudflare.com/v1/my-id/my-gateway/google-ai-studio:generateContent

Instead of the correct format:
https://gateway.ai.cloudflare.com/v1/my-id/my-gateway/google-ai-studio/v1beta/models/gemini-2.5-flash:generateContent

Changes:
- Modified _check_custom_proxy to preserve the full path structure from the original URL
- Extracts the path from the original Google AI URL and appends it to the custom base
- Maintains backward compatibility for Vertex AI models (unchanged behavior)
- Added comprehensive tests to verify the fix works correctly

Fixes #11959

* Fix: Update test to match actual Gemini URL format and fix double colon issue

- Fixed test expectation to include the full model path with 'gemini/' prefix
- Fixed double colon issue in Vertex AI URL construction when using custom api_base
- All tests now pass successfully
2025-07-01 17:56:22 -07:00
Jugal D. Bhatt 923004db1b Merge pull request #12218 from BerriAI/email_template
Customizable Email template - Subject and Signature
2025-07-02 06:15:41 +05:30
Jugal D. Bhatt 1513cb5756 Merge pull request #12223 from BerriAI/mcp_error_handling
added error handling for MCP tools not found or invalid server
2025-07-02 06:15:06 +05:30
Ishaan Jaff 2e3a0222e6 Revert "test_anthropic_with_responses_api"
This reverts commit 2f0bdf887e80f85669fb0bae9fcede16863d658e.
2025-07-01 17:43:21 -07:00
Ishaan Jaff 648e8d6533 test_anthropic_with_responses_api 2025-07-01 17:43:21 -07:00
Krish Dholakia 9582c88eab Non-anthropic (gemini/openai/etc.) models token usage returned when calling /v1/messages (#12184)
* fix(proxy_server.py): handle empty config yaml

Fixes https://github.com/BerriAI/litellm/issues/12163

* fix(gemini/common_utils.py): replace models/ as expected, instead of using 'strip'

Fixes https://github.com/BerriAI/litellm/issues/12160

* fix(anthropic/experimental_pass_through/messages/transformation.py): check for env var when selecting api key

* fix(anthropic/transformation.py): return tool_use content block start on anthropic bridge

Closes https://github.com/BerriAI/litellm/issues/12158

* fix(anthropic/streaming_iterator.py): fix setting index in block

ensure index is set just once and increments correctly when a new block is created

* fix(anthropic/adapters/handler.py): update logging obj with stream options value if set

* feat(anthropic/streaming_iterator.py): return usage from chat completion to messages bridge

enables usage tracking for non-anthropic models

Closes https://github.com/BerriAI/litellm/issues/12132

* fix(streaming_iterator.py): safely access usage chunk

* fix: suppress linting error

* test: update tests

* fix: fix streaming errors
2025-07-01 17:41:48 -07:00
Jugal Bhatt 27e6ef5f39 added error handling for MCP tools not found 2025-07-01 17:12:01 -07:00
Jugal Bhatt fefc5fc33a add warning message for non premium users 2025-07-01 16:27:31 -07:00
Jugal Bhatt b63d64dcf5 add subject and signature tests 2025-07-01 15:15:40 -07:00
Cole McIntosh abe364c2bc Fix: Ensure exception is not None before checking its string representation (#12209)
The test_keys_delete_error_handling test was failing with:
- ConnectionError when the mock wasn't properly applied
- The test was checking str(result.exception) without first verifying exception exists

This fix adds an explicit check that result.exception is not None before
attempting to convert it to string, preventing potential AttributeError
and making the test more robust.
2025-07-01 12:30:31 -07:00
Tim O'Farrell e50789730d Fix allow strings in calculate cost (#12200)
* Allow strings in calculate cost

Sometimes the cost per unit is a string (e.g.: If a value like "3e-7" was read from the config.yaml)

* Add comprehensive tests for string cost value handling

- Added test_string_cost_values() to test basic string cost conversion functionality
- Added test_calculate_cost_component_with_string_values() to test the calculate_cost_component function directly
- Added test_string_cost_values_edge_cases() to test mixed string/float costs and error handling
- Added test_string_cost_values_with_threshold() to test string costs with threshold pricing
- Enhanced _get_token_base_cost() to handle string-to-float conversion for base costs and threshold costs
- Enhanced generic_cost_per_token() to handle string-to-float conversion for audio and reasoning token costs
- All tests cover scientific notation (e.g., '3e-7'), decimal notation (e.g., '0.000001'), and error handling for invalid strings
- Maintains backward compatibility with existing float cost values

* Dry up code

* Fixed case where number was an integer

* Allowing None

---------

Co-authored-by: openhands <openhands@all-hands.dev>
2025-07-01 11:37:15 -07:00
Krish Dholakia 49ed3065f6 VertexAI Anthropic - streaming cost tracking w/ prompt caching fixes (#12188)
* fix(rebuild-usage-object---ensure-cache_tokens-is-set): Ensures cache tokens is correctly set

Fixes https://github.com/BerriAI/litellm/issues/12149

* test(test_stream_chunk_builder_utils.py): add unit test to ensure cached tokens is part of stream chunk builder

Ensures standardized values are used
2025-06-30 22:00:10 -07:00
Ishaan Jaff 847c4514c4 test fix - test_anthropic_messages_passthrough.py 2025-06-30 21:56:31 -07:00
Krish Dholakia ee9dd158dd Fix - handle empty config.yaml + Fix gemini /models - replace models/ as expected, instead of using 'strip' (#12189)
* fix(proxy_server.py): handle empty config yaml

Fixes https://github.com/BerriAI/litellm/issues/12163

* fix(gemini/common_utils.py): replace models/ as expected, instead of using 'strip'

Fixes https://github.com/BerriAI/litellm/issues/12160

* fix(anthropic/experimental_pass_through/messages/transformation.py): check for env var when selecting api key

* docs(config_settings.md): add api key to docs
2025-06-30 21:56:03 -07:00
Young Han 042f6b187e [Bug Fix] Fix Error code: 307 for LlamaAPI Streaming Chat (#11946)
* fix: add follow_redirects to avoid 307 error code

* feat: add error 307 test case

* feat: add follow_redirects=True to AsyncClient
2025-06-30 16:52:42 -07:00
Ishaan Jaff d65a9fdcc7 [Bug Fix] Using /messages with lowest latency routing (#12180)
* add validate_anthropic_api_metadata

* fixes for lowest latency deployment

* add _select_metadata_field

* test_anthropic_messages_litellm_router_latency_metadata_tracking
2025-06-30 15:57:19 -07:00
Ishaan Jaff c1d495f09e [Bug Fix] Allow passing litellm_params when using generateContent API endpoint (#12177)
* add _add_generic_litellm_params_to_request

* fix type

* fix: setup_result.litellm_params

* fix passing litellm params

* test_api_base_and_api_key_passthrough

* fixes for passing litellm params

* fix linting errors
2025-06-30 15:17:46 -07:00
Ishaan Jaff d727d63a81 [Feat] Add new AWS SQS Logging Integration (#12176)
* add aws_sqs

* add sqs controls

* add SQS to registry

* fix url lib parse

* fixes AWS SQS

* test_async_sqs_logger_flush

* fix test

* fix SQS logger auth

* add AWS SQS

* add aws sqs

* docs logging

* test_async_sqs_logger_flush

* test_async_sqs_logger_flush

* add SQS logger

* update SQS logging

* use constants for SQS
2025-06-30 14:02:49 -07:00
Cole McIntosh a7594196cd fix: support Cursor IDE tool_choice format {"type": "auto"} (#12168)
* fix: support Cursor IDE tool_choice format {"type": "auto"}

- Update validate_chat_completion_tool_choice to normalize {"type": "auto"} to "auto"
- Handles Cursor IDE sending non-standard tool_choice format
- Add comprehensive tests for tool choice validation

Fixes #12098

* fix: return full tool_choice object for Cursor IDE format

Based on PR feedback, updated validate_chat_completion_tool_choice to return
the full tool_choice dictionary instead of just extracting the type string.
This maintains consistency with downstream code that expects the full object
structure.

- Changed behavior: {"type": "auto"} now returns {"type": "auto"} instead of "auto"
- Updated tests to reflect the new expected behavior
- Ensures compatibility with code that passes tool_choice to optional_params

Addresses feedback from PR #12168
2025-06-30 12:39:58 -07:00
Krish Dholakia cec7e4941a UI QA Fixes - prevent team model reset on model add + return team-only models on /v2/model/info + render team member budget correctly (#12144)
* fix(team_endpoints.py): prevent overwriting current list of team models on new model add

* fix(networking.tsx): fix default proxy base url

* fix(proxy_server.py): include team only models when retrieving all deployments on `/v2/model/info` helper util

ensures team only models are shown to user

* fix(router.py): check model name by team public model name when team id given

Fixes issue where team member could not see team only models when clicking into that team on `Models + Endpoints`

* fix(team_member_view.tsx): fix rendering team member budget, when budget is set

* test: update tests

* test: update unit test
2025-06-28 22:04:49 -07:00
Krish Dholakia f7af8902b0 /v1/messages - Remove hardcoded model name on streaming + Tags - enable setting custom header tags (#12131)
* fix(anthropic/experimental_pass_through): use given model name when returning streaming chunks

don't harcode model name on streaming

confusing for user

* fix(anthropic/streaming_iterator.py): remove scope of import

* feat(litellm_logging.py): allow admin to specify additional headers for using as spend tags

Closes https://github.com/BerriAI/litellm/issues/12129

* test(test_litellm_logging.py): add unit tests

* feat(openweb_ui.md): add custom tag tutorial to docs

* docs(cost_tracking.md): add tag based usage UI screenshot

* test: update test

* fix: fix import
2025-06-28 21:49:35 -07:00
Ishaan Jaff 0c19414b36 [️ Python SDK import] - reduce python sdk import time by .3s (#12140)
* use 1 file for KeyManagementSystem

* move key management settings

* fix import locs

* test_proxy_types_not_imported

* test the import loc

* fix import item

* fix imports

* fix import loc

* fix imports
2025-06-28 14:57:10 -07:00
Ishaan Jaff 6b623f9c98 test whitelisted models 2025-06-28 14:46:16 -07:00
Ishaan Jaff cfc07f361b [Bug Fix] Invite links email should contain the correct invite id (#12130)
* use common helper create_invitation_for_user

* use common util in proxy

* fix create_invitation_for_user

* refactor base email

* test_get_invitation_link_creates_new_when_none_exist

* fix code QA checks
2025-06-28 09:19:32 -07:00
Cole McIntosh 0b95fb63cc Add Azure OpenAI assistant features cost tracking (#12045)
* Add Azure OpenAI assistant features cost tracking

Implements cost tracking for Azure's new assistant features:
- File Search: $0.1 USD per 1 GB/Day (storage-based pricing)
- Code Interpreter: $0.03 USD per session
- Computer Use: $0.003 input + $0.012 output per 1K tokens

Features:
- Provider-specific pricing (Azure vs OpenAI)
- Model-specific pricing overrides via JSON config
- Environment variable configuration
- Backwards compatible with existing OpenAI pricing

* Add comprehensive tests for Azure assistant features cost tracking

- Unit tests for file search, code interpreter, computer use, vector store
- Integration tests for combined cost calculation
- Provider-specific pricing tests (Azure vs OpenAI)
- Model-specific pricing override tests
- Edge case handling (None inputs, zero values)
- All 17 tests passing

* Fix test and ensure all Azure assistant cost tracking tests pass

- Fixed integration test approach
- All 17 tests now passing
- Comprehensive coverage of Azure assistant features cost tracking

* Enhance cost tracking for Azure assistant features

- Safely convert and extract parameters for file search, computer use, and code interpreter sessions.
- Ensure model_info is consistently converted to a dictionary format.
- Improve error handling for input values to prevent type-related issues.
- Maintain compatibility with existing cost calculation methods.

* Refactor cost tracking for Azure assistant features

- Introduced separate methods for handling costs related to web search, file search, vector store, computer use, and code interpreter.
- Enhanced parameter extraction and conversion for file search and computer use.
- Improved error handling and type safety throughout the cost calculation process.
- Maintained compatibility with existing cost calculation methods while streamlining the overall structure.
2025-06-27 21:33:00 -07:00
Ishaan Jaff 95f1850fac add jest.retryTimes(3); 2025-06-27 21:31:51 -07:00
Bougou Nisou 58dda44fda feat: enhance redaction functionality for EmbeddingResponse (#12088) 2025-06-27 21:30:26 -07:00
Cole McIntosh 6578133bb7 Fix user-team association issues in LiteLLM proxy (#12082)
* Fix user-team association issues in LiteLLM proxy

- Update list_team function to properly filter teams using user's teams array instead of only checking members_with_roles field
- Add Field descriptions and docstring to TeamMemberAddRequest and related models for better Swagger/OpenAPI documentation
- Maintain backward compatibility with fallback to members_with_roles if user lookup fails

This ensures users created with teams parameter appear correctly in team views and improves API documentation.

* Fix duplicate member checking in team_member_add endpoint

- Enhanced team_member_add_duplication_check to check both user_id and user_email
- Added additional duplicate prevention logic after user creation/lookup
- Fixed issue where users added by email could be duplicated in teams
- Added logging for debugging duplicate detection

This addresses the bug where adding the same user by email multiple times would create duplicate entries in the team's members_with_roles array.

* Improve duplicate member prevention in team_member_add

- Enhanced early duplicate check to handle both user_id and user_email
- Added late-stage duplicate prevention after user lookup/creation
- Fixed issue where users could be added multiple times by email
- Cleaned up debug logging

Note: There's still an edge case where the duplicate prevention may not work
correctly in all scenarios. This needs further investigation and testing.

* Refactor team_member_add endpoint for improved member management

- Split team_member_add functionality into smaller, dedicated functions for permission validation, member processing, and team member list updates.
- Enhanced permission checks to ensure only authorized users can add members.
- Streamlined member addition logic to reduce redundancy and improve readability.
- Maintained existing functionality while improving code structure and maintainability.

* Add tests for team_member_add helper functions

- Add test for _validate_team_member_add_permissions with admin user
- Add test for _validate_team_member_add_permissions with non-admin user
- Add test for _process_team_members with single member
- Add test for _process_team_members with multiple members
- Add test for _update_team_members_list with new member
- Add test for _update_team_members_list duplicate prevention

These tests ensure the refactored helper functions work correctly
after fixing the PLR0915 linting error.
2025-06-27 21:29:49 -07:00
Youfu Zhang 1c68c24358 introduce new environment variable NO_REDOC to opt-out Redoc (#12092)
Signed-off-by: Youfu Zhang <zhangyoufu@gmail.com>
2025-06-27 21:26:37 -07:00
Krish Dholakia ee6e76e1f9 Bedrock Passthrough cost tracking (/invoke + /converse routes - streaming + non-streaming) (#12123)
* refactor(passthrough_endpoints-success-handler): refactor llm passthrough logging logic

isolate the llm translation work to enable cost tracking on sdk

* feat: initial implementation of passthrough SDK cost calculation

enables bedrock passthrough cost tracking to work

* feat(cost_calculator.py): working cost calculation for bedrock passthrough

* feat(litellm_logging.py): consider allm_passthrough in cost tracking

allows async calls (e.g. via proxy) to work

* feat(bedrock/passthrough): working event stream decoding for bedrock passthrough calls + logging instrumentation for passthrough sdk calls (log on stream completion)

Enables bedrock streaming cost calculation

* feat(litellm_logging.py): support streaming passthrough cost tracking

* feat(passthrough/main.py): working async streaming cost calculation

Closes https://github.com/BerriAI/litellm/issues/11359

* feat(proxy_server.py): fix passthrough routing when llm router enabled

* feat: further fixes

* feat(bedrock/): working bedrock passthrough cost tracking (non-streaming)

* feat(litellm_logging.py): working usage tracking for bedrock passthrough calls

ensures tokens are logged

* feat(bedrock/passthrough): add converse passthrough cost tracking support

* feat(base_llm/passthrough): remove redundant function

* refactor(litellm_logging.py): refactor function to be below 50 LOC

* test: update test

* test: remove redundant test
2025-06-27 20:01:12 -07:00
Ishaan Jaff 080372399f test_mock_router_testing_params_str_to_bool_conversion 2025-06-27 18:07:33 -07:00
Ishaan Jaff d8dc84ee96 test fix - router utils 2025-06-27 18:05:37 -07:00
Ishaan Jaff 01b9e6efb1 Revert "fix: set logger levels based on LITELLM_LOG environment variable" (#12122) 2025-06-27 17:55:44 -07:00
Ishaan Jaff ebf6395bc1 [Feat] Add Eleven Labs - Speech To Text Support on LiteLLM (#12119)
* add ELEVENLABS as a provider

* add deepgram to main.py

* add ElevenLabsException

* add ElevenLabsAudioTranscriptionConfig

* add transform_audio_transcription_response

* TestElevenLabsAudioTranscription

* add elevenlabs/scribe_v1 to model cost map

* add ElevenLabsAudioTranscriptionConfig

* add AudioTranscriptionRequestData

* add ElevenLabs transform

* use AudioTranscriptionRequestData

* refactoring fixes

* add ProcessedAudioFile util for reading audio files

* test_elevenlabs_diarize_parameter_passthrough

* docs eleven labs

* docs fixes

* fix code qa checks

* fixes - audio transcription

* ui - add ElevenLabs logo

* add elevenlabs logo

* docs - ElevenLabs

* test fix elevenlabs
2025-06-27 17:50:49 -07:00
Ishaan Jaff 041db0268c [Bug fix] Router - handle cooldown_time = 0 for deployments (#12108)
* fix get cooldown time

* fixes for _should_run_cooldown_logic

* test_cooldown_time_zero_uses_zero_not_default

* Update litellm/router_utils/cooldown_cache.py

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update litellm/router_utils/cooldown_handlers.py

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-06-27 17:50:35 -07:00