Commit Graph

61 Commits

Author SHA1 Message Date
Yuta Saito 6a60b3d848 test: completions mcp output test 2026-01-23 15:17:14 +09:00
Yuta Saito ed67bf2705 feat: Add MCP tools response to chat completions 2026-01-22 15:32:04 +09:00
YutaSaito 4a14a53ae8 Merge pull request #19469 from BerriAI/litellm_feat_mcp_spendlogs
[feat] mcp spendlogs
2026-01-22 05:29:21 +09:00
Sameer Kankute 3a0d166eb0 Fix: tool call streaming in chat completino brigde 2026-01-21 12:14:02 +05:30
Yuta Saito caf5f7f8ae test: add test 2026-01-21 14:51:56 +09:00
Sameer Kankute a3c1f4758d Merge branch 'main' into litellm_consistent_id_streaming_responses 2026-01-20 19:02:23 +05:30
Sameer Kankute f945fd9a84 Fix: ID mismatch between text-start and text-delta 2026-01-20 11:15:37 +05:30
victorigualada 7d6d419a67 fix: preserve tool output ordering for gemini in responses bridge (#19360)
* fix: preserve tool output ordering for gemini in responses bridge

- Keep function_call_output adjacent to its function_call when building chat messages
- Normalize function_call_output.output lists (input_* parts) into tool message content

* fix test

* small improvements
2026-01-19 20:37:59 -08:00
victorigualada 581d086c20 fix(responses): stream tool call events in completion bridge (#19368)
Emit Responses API streaming events for tool calls when the underlying chat stream contains tool_call deltas, and recover tool calls into the stream when they only appear in the final response.
2026-01-19 20:29:50 -08:00
Yuta Saito ba43f742ab fix: event loop nesting issue in MCP chat completions with streaming
Problem: When using MCP tools with  and , the following error occurred:

RuntimeError: Timeout context manager should be used inside a task
2026-01-15 15:36:56 +09:00
Sameer Kankute 1b34d17935 Fix: Responses content can't be none 2026-01-14 12:13:18 +05:30
Dima-Mediator 7c61933bc5 Fix image tokens spend logging for /images/generations 2026-01-12 23:07:08 -05:00
Sameer Kankute e7efd51bd7 Merge branch 'main' into litellm_staging_01_06_2026 2026-01-09 17:06:17 +05:30
Sameer Kankute 9d5eb60ff1 Fix: test_text_format_to_text_conversion - properly mock handler to avoid API calls 2026-01-08 16:37:12 +05:30
Wiley Kestner 9e6714fe1b Tally total_tokens in response if missing (#18468) (#18445)
Calculate `total_tokens` in usage data in Response manually if:

    - `total_tokens` is missing
    - `total_tokens` can be calculated from input and output tokens

Run the test for this feature with:

`poetry run pytest tests/test_litellm/responses/test_responses_utils.py -k "test_transform_response_api_usage_calculates_total_from_input_and_output_tokens_if_available" -v`
2026-01-06 20:34:02 +05:30
Alexsander Hamir 5534038e93 Fix CI: Revert security scan changes and add GitGuardian ignore rules (#18358) 2025-12-22 17:03:53 -08:00
Ishaan Jaffer 6112160a16 Revert "[Fix] Security - Remove example API keys with high entropy (#18255)"
This reverts commit 24edbccf5c.
2025-12-20 20:48:11 +05:30
Alexsander Hamir 24edbccf5c [Fix] Security - Remove example API keys with high entropy (#18255) 2025-12-19 10:09:50 -08:00
Sameer Kankute 54b09cab28 Add test for handling provider specific tools 2025-12-15 17:41:38 +05:30
Ishaan Jaff 24d6ec67c7 [QA] Cursor Integration x LiteLLM (#17855)
* fix utils.py

* ValidUserMessageContentTypesLiteral

* add _transform_tool_choice

* _transform_responses_api_content_to_chat_completion_content

* TestContentTypeTransformation

* test_map_tool_choice_string_auto

* fix validate_chat_completion_user_messages

* fix _is_input_item_tool_call_output

* fix LiteLLMCompletionResponsesConfig
2025-12-13 12:49:45 -08:00
Yuta Saito 864b61b433 fix: support ResponseFunctionToolCall in follow-up input 2025-12-13 07:55:13 +09:00
Yuta Saito 48579eafe3 fix: strip mcp server prefixes in responses 2025-12-13 07:17:50 +09:00
Yuta Saito 8cccf3e9f0 fix: update MCP handler invocation to pass full call context from main.py 2025-12-12 06:41:58 +09:00
Yuta Saito 6393277bf4 fix: separate MCP handling out of main.py 2025-12-11 10:39:14 +09:00
Yuta Saito ed5cbdac2f feat: add support for using MCPs on /chat/completions 2025-12-10 10:55:33 +09:00
Sameer Kankute 41f0cf8523 Add usage details in responses usage object 2025-12-08 11:51:47 +05:30
Ishaan Jaffer c78c2cf3e9 test_async_no_duplicate_spend_logs 2025-12-06 16:14:56 -08:00
Ishaan Jaffer 71ea926f9a test_no_duplicate_spend_logs 2025-12-06 09:56:05 -08:00
Alexsander Hamir 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
Cesar Garcia 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
soo-jin.kim a2a45ce8c9 fix: prevent duplicate spend logs in Responses API for non-OpenAI providers (#16992)
* fix: prevent duplicate spend logs in Responses API for non-OpenAI providers

Fixes #15740

This fixes a logging duplication bug where using kwargs.pop() removed
the litellm_logging_obj before passing kwargs to internal acompletion()
calls, causing duplicate spend log entries for providers without native
Responses API support (Anthropic, Gemini, etc).

By changing from pop() to get(), the logging object is preserved and
reused across the internal completion call, preventing duplicate entries
and maintaining correct cost tracking.

* test: add test for logging object preservation in responses API

Verify that litellm_logging_obj is preserved in kwargs when calling
responses(), ensuring no duplicate spend log entries are created.
2025-11-23 21:57:01 -08:00
Sameer Kankute f804ab6de5 Add LLM provider response headers to Responses API (#16091)
* Add llm headers to responses api

* fix mock test
2025-11-01 13:25:56 -07:00
Ishaan Jaffer 159db27d5c fix test claude-sonnet-4-5-20250929 2025-10-31 18:13:29 -07:00
Ishaan Jaffer 33371d18f4 test fix claude-sonnet-4-5-20250929 2025-10-28 19:05:13 -07:00
Ishaan Jaffer 1b49dba1dd fix claude-sonnet-4-5 2025-10-28 17:37:08 -07:00
Ishaan Jaffer e80bba83e3 test fix 2025-10-22 09:29:04 -07:00
soo-jin.kim 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
Sameer Kankute 44495c0117 fix encrypted content error (#15782) 2025-10-21 23:29:48 -07:00
Ishaan Jaff 157739da01 [Bug]: Fix Incorrect status value in responses api with gemini (#15753)
* _map_chat_completion_finish_reason_to_responses_status

* test_transform_chat_completion_response_with_reasoning_content

* test_transform_chat_completion_response_output_item_status
2025-10-20 17:58:56 -07:00
Krrish Dholakia 1949436047 test: update test 2025-10-12 21:58:06 -07:00
Krrish Dholakia 15b5e6f5d9 feat(responses_api/): fix missing streaming events on responses api <-> chat completion bridge
ensure we are passing the required events when streaming non-openai models via responses api
2025-10-10 14:53:15 -07:00
Sameer Kankute 73f96712f5 fix the reasoningresponse id (#15265) 2025-10-07 11:24:29 -07:00
Adam Tao 9b0eaf0989 test: add a testcase for cached_tokens
Signed-off-by: Adam Tao <tcx4c70@gmail.com>
2025-09-18 18:40:11 +08:00
soojin 488b373835 test: add unit tests for response api bug fixes 2025-09-13 23:10:15 +09:00
Sameer Kankute 231d54741f Move test to test_litellm/ folder 2025-09-05 10:40:26 +05:30
Sameer Kankute ad9f54a192 Move test to test_litellm/ folder 2025-09-05 10:08:34 +05:30
Sameer Kankute f7f106f8b8 Move test to test_litellm/ folder 2025-09-05 10:00:58 +05:30
Sam Xie ee13c65701 [Bug]: /responses endpoint proxy ignores extra_headers in GitHub Copilot (#13775)
* fix: pass extra_headers parameter through responses API transformation chain

Ensure extra_headers parameter is properly forwarded from the responses() function
through the transformation handler and config to maintain header propagation in
litellm_completion_request dict.

* Add tests
2025-08-27 12:35:09 -07:00
Ishaan Jaff cf64033044 test fix 2025-08-23 14:04:41 -07:00
Ishaan Jaff 56c16fc6f6 [Performance] Reduce Significant CPU overhead from litellm_logging.py (#13895)
* fix: litellm.configured_cold_storage_logger

* fix Session Management - Non-OpenAI Models docs

* ruff fix

* test fix
2025-08-22 16:17:57 -07:00