Commit Graph
113 Commits
Author SHA1 Message Date
Boxuan LiandGitHub 89458573a2 Add context window exception mapping for Together AI (#17284) 2025-12-01 20:02:59 -08:00
Ishaan Jaffer 772be1778a test_append_system_prompt_messages 2025-11-26 19:00:31 -08:00
Kerem TurgutluandGitHub 8637d74e17 include server_tool_use in streaming usage (#16826)
* include server_tool_use in streaming usage

* add test
2025-11-25 14:50:17 -08:00
Krish DholakiaandGitHub 270d23939e (fix) litellm_logging.py: fix mcp tool call response logging + (fix) responses_bridge: remove unmapped param error mid-stream - allows gpt-5 web search to work via responses api in .completion() (#16946)
* fix: fix getting mcp servers

* fix(litellm_logging.py): handle list objects for final response in standard logging payload

Fixes issue where mcp tool call response wouldn't show up

* fix(litellm_responses_transformation/): remove invalid item error for unmapped objects - breaks stream and there's no real value to this as outside of a few of them, not all can be mapped to chat completions

resolves error for web search calls via chat completions to responses api
2025-11-22 15:48:32 -08:00
Alexsander HamirandGitHub b02baf53a9 Fix: prevent memory blowout in LoggingWorker (#16559)
* fix: prevent memory blowout in LoggingWorker

Tasks were being executed sequentially with each task awaited before
processing the next one. When the queue had 10k+ tasks, only one could
execute at a time. Since the request rate exceeded execution speed,
objects accumulated in memory (50k+), holding references to heavy
objects and causing memory blowout.

The new implementation uses a semaphore to allow up to 1000 concurrent
tasks while properly tracking and cleaning up each task, significantly
improving throughput and preventing queue buildup.

* fix: require semaphor before removing task from queue

* fix: make worker concurrency configurable

* fix: clean comments

* fix: clarify new env purpose

* fix: add missing lib

* make constants configurable instead of hardcoded

* add more aggressive cleaning when queue is full

* add helpers function for the aggressive cleaning functionality

* use envs instead of static constants

* import and document constants

* add unit test for new functionality

* fix default value on config_settings

* fix: remove unused variables and imports to resolve linter errors

- Remove unused time_since_last_clear variable in logging_worker.py
  The variable was calculated but never used in _handle_queue_full()
  method, causing F841 linter error.

- Remove unused TYPE_CHECKING import in mcp_server/server.py
  The import was not used anywhere in the file, causing F401 linter error.

These changes improve code cleanliness and ensure the codebase passes
all linter checks without affecting functionality.

* add missing log expected by test_queue_full_handling

* fix: clean config_setting.md file

* fix: handle logging errors gracefully during shutdown in _flush_on_exit

During process shutdown, logging handlers may be closed while _flush_on_exit
tries to flush queued logging coroutines. This causes 'ValueError: I/O
operation on closed file' errors when coroutines attempt to log.

Changes:
- Add _safe_log helper method that wraps logging calls and suppresses
  errors when logging handlers are closed (ValueError, OSError, AttributeError)
- Replace all verbose_logger calls in _flush_on_exit with _safe_log
- Remove logging from exception handler in coroutine execution loop
  to prevent cascading errors during shutdown

This ensures graceful shutdown even when logging handlers are closed,
which is common during process termination.
2025-11-22 13:58:29 -08:00
Ishaan Jaffer badbadba0d fix img URL for tests 2025-11-22 09:41:15 -08:00
Dima-MediatorandGitHub a0d4d0b304 Gemini models: capture image_tokens and support cost_per_output_image_token in costs calculations (#16912) 2025-11-21 19:59:24 -08:00
yuneng-jiangandGitHub 6881594632 [Fix] Exclude litellm_credential_name from Sensitive Data Masker (Updated) (#16958)
* Exclude litellm_credential_name from sensitive masker

* Adding missing file
2025-11-21 19:09:48 -08:00
yuneng-jiangandGitHub eb48d5cc42 Revert "Exclude litellm_credential_name from sensitive masker (#16950)" (#16956)
This reverts commit 5cfacb96e6.
2025-11-21 18:09:54 -08:00
yuneng-jiangandGitHub 5cfacb96e6 Exclude litellm_credential_name from sensitive masker (#16950) 2025-11-21 16:40:17 -08:00
Nicholas CoutureandGitHub 4be372eb48 fix: support Anthropic tool_use and tool_result in token counter (#16351)
* fix: support Anthropic tool_use and tool_result in token counter

* refactor(token_counter): add dynamic field inference for Anthropic content blocks

* test: Add additional tests

* make format

* Fix lint error

* Fix mypy narrow type lint errors
2025-11-13 14:30:46 -08:00
Sameer KankuteandGitHub 92bd12c862 Fix raising wrong 429 error on wrong exception (#16482)
* fix raising wrong 429 error on wrong exception

* remove double re import
2025-11-12 18:41:12 -08:00
Krish DholakiaandGitHub 06906534b3 feat(audio_transcriptions/): calculate duration of audio file for cost calculation + feat (image_generations): cost tracking accuracy improved with output_format, quality, size values fixed per openai model
* feat(audio_transcriptions/): calculate duration of audio file for cost calculation

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

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

* fix(cost_calculator.py): correctly use base model, when set

Fixes issue where azure base model was being ignored

* feat(cost_calculator.py): fix default cost tracking quality param for image generation

* feat(image_generations/): return output_format, quality, size

aligns response to openai spec and improves cost tracking accuracy

* fix(cost_calculator.py): refactor cost calculation for image generation to use image response instead of hidden params

* build: update build

* fix: fix cost calculation

* build: update poetry lock

* fix: fix ruff checks

* fix: fix aembedding

* fix: fix ruff errors

* fix: modify to catch errors

* fix: test

* fix: loosen test to handle openai lib out of sync

* fix: fix base models

* fix: fix usage object
2025-11-08 16:24:31 -08:00
86d73c918c Adds support for returning Azure Content Policy error information when exceptions from Azure OpenAI occur (#16231)
* add provider_specific_fields to ContentPolicyViolationError

* use provider_specific_fields in ProxyException

* update openai_exception_handler

* fix use exception checker for content policy violation azure

* add AzureOpenAIExceptionMapping

* test_azure_with_content_safety_error

* Accessing Provider-Specific Error Details

* TestExceptionCheckers

* unit test got provider_specific_fields=

* add clear types for error dict

* fix test_azure_with_content_safety_error

---------

Co-authored-by: Ishaan Jaff <ishaanjaffer0324@gmail.com>
2025-11-08 16:04:36 -08:00
Krish DholakiaandGitHub 202eaeb1a2 Revert "(feat) Audio transcription - cost tracking + (feat) image generation …" (#16409)
This reverts commit c96da44265.
2025-11-08 15:38:16 -08:00
Krish DholakiaandGitHub c96da44265 (feat) Audio transcription - cost tracking + (feat) image generation - accurate cost tracking based on output_format/quality/size
* feat(audio_transcriptions/): calculate duration of audio file for cost calculation

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

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

* fix(cost_calculator.py): correctly use base model, when set

Fixes issue where azure base model was being ignored

* feat(cost_calculator.py): fix default cost tracking quality param for image generation

* feat(image_generations/): return output_format, quality, size

aligns response to openai spec and improves cost tracking accuracy

* fix(cost_calculator.py): refactor cost calculation for image generation to use image response instead of hidden params

* build: update build

* fix: fix cost calculation

* build: update poetry lock

* fix: fix ruff checks

* fix: fix aembedding

* fix: fix ruff errors

* fix: modify to catch errors

* fix: test

* fix: loosen test to handle openai lib out of sync
2025-11-08 15:30:46 -08:00
Krish DholakiaandGitHub bce8a5d6b7 Revert "(feat) audio transcriptions cost tracking (for azure/other non-openai…" (#16402)
This reverts commit 9a88fe0861.
2025-11-08 14:24:51 -08:00
Krish DholakiaandGitHub 9a88fe0861 (feat) audio transcriptions cost tracking (for azure/other non-openai models) + (fix) image generations - accurate cost tracking for dalle3/gpt-image-1 - uses the correct max image quality (#16076)
* feat(audio_transcriptions/): calculate duration of audio file for cost calculation

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

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

* fix(cost_calculator.py): correctly use base model, when set

Fixes issue where azure base model was being ignored

* feat(cost_calculator.py): fix default cost tracking quality param for image generation

* feat(image_generations/): return output_format, quality, size

aligns response to openai spec and improves cost tracking accuracy

* fix(cost_calculator.py): refactor cost calculation for image generation to use image response instead of hidden params

* build: update build

* fix: fix cost calculation

* build: update poetry lock

* fix: fix ruff checks
2025-11-08 13:54:37 -08:00
Ishaan Jaffer c60a13c919 fixes 2025-11-08 11:11:22 -08:00
Ishaan JaffandGitHub ca229fe030 [Feat] LiteLLM Guardrail - UI Fix, ensure you can see UI Friendly name for PII Patterns (#16382)
* fix safe dumps

* add patterns.json

* add PrebuiltPattern

* add test patterns
2025-11-07 18:14:58 -08:00
Alan PonnachanandGitHub 5b01fe0a81 fix(vertex_ai): Correctly map 429 Resource Exhausted to RateLimitError (#16363) 2025-11-07 14:36:20 -08:00
Andrii KislitsynandGitHub c497b6f239 Add retry-after header support for errors 502, 503, 504 (#16288)
* retry-after-header-support-for-502-503-504-initial

* retry-after-header-support-for-502-503-504-tests-and-linters
2025-11-06 19:33:29 -08:00
Ishaan Jaffer dc71eb12e3 fix _get_spend_logs_metadata 2025-11-06 17:08:53 -08:00
Ishaan Jaffer 8e73e11fc8 SEARCH_PROVIDERS 2025-11-06 17:07:53 -08:00
Ishaan Jaffer 8a9fe7b056 fix delete callbacks 2025-11-06 17:06:34 -08:00
Jamie GoodyearandGitHub 2c9970742f [LiteLLM-16250] Proxy to Bedrock will add name to file content, breaks when cache_control in use (#16275) 2025-11-05 18:39:38 -08:00
0c743e1adc Add E2E Container API Support (#16136)
* Add v1 cut of container api

* fix lint errors

* Add proxy support to container apis & logging support (#16049)

* Add proxy support to container apis

* Add logging support

* Add cost tracking support for containers and documentation

* Add new constant documentation

* Add container cost in model map

* fix failing azure tests

* Update tests based on model map changes

* fix model map tests

* fix model map tests

* Container modeshould be container

* Container tests fix

* Merge branch 'main' into litellm_sameer_oct_staging_2

---------

Co-authored-by: Ishaan Jaffer <ishaanjaffer0324@gmail.com>
2025-11-01 14:03:51 -07:00
langpingandGitHub 5bba1e8405 Added fallback logic for detecting file content-type when S3 returns generic (#15635)
* enhance image processing fallback logic

* Extract to comment utils
2025-10-29 08:24:20 -07:00
Ishaan JaffandGitHub 20f9e189fb [Buf fix] - Azure OpenAI, fix ContextWindowExceededError is not mapped from Azure openai errors (#15981)
* fix is_error_str_context_window_exceeded

* test_is_error_str_context_window_exceeded
2025-10-27 13:44:55 -07:00
Krish DholakiaandGitHub 1543891763 Responses API - support tags in metadata
* fix(ui/): fix routing for custom server root path

* fix: fix eslint errors

* fix(vector_store_pre_call_hook.py): Fix https://github.com/BerriAI/litellm/issues/15724

* fix(responses/main.py): have 'tags' work across metadata + litellm_metadata

* fix: add unit testing
2025-10-25 12:07:54 -07:00
Jacob LinneyandGitHub 0644c20604 fix(vertex-ai): cost tracking for search spend (#15859) 2025-10-23 13:29:10 -07:00
soo-jin.kimandGitHub 8050995dbb fix: Rename configured_cold_storage_logger to cold_storage_custom_logger (#15798)
- Change variable name in litellm/__init__.py from configured_cold_storage_logger to cold_storage_custom_logger
- Update all references across the codebase to use the new variable name
- This fixes silent failure of cold storage logging due to variable name mismatch
- Configuration files use cold_storage_custom_logger, code should match

Files updated:
- litellm/__init__.py
- litellm/litellm_core_utils/litellm_logging.py
- litellm/proxy/spend_tracking/cold_storage_handler.py
- litellm/responses/litellm_completion_transformation/session_handler.py
- tests/test_litellm/litellm_core_utils/test_litellm_logging.py
- tests/test_litellm/responses/litellm_completion_transformation/test_session_handler.py
2025-10-22 09:17:08 -07:00
Thomas MildnerandGitHub 1cfc4624c3 [Feat] Add SENTRY_ENVIRONMENT configuration for Sentry integration (#15760)
* [Feat] Add SENTRY_ENVIRONMENT configuration for Sentry integration and corresponding tests

* [Refactor] Enhance test_sentry_environment by mocking sentry_sdk and improving environment handling

* [Fix] Update default SENTRY_ENVIRONMENT to 'production' and enhance test for Sentry integration

* [Fix] Update test_sentry_environment to verify correct handling of SENTRY_ENVIRONMENT values

* [Fix] Update test_sentry_environment to assert correct handling of production environment
2025-10-21 16:40:55 -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
Krish DholakiaandGitHub 302f55c7db Bedrock + MCP - working MCP calls to bedrock via Responses API + Log hidden params for OTEL calls (#15677)
* fix: minor fixes to mcp streaming with bedrock

* fix(bedrock/): working bedrock with mcp tools

handle empty description

* test: add unit test

* test: test fixes

* fix(vector_store_registry.py): load vector store with litellm params from config.yaml

fixes minor issue where litellm params weren't being loaded in from config.yaml

* docs(knowledgebase.md): document azure vector store current limitation

* fix(opentelemetry.py): add hidden params to otel logs

Fixes LIT-1274

* fix: fix test
2025-10-18 10:39:28 -07:00
Ishaan Jaffer fd83b292a6 test_bedrock_anthropic_prompt_caching 2025-10-15 17:46:44 -07:00
Alexsander HamirandGitHub 9d7dea42d0 [Fix] - SensitiveDataMasker converts lists to string (#15420)
* fix: preserve lists in SensitiveDataMasker to prevent string conversion

Added 'list' to allowed primitive types in mask_dict() to prevent lists like
tags from being converted to string representations in API responses.

Before: {"tags": "['East US 2', 'production', 'test']"}
After:  {"tags": ["East US 2", "production", "test"]}

* add: unit test
2025-10-10 17:50:51 -07:00
Tim Elfrink c5eb22381d fix(bedrock): include cacheWriteInputTokens in prompt_tokens calculation
Fixes #15263

This PR fixes the cost calculation for Bedrock Anthropic models with prompt caching.

**Root Cause:**
PR #9838 incorrectly removed adding `cacheWriteInputTokens` to `prompt_tokens`
for Bedrock, based on the assumption that it would cause double counting (similar
to an Anthropic API issue). However, Bedrock's token structure is different:

- **Bedrock API**: `inputTokens`, `cacheReadInputTokens`, and `cacheWriteInputTokens`
  are ALL separate values that should be summed for total input tokens
- **Anthropic API**: Same structure - all three token types are separate

The fix in #9838 was later reverted for Anthropic (correctly re-adding
`cache_creation_input_tokens` to `prompt_tokens`), but Bedrock was never fixed.

**Changes:**
1. Re-add `cacheWriteInputTokens` to `input_tokens` in Bedrock transformation
2. Update test assertions to reflect correct behavior
3. Add regression test for prompt caching cost calculation
4. Fix typo in Anthropic transformation where `cache_creation_tokens` was
   incorrectly set to `cache_read_input_tokens`

**Testing:**
- All existing Bedrock transformation tests pass
- New test validates correct cost calculation with prompt caching
- Verified costs are non-negative and accurate
2025-10-07 20:28:46 +02:00
malagsandGitHub 68189d1c04 [Performance] Reduce complexity of InMemoryCache.evict_cache from O(n*log(n)) to O(log(n)) (#15000)
* Improved performance by reducing complexity

* Improved logic to prevent memory from increasing too much, added test

* Restore indent

* Restore indent

* Added type annotation

* Updated test to correctly initialize the expiration_heap
2025-09-30 16:49:35 -07:00
Krish DholakiaandGitHub 88f9cad886 Merge pull request #14796 from BerriAI/litellm_anthopic_token_count_issue
Add service_tier based pricing support for openai[ BOTH Service & Priority Support]
2025-09-22 22:38:59 -07:00
Sameerlite d2208023d2 Add service_tier based pricing support for openai 2025-09-23 10:48:27 +05:30
Ishaan JaffGitHubCopilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
b9ffa98c55 [Feat] Proxy CLI: Create a python method to login using litellm proxy (#14782)
* fix: cli auth with SSO okta

* fix: add LITTELM_CLI_SERVICE_ACCOUNT_NAME

* fix: get_litellm_cli_user_api_key_auth

* use existing_key CLI

* fix: use existing key

* test auth commands

* test_cli_sso_callback_regenerate_vs_create_flow

* feat: add CLI Token Utilities

* fix: get_stored_api_key

* move file

* fix: get_valid_models

* fix config.yaml

* TestCLITokenUtils

* TestGetValidModelsWithCLI

* fix: tie user id to keys created through CLI

* fix: add teams interface to CLI

* add /keys/update to the list client commands

* fix /sso/cli/poll to return the user_id

* fix: working TeamsManagementClient

* fix CLI Login command

* fixes for auth

* Potential fix for code scanning alert no. 3400: Clear-text logging of sensitive information

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

* ruff fix

---------

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
2025-09-22 21:28:38 -07:00
Ishaan Jaffer 59d2f0f465 test_string_cost_values 2025-09-20 13:34:57 -07:00
Krish DholakiaandGitHub aa54994994 Merge pull request #14666 from michaeltansg/feat/add-bangkok-timezone
Added Indochina Time timezone support for budget resets
2025-09-18 23:41:27 -07:00
Krish DholakiaandGitHub 664c83cfb5 Merge branch 'litellm_contributor_prs_09_18_2025_p2' into litellm_dev_09_17_2025_p2_v2 2025-09-18 19:50:55 -07:00
Michael Tan 6721189b7c feat: add Asia/Bangkok timezone support for budget resets
- Add Asia/Bangkok (UTC+7) to timezone_map in duration_parser.py
- Update documentation to include Bangkok in common timezone values
- Add test case to verify Bangkok timezone functionality
2025-09-18 14:56:12 +07:00
Alexsander HamirandGitHub 8d96626044 fix: iscoroutine removed from hot path +50 RPS (#14649)
* fix: iscoroutine removed from hot path

* fix: replace all instances & separate concerns

1. Replaced all instances of iscoroutine with is_async_callable
2. Place the coroutine checker in its own file

* fix: PR comment changes

* fix: missing config setting declaration

* fix: revert non-performance related changes

* fix: revert to initial implementation

* fix: remove dead const
2025-09-17 19:01:43 -07:00
Krrish Dholakia 2f45c7ffd3 feat(anthropic/chat/transformation.py): account for 1h vs. 5m cache creation token cost difference
Closes LIT-907
2025-09-17 16:16:20 -07:00
Krish DholakiaandGitHub 895c41efa3 Merge pull request #14619 from BerriAI/litellm_dev_09_16_2025_p1
UI - allow team member to view service account keys they create + Anthropic - include cache creation tokens in prompt token total (separate out during cost tracking)
2025-09-17 15:43:04 -07:00
Krish DholakiaandGitHub bf0dd4a284 Merge pull request #14418 from iabhi4/deep-copy-issue
fix: avoid deepcopy crash with non-pickleables in Gemini/Vertex
2025-09-16 22:55:31 -07:00