Commit Graph
28331 Commits
Author SHA1 Message Date
yuneng-jiangandGitHub fe23eee079 Merge pull request #17598 from BerriAI/litellm_ui_customer_usage_banner
[Feature] UI - Add Info Banner for Customer Usage
2025-12-06 09:04:39 -08:00
yuneng-jiang fa47861ca0 Add banner for customer usage 2025-12-06 08:57:15 -08:00
Alexsander HamirandGitHub 53e2516ace fix: make test_watsonx_gpt_oss_prompt_transformation deterministic (#17597)
- Remove network dependency by mocking HuggingFace template fetch
- Use mock template that produces correct format for test validation
- Test now focuses on transformation logic, not network calls
- Fixes flaky test failures due to network timeouts/rate limits

The test verifies that prompt transformation occurs (not simple
concatenation), which doesn't require the actual HuggingFace template.
Mocking makes the test deterministic and faster while still validating
the core behavior.
2025-12-06 08:48:39 -08:00
Alexsander HamirandGitHub db40a38999 Add retry logic to apk package installation in Dockerfile.non_root (#17596)
- Add retry loop (3 attempts with 5s delay) to builder stage apk add command
- Add retry logic to runtime stage apk upgrade and apk add commands
- Improves resilience to transient network errors during package downloads
2025-12-06 08:17:50 -08:00
Alexsander HamirandGitHub 73075c7d24 fix: add retry logic for flaky Azure image generation health check test (#17595)
- Add missing @pytest.mark.asyncio decorator
- Implement retry logic with exponential backoff (3 retries)
- Only retry on transient Azure internal server errors
- Fail immediately on non-transient errors

This fixes the flaky test_azure_img_gen_health_check which was failing
due to transient Azure internal server errors that are outside our control.
2025-12-06 08:11:52 -08:00
Alexsander HamirandGitHub 1e89aa3068 Fix: Resolve flakiness in three integration tests (#17594)
Fixed three flaky tests that were intermittently failing in CI:

1. test_no_duplicate_spend_logs (test_litellm/responses/test_no_duplicate_spend_logs.py)
   Problem: Used await asyncio.sleep(1) to wait for async logging completion,
            which created race conditions. The async logging worker queues tasks
            in the background, and sleep() doesn't guarantee completion.

   Fix: Replaced sleep() with GLOBAL_LOGGING_WORKER.flush() which properly waits
        for the logging queue to empty, ensuring all async logging tasks complete
        before assertions run.

2. test_log_langfuse_v2_handles_null_usage_values (test_litellm/integrations/test_langfuse.py)
   Problem: Used datetime.datetime.now() twice for start_time and end_time, which
            could cause timing inconsistencies between test runs, especially in
            CI environments with variable execution speeds.

   Fix: Use fixed timestamps instead of datetime.now() to ensure consistent timing
        across all test runs, eliminating timing-related flakiness.

3. test_watsonx_gpt_oss_prompt_transformation (test_litellm/llms/watsonx/test_watsonx.py)
   Problem: Directly accessed mock_post.call_args without checking if it exists,
            which could be None if the mock wasn't called or if an exception
            occurred before the POST request. The test catches exceptions and
            continues, making this a potential failure point.

   Fix: Added proper assertions and use call_args_list[0] for safer access:
        - Assert that call_args_list has at least one call
        - Assert that call_args is not None
        - Assert that 'data' key exists in kwargs
        This ensures the test fails with clear error messages rather than
        intermittent AttributeError exceptions.

All fixes maintain the original test intent while making them deterministic
and reliable in CI environments.
2025-12-06 07:57:03 -08:00
Alexsander HamirandGitHub 99ab9fd145 Fix: Ensure guardrail metadata is preserved in request_data (#17593)
Fixed bug in add_guardrail_to_applied_guardrails_header where guardrail
information was lost when request_data didn't have a metadata key. The
function would create a new metadata dict but never assign it back to
request_data, causing the x-litellm-applied-guardrails header to be
missing from responses.

This fixes the failing test_guardrails_with_api_key_controls test.
2025-12-06 07:50:15 -08:00
Alexsander HamirandGitHub 00a9f99718 Fix flaky test: test_logging_non_streaming_request (#17592)
- Filter async_log_success_event calls by expected input message
- Bridge models (openai/codex-mini-latest) may make internal calls that also log
- Test now asserts exactly one call with the expected input 'Hey' instead of asserting total call count
- Makes test robust to bridge-related double logging while still validating core behavior
2025-12-06 07:40:23 -08:00
Alexsander HamirandGitHub 3db6d2a1ed Reapply Langfuse logger test mock setup fix (#17591)
Reapplies the fix from commit a885e21543 that was
reverted in 6c9556be67.

The original revert was done because the test was flaky and giving false
negatives. This fix properly mocks the Langfuse client to ensure the test
can correctly verify that _log_langfuse_v2 converts None usage values to 0.

Changes:
- Add mock_langfuse_client.client attribute to prevent errors during init
- Add trace_id to mock_langfuse_generation for proper return value handling
- Remove redundant mock setup code
- Explicitly set logger.Langfuse to mock client after initialization
- Set logger.langfuse_sdk_version to ensure _supports_* methods work correctly
2025-12-06 07:26:34 -08:00
Alexsander HamirandGitHub 6c9556be67 Revert "Fix Langfuse logger test mock setup (#17588)" (#17590)
This reverts commit a885e21543.
2025-12-06 06:25:47 -08:00
Alexsander HamirandGitHub 998b27c655 fix: preserve usage from JSON response for OpenAI provider in Bedrock (#17589)
- Skip usage recalculation if usage was already set from response JSON
- Fixes test_bedrock_openai_response_parsing which expected usage values from JSON response
- Prevents overwriting correct usage values with token counting for OpenAI imported models
2025-12-06 06:17:46 -08:00
Alexsander HamirandGitHub a885e21543 Fix Langfuse logger test mock setup (#17588)
* Fix test_log_langfuse_v2_handles_null_usage_values test failure

The test was failing because the logger's Langfuse client wasn't properly
mocked. Even though sys.modules was mocked, the logger's __init__ method
creates its own Langfuse client instance that wasn't using the test's mock.

Changes:
- Explicitly set logger.Langfuse to the mock client after initialization
- Set logger.langfuse_sdk_version to ensure _supports_* methods work correctly
- Added mock_langfuse_client.client attribute to prevent errors during init
- Added trace_id to mock_langfuse_generation for proper return value handling
- Removed redundant mock setup code

This ensures the test can properly verify that _log_langfuse_v2 correctly
converts None usage values to 0 by allowing the mock's generation method
to be called and asserted.

Fixes: AssertionError: Expected 'generation' to have been called once. Called 0 times.
2025-12-06 05:56:24 -08:00
Alexsander HamirandGitHub 415a8ab9a6 Fix: remove merge markdown (#17586) 2025-12-06 05:38:16 -08:00
yuneng-jiangandGitHub 2dd2f84b86 Merge pull request #17553 from BerriAI/litellm_ui_use_auth_new_login
[Fix] Change useAuthorized Hook to redirect to new Login Page
2025-12-05 21:06:07 -08:00
yuneng-jiangandGitHub 60bbe323f7 Merge pull request #17569 from BerriAI/litellm_ui_flaky_test_2
[Fix] Flaky UI Test
2025-12-05 21:03:51 -08:00
Ishaan Jaffer 8b499adba6 Revert "Add license metadata to health/readiness endpoint. (#15997)"
This reverts commit d89990e0c5.
2025-12-05 19:31:30 -08:00
YutaSaitoandGitHub 12850969fb Merge pull request #17570 from BerriAI/litellm_fix_mcp_test 2025-12-06 11:24:35 +09:00
yuneng-jiang 1f2bf08136 Fix flaky ui test 2025-12-05 17:55:07 -08:00
Yuta Saito 21a18128ec fix: mcp test 2025-12-06 10:54:22 +09:00
Ishaan Jaffer ce4b5daf70 ollama fix 2025-12-05 17:25:55 -08:00
Ishaan Jaffer f0a93fb9b9 test_string_cost_values_edge_cases 2025-12-05 17:25:55 -08:00
yuneng-jiangandGitHub fdb49c97f2 Merge pull request #17562 from BerriAI/litellm_ui_compare_images
[Feature] Support Images in Compare UI
2025-12-05 17:24:05 -08:00
Ishaan Jaffer 96e4c9e078 fix _update_metadata_with_tags_in_header 2025-12-05 17:20:14 -08:00
dependabot[bot]GitHubdependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
83291d394e build(deps): bump mdast-util-to-hast in /ui/litellm-dashboard (#17444)
Bumps [mdast-util-to-hast](https://github.com/syntax-tree/mdast-util-to-hast) from 13.2.0 to 13.2.1.
- [Release notes](https://github.com/syntax-tree/mdast-util-to-hast/releases)
- [Commits](https://github.com/syntax-tree/mdast-util-to-hast/compare/13.2.0...13.2.1)

---
updated-dependencies:
- dependency-name: mdast-util-to-hast
  dependency-version: 13.2.1
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-12-05 17:12:51 -08:00
Ishaan Jaffer eaa7e61f57 test fixes 2025-12-05 17:12:01 -08:00
Ishaan Jaffer 58f8be60a1 fix REDIS_DAILY_END_USER_SPEND_UPDATE_QUEUE 2025-12-05 17:07:09 -08:00
yuneng-jiangandGitHub 82376d8b76 Merge pull request #17564 from BerriAI/litellm_end_user_spend_redis_test
[Fix] CI/CD - Adding end user and org to service types
2025-12-05 16:44:37 -08:00
yuneng-jiang 86baa9e5fb Adding end user and org to service types 2025-12-05 16:38:09 -08:00
yuneng-jiangandGitHub 8e74a3b692 Merge pull request #17563 from BerriAI/litellm_v2_login_test_fix
[Fix] Mock server_root_path for v2/login test
2025-12-05 16:23:51 -08:00
yuneng-jiangandGitHub df8b0e8389 Merge pull request #17506 from BerriAI/litellm_ui_customer_usage
[Feature] Customer Usage UI
2025-12-05 16:18:42 -08:00
b5133c4c7d Feat/mcp preserve tool metadata calltoolresult (#17561)
* feat(mcp): preserve tool metadata and full CallToolResult in MCP gateway

This PR fixes two issues that prevented ChatGPT from rendering MCP UI widgets
when proxied through LiteLLM:

1. Preserve Tool Metadata in tools/list
   - Modified _create_prefixed_tools() to mutate tools in place instead of
     reconstructing them, preserving all fields including metadata/_meta
   - This ensures ChatGPT can see 'openai/outputTemplate' URIs in tools/list
     and will call resources/read to fetch widgets

2. Preserve Full CallToolResult (structuredContent + metadata)
   - Changed call_mcp_tool() and _handle_managed_mcp_tool() to return full
     CallToolResult objects instead of just content
   - Updated error handlers to return CallToolResult with isError flag
   - Wrapped local tool results in CallToolResult objects
   - This preserves structuredContent and metadata fields needed for widget rendering

Files changed:
- litellm/proxy/_experimental/mcp_server/mcp_server_manager.py
- litellm/proxy/_experimental/mcp_server/server.py

Fixes issues where ChatGPT could not render MCP UI widgets when using
LiteLLM as an MCP gateway.

* feat(mcp): Preserve tool metadata and return full CallToolResult for ChatGPT UI widgets

- Preserve metadata and _meta fields when creating prefixed tools
- Return full CallToolResult instead of just content list
- Ensures ChatGPT can discover and render UI widgets via openai/outputTemplate
- Fixes metadata stripping that prevented widget rendering in ChatGPT

Changes:
- mcp_server_manager.py: Mutate tools in place to preserve all fields including metadata
- server.py: Return CallToolResult with structuredContent and metadata preserved
- Added test to verify metadata preservation

* fix: guard cost calculator when BaseModel lacks _hidden_params

---------

Co-authored-by: Afroz Ahmad <aahmad@Afrozs-MacBook-Pro.local>
Co-authored-by: Afroz Ahmad <aahmad@KNDMCPTMZH3.sephoraus.com>
2025-12-05 16:15:22 -08:00
yuneng-jiang 5afd03fef3 Mock server_root_path for test 2025-12-05 16:13:56 -08:00
Xingjian LiandGitHub 342723eb12 fix: Handle global location for Vertex AI Gemini image generation (#17255)
- Add check for 'global' location to use correct API endpoint
- Global location uses aiplatform.googleapis.com without region prefix
- Regional locations use {region}-aiplatform.googleapis.com format
- Fixes URL construction error when using vertex_location='global'

Resolves issue with gemini-3-pro-image-preview model on global endpoint
2025-12-05 15:56:38 -08:00
Cesar GarciaandGitHub 87f94172a9 fix(responses): Add image generation support for Responses API (#16586)
* fix(responses): Add image generation support for Responses API

Fixes #16227

## Problem
When using Gemini 2.5 Flash Image with /responses endpoint, image generation
outputs were not being returned correctly. The response contained only text
with empty content instead of the generated images.

## Solution
1. Created new `OutputImageGenerationCall` type for image generation outputs
2. Modified `_extract_message_output_items()` to detect images in completion responses
3. Added `_extract_image_generation_output_items()` to transform images from
   completion format (data URL) to responses format (pure base64)
4. Added `_extract_base64_from_data_url()` helper to extract base64 from data URLs
5. Updated `ResponsesAPIResponse.output` type to include `OutputImageGenerationCall`

## Changes
- litellm/types/responses/main.py: Added OutputImageGenerationCall type
- litellm/types/llms/openai.py: Updated ResponsesAPIResponse.output type
- litellm/responses/litellm_completion_transformation/transformation.py:
  Added image detection and extraction logic
- tests/test_litellm/responses/litellm_completion_transformation/test_image_generation_output.py:
  Added comprehensive unit tests (16 tests, all passing)

## Result
/responses endpoint now correctly returns:
```json
{
  "output": [{
    "type": "image_generation_call",
    "id": "..._img_0",
    "status": "completed",
    "result": "iVBORw0KGgo..."  // Pure base64, no data: prefix
  }]
}
```

This matches OpenAI Responses API specification where image generation
outputs have type "image_generation_call" with base64 data in "result" field.

* docs(responses): Add image generation documentation and tests

- Add comprehensive image generation documentation to response_api.md
  - Include examples for Gemini (no tools param) and OpenAI (with tools param)
  - Document response format and base64 handling
  - Add supported models table with provider-specific requirements

- Add unit tests for image generation output transformation
  - Test base64 extraction from data URLs
  - Test image generation output item creation
  - Test status mapping and integration scenarios
  - Verify proper transformation from completions to responses format

Related to #16227

* fix(responses): Correct status type for image generation output

- Add _map_finish_reason_to_image_generation_status() helper function
- Fix MyPy type error: OutputImageGenerationCall.status only accepts
  ['in_progress', 'completed', 'incomplete', 'failed'], not the full
  ResponsesAPIStatus union which includes 'cancelled' and 'queued'

Fixes MyPy error in transformation.py:838
2025-12-05 15:56:26 -08:00
Cesar GarciaandGitHub 829b06f53f Fix: Gemini image_tokens incorrectly treated as text tokens in cost calculation (#17554)
When Gemini image generation models return `text_tokens=0` with `image_tokens > 0`,
the cost calculator was assuming no token breakdown existed and treating all
completion tokens as text tokens, resulting in ~10x underestimation of costs.

Changes:
- Fix cost calculation logic to respect token breakdown when image/audio/reasoning
  tokens are present, even if text_tokens=0
- Add `output_cost_per_image_token` pricing for gemini-3-pro-image-preview models
- Add test case reproducing the issue
- Add documentation explaining image token pricing

Fixes #17410
2025-12-05 15:55:38 -08:00
2905feb889 feat(oci): Add textarea field type for OCI private key input (#17159)
This enables Oracle Cloud Infrastructure (OCI) GenAI authentication via the UI
by allowing users to paste their PEM private key content directly into a
multiline textarea field.

Changes:
- Add `textarea` field type to UI component system
- Configure OCI provider with proper credential fields (oci_key, oci_user,
  oci_fingerprint, oci_tenancy, oci_region, oci_compartment_id)
- Handle PEM content newline normalization (\\n -> \n, \r\n -> \n)
- Use OCIError for consistent error handling

Previously OCI only supported file-based authentication (oci_key_file), which
doesn't work for UI-based model configuration. This adds support for inline
PEM content via the new oci_key field.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude <noreply@anthropic.com>
2025-12-05 15:53:54 -08:00
Devaj ModyandGitHub e5f7a0b0a5 fix(streaming): add length validation for empty tool_calls in delta (#17523)
Fixes #17425

  - Add length check for tool_calls in model_response.choices[0].delta
  - Prevents empty tool call objects from appearing in streaming responses
  - Add regression tests for empty and valid tool_calls scenarios
2025-12-05 15:53:49 -08:00
Yuichiro UtsumiandGitHub d18e489872 fix(docs): remove source .env (#17466)
Remove `source .env` since `docker compose` automatically loads
the `.env` file.

Signed-off-by: utsumi.yuichiro <utsumi.yuichiro@fujitsu.com>
2025-12-05 15:53:05 -08:00
Chris LapaandGitHub 9c5f2ea827 Fixes #13652 - auth not working with ollama.com (#17191)
* ollama: adds missing auth headers if set

* ollama: sets ollama as openai compatible provider.

* ollama: adds tests for ollama auth
2025-12-05 15:52:54 -08:00
yuneng-jiang 852a1fee89 Support images in compare UI 2025-12-05 15:51:56 -08:00
Cesar GarciaandGitHub 2cf41d63a6 fix(gemini): use thought:true instead of thoughtSignature to detect thinking blocks (#17266)
The previous implementation incorrectly used `thoughtSignature` as the criterion
to detect thinking blocks. However, per Google's docs:
- `thought: true` indicates that a part contains reasoning/thinking content
- `thoughtSignature` is just a token for multi-turn context preservation
  (a part can have thoughtSignature without thought:true, e.g., function calls)

This caused functionCall data to leak into reasoning_content when using
Gemini 2.5 Pro with streaming + tools enabled.

Changes:
- _extract_thinking_blocks_from_parts now checks `part.get("thought") is True`
- Extract actual text content instead of json.dumps(part)
- Include signature only when present (optional in Gemini 2.5)

Refs:
- https://ai.google.dev/gemini-api/docs/thinking
- https://ai.google.dev/gemini-api/docs/thought-signatures
2025-12-05 15:51:51 -08:00
Irfan Sofyana PutraandGitHub bffc118170 fix bedrock qwen anthropic beta (#17467) 2025-12-05 15:47:34 -08:00
Ishaan Jaffer e519462efa fix MYPY linting 2025-12-05 15:46:26 -08:00
Ishaan Jaffer ae065525ea fix ZAI 2025-12-05 15:46:26 -08:00
Dominic FallowsandGitHub 2ffe8ee204 fix(presidio): handle empty content and error dict responses (#17489)
- Skip empty/whitespace text before calling Presidio API
- Handle error dict responses gracefully (e.g., {'error': 'No text provided'})
- Add defensive error handling for invalid result items
- Add comprehensive test coverage for empty content scenarios

Fixes crash in tool/function calling where assistant messages have empty content.
2025-12-05 15:45:19 -08:00
dependabot[bot]GitHubdependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
5fb7530d8c build(deps): bump jws from 3.2.2 to 3.2.3 in /ui/litellm-dashboard (#17494)
Bumps [jws](https://github.com/brianloveswords/node-jws) from 3.2.2 to 3.2.3.
- [Release notes](https://github.com/brianloveswords/node-jws/releases)
- [Changelog](https://github.com/auth0/node-jws/blob/master/CHANGELOG.md)
- [Commits](https://github.com/brianloveswords/node-jws/compare/v3.2.2...v3.2.3)

---
updated-dependencies:
- dependency-name: jws
  dependency-version: 3.2.3
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-12-05 15:44:15 -08:00
Ishaan JaffandGitHub f02df3035a [Feat] Allow using dynamic rate limit/priority reservation on teams (#17061)
* use helper to get key/team priority

* test_team_metadata_priority

* docs team priority
2025-12-05 15:42:27 -08:00
yuneng-jiangandGitHub cb18af542e Merge pull request #17498 from BerriAI/litellm_customer_usage_backend
[Feature] Customer (end user) Usage
2025-12-05 15:31:08 -08:00
Devaj ModyandGitHub 6ff7ed14f6 fix(team): use organization.members instead of deprecated organization.users (#17557)
Fixes #17552

  - Change Prisma include from 'users' to 'members'
  - Use LiteLLM_OrganizationTableWithMembers type for membership validation
  - Access organization.members instead of organization.users
  - Add tests for membership validation
2025-12-05 15:30:59 -08:00
Cesar GarciaandGitHub 7259de2f12 feat: add Mistral Large 3 model support (#17547)
Add Mistral Large 3 (675B MoE) to model catalog for both providers:
- mistral/mistral-large-3
- azure_ai/mistral-large-3

Specs:
- 256k context window
- $0.50/1M input, $1.50/1M output
- Supports vision (multimodal)
- Supports function calling

Closes #17527
2025-12-05 15:26:20 -08:00