Commit Graph
93 Commits
Author SHA1 Message Date
Lei Nie 1716956520 test(responses): update expected events and add mock test for content_part.added
- Update test_anthropic_via_responses_api expected_events to include
  CONTENT_PART_ADDED between OUTPUT_ITEM_ADDED and OUTPUT_TEXT_DELTA
- Add TestEnsureOutputItemContentPartAdded with 3 mock tests:
  message item emits content_part.added, reasoning item does not,
  and the event is only emitted once
2026-03-23 22:29:50 +00:00
Sameer Kankute 021540b2e2 fix: prevent double prompt management in async path, preserve optional params
- aresponses() now pops prompt_id from kwargs after the async hook runs
  and passes merged_optional_params via _async_prompt_merged_params.
  responses() checks for this internal kwarg first and skips the sync
  hook entirely when present — eliminating double-merge of template
  messages.
- merged_optional_params from async_get_chat_completion_prompt is no
  longer discarded (_); it flows through to local_vars in responses().
- Async tests now assert get_chat_completion_prompt.assert_not_called()
  to directly detect any double-execution regression.

Made-with: Cursor
2026-03-18 17:09:28 +05:30
Sameer Kankute d333dc4077 address greptile review feedback (greploop iteration 1)
- Fix async path: call async_get_chat_completion_prompt in aresponses()
  before executor dispatch, mirroring acompletion() in main.py. Discard
  merged_optional_params in async path (sync responses() handles them
  via local_vars), avoiding TypeError from duplicate kwargs in partial().
- Fix provider re-resolution: replace "/" in model heuristic with
  model != original_model comparison so bare model names are handled.
- Add 3 async tests covering hook invocation, optional param
  propagation, and non-message item filtering in aresponses().

Made-with: Cursor
2026-03-18 16:49:07 +05:30
Sameer Kankute b32f5ea379 Fix greptile comments 2026-03-18 16:37:52 +05:30
Sameer Kankute 0d70864d09 Add support for prompt management for responses 2026-03-18 15:48:31 +05:30
yuneng-jiangandClaude Opus 4.6 a81a1968ed Fix test isolation: clear litellm.callbacks and model_fallbacks between tests
The isolate_litellm_state conftest fixture saved/restored litellm.callbacks
but never cleared it before each test, unlike the other callback lists. It
also didn't handle litellm.model_fallbacks. Leaked callbacks and fallback
config caused mocked tests to route through Router/fallback paths, hitting
real APIs with mock keys.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-15 16:43:15 -07:00
Chesars feed274aa3 Reapply "feat: add model_cost aliases expansion support"
This reverts commit 3d2df7e8b5.
2026-03-12 13:36:57 -03:00
Chesars 1be6b31e2f merge: resolve conflicts between main and litellm_oss_staging_03_11_2026 2026-03-12 09:38:31 -03:00
Varad KhondeandGitHub 9b15f639a4 fix(responses): merge parallel function_call items into single assistant message (#23116) 2026-03-09 09:01:31 -07:00
Sameer Kankute d143df8591 Add tests for resp
onses websocket
2026-03-04 18:27:06 +05:30
Shivam RawatandGitHub d49abf8577 [Fix] Pass MCP auth headers from request into tool fetch for /v1/responses and chat completions (#22291)
* fixed dynamic auth for /responses with mcp

* fixed greptile concern
2026-02-27 19:15:51 -08:00
Ishaan JaffandGitHub 6ec16d583d fix(test): add timeout to flush() call to prevent 300s hang in CI (#21819)
GLOBAL_LOGGING_WORKER.flush() calls queue.join() which blocks until all
items are task_done(). In CI with pytest-asyncio, each test gets a fresh
event loop so the worker reinitializes its queue - items from a previous
test never get task_done(), causing an infinite hang.

Fix: wrap flush() with asyncio.wait_for(..., timeout=10.0).
2026-02-21 14:10:57 -08:00
Ishaan JaffandGitHub 8483477512 fix(test): add asyncio.sleep(0) before flush() to prevent hang in test_async_no_duplicate_spend_logs (#21813) 2026-02-21 13:09:36 -08:00
Ishaan JaffandGitHub 02670582c5 fix(tests): replace asyncio.sleep(1) with event-based wait in metadata callback tests (#21805) 2026-02-21 12:40:06 -08:00
Sameer Kankuteandyuneng-jiang 36fd14357c FIx: replace deprecated claude-3-7-sonnet-20250219 with claude-4-sonnet-20250514 2026-02-20 17:27:59 -08:00
Sameer Kankute 5d8f2196d1 Add test case 2026-02-20 16:22:44 +05:30
Sameer KankuteandGitHub bd0c80406f Merge pull request #21326 from BerriAI/litellm_oss_staging_02_16_2026
Litellm oss staging 02 16 2026
2026-02-18 17:47:57 +05:30
Julio Quinteros ProandClaude Sonnet 4.6 c3346962a9 fix: replace silent if-hasattr guards with unconditional assertions in MCP streaming tests
The `if hasattr(...)` guards in test_acompletion_with_mcp_adds_metadata_to_streaming
and test_acompletion_with_mcp_streaming_metadata_in_correct_chunks could silently skip
the provider_specific_fields assertions if chunks lacked choices/delta. Replace with
unconditional `assert hasattr(...)` so failures surface immediately.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-17 21:42:31 -03:00
Julio Quinteros ProandClaude Opus 4.5 ab6d2eefb9 fix: improve test isolation for parallel execution
Fixes test failures that occur during parallel test execution (pytest -n 4)
due to module reloading issues with conftest.py reloading litellm.

Changes:
- Add module reload fixtures to ensure fresh references after conftest reloads
- Use patch.object and string-based patches instead of direct attribute assignment
- Use class name comparison instead of isinstance for reloaded modules
- Handle case where litellm is missing from sys.modules during parallel runs
- Move stream consumption inside patch contexts to avoid real API calls
- Mock litellm.acompletion instead of low-level HTTP handlers
- Add skipif decorator for enterprise-only test classes

Affected test files:
- test_container_integration.py
- test_responses_background_cost.py
- test_huggingface_embedding_handler.py
- test_vertex_ai_rerank_integration.py
- test_volcengine_responses_transformation.py
- test_pillar_guardrails.py
- test_litellm_pre_call_utils.py
- test_proxy_server.py
- test_converse_transformation.py
- test_chat_completions_handler.py
- test_aresponses_api_with_mcp.py
- test_anthropic_experimental_pass_through_messages_handler.py

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-17 21:28:23 -03:00
Chiranjeevisantosh MadugundiGitHubCursorKrish Dholakiagreptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
dcff3260df fix: preserve metadata for custom callbacks on codex/responses path (… (#21243)
* fix: preserve metadata for custom callbacks on codex/responses path (#21204)

- Use metadata or litellm_metadata when calling update_environment_variables
  in responses/main.py so metadata is not overwritten by None on the
  bridge path (completion -> responses API).
- Add tests for metadata in custom callback for codex models and for
  litellm_metadata in aresponses().

Co-authored-by: Cursor <cursoragent@cursor.com>

* Update tests/test_litellm/responses/test_metadata_codex_callback.py

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Krish Dholakia <krrishdholakia@gmail.com>
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
2026-02-16 08:59:38 -08:00
Julio Quinteros Pro 8d15996b5a test: Fix flaky tests with proper mocking and skip conditions
1. test_acompletion_with_mcp_streaming_metadata_in_correct_chunks:
   - Moved stream consumption inside patch context to avoid real API calls
   - The previous implementation had assertions outside the `with patch(...)`
     block, causing real OpenAI API calls when consuming the stream

2. TestCheckResponsesCost tests:
   - Added skip condition when litellm_enterprise module is not available
   - These tests import from litellm_enterprise.proxy.common_utils.check_responses_cost
     which is only available in the enterprise version
2026-02-15 13:08:30 -03:00
Krish DholakiaandGitHub fa0b26c611 ci/cd fixes (#21218)
* fix: add a2a-sdk to dev deps

* fix: fix test

* fix: update poetry lock

* test: cleanup bad/hanging tests
2026-02-14 12:11:53 -08:00
Lei NieandSameer Kankute e9c99f41bd fix(vertex_ai): forward extra_body to completion transformation handler (#20950)
* fix(vertex_ai): forward extra_body to completion transformation handler

The responses() function accepted extra_body as a named parameter but
did not pass it to response_api_handler when responses_api_provider_config
was None (completion transformation path), silently dropping it.

Also adds deep-merge support for extra_body in Vertex AI Gemini
transformation, so dict values like generationConfig are merged rather
than replaced.

* refactor(vertex_ai): extract _merge_extra_body to fix PLR0915 lint

Move the extra_body merge loop into a helper function to keep
_transform_request_body under the 50-statement limit.
2026-02-13 18:25:32 +05:30
Ishaan JaffandGitHub 3d9b145b04 [Feat] Adds support for server-side compaction on the OpenAI Responses API context_management (#21058)
* test_responses_api_context_management_server_side_compaction

* Server-side compaction

* docs fix

* test_responses_api_shell_tool
2026-02-12 10:00:30 -08:00
Sameer KankuteandGitHub 5222fd4795 Merge pull request #20783 from BerriAI/litellm_oss_staging_02_09_2026
litellm oss staging 09/02/2026
2026-02-10 18:02:14 +05:30
Lei NieandSameer Kankute 08824f9912 [Bug] Fix missing image_tokens in Responses API output_tokens_details (#20404)
When transforming chat completion responses to Responses API format,
image_tokens from completion_tokens_details was not being included
in output_tokens_details. This affected Vertex AI/Gemini models that
return image token counts in candidatesTokensDetails with modality="IMAGE".

The fix adds image_tokens handling alongside existing reasoning_tokens
and text_tokens transformation.
2026-02-10 16:10:07 +05:30
Emerson GomesSameer Kankutegreptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
28e15f4fd6 fix(responses): preserve cached tool call objects in tool result recovery (#20700)
* fix(responses): preserve cached tool call objects in tool result recovery

* fix(responses): support attr-based cached tool call recovery

* Update litellm/responses/litellm_completion_transformation/transformation.py

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>

---------

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
2026-02-10 16:00:36 +05:30
Emerson Gomes cf17a440cd fix(responses): guard ambiguous tool-call index reuse 2026-02-08 08:53:17 -06:00
Emerson Gomes 68d788c84d fix(responses): preserve streamed tool deltas when id is omitted 2026-02-08 08:48:39 -06:00
Nate TessmanandSameer Kankute d7997db912 fix: Include hidden params in chat response to responses api response transformation (#20084)
* Include hidden_params in chat completion to responses transformation

* add tests
2026-02-02 18:24:21 +05:30
Cesar GarciaandGitHub b1968a8e33 fix(responses): update local_vars with detected provider (#19782) (#19798)
When using the responses API with provider-specific params (aws_*, vertex_*)
without explicitly passing custom_llm_provider, the code crashed with:
AttributeError: 'NoneType' object has no attribute 'startswith'

Root cause: local_vars was captured via locals() before get_llm_provider()
detected the provider from the model string (e.g., "bedrock/..."), so
custom_llm_provider remained None when processing provider-specific params.

Fix: Update local_vars["custom_llm_provider"] after get_llm_provider() call
so the detected provider is available for param processing.

Affected provider-specific params:
- aws_* (aws_region_name, aws_access_key_id, etc.) for Bedrock/SageMaker
- vertex_* (vertex_project, vertex_location, etc.) for Vertex AI
2026-01-26 20:47:35 -08:00
Yuta Saito 919033a6d0 fix: include tool arguments in proxy_server_request for spend logs callbacks 2026-01-23 16:36:37 +09:00
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
YutaSaitoandGitHub 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 KankuteandGitHub 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
victorigualadaandGitHub 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
victorigualadaandGitHub 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 KankuteandGitHub 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 KestnerandGitHub 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 HamirandGitHub 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 HamirandGitHub 24edbccf5c [Fix] Security - Remove example API keys with high entropy (#18255) 2025-12-19 10:09:50 -08:00