Commit Graph

44 Commits

Author SHA1 Message Date
Sameer Kankute 00a810e92d feat(openai): round-trip Responses API reasoning_items in chat completions
Made-with: Cursor
2026-03-27 20:25:08 +05:30
Ethan T. 98890e771d style: apply black formatting to test file 2026-03-14 21:19:03 +08:00
Ethan T. 71c9ba0b1b test: add tests for file type to input_file mapping 2026-03-14 15:12:54 +08:00
Cursor Agent ff145398d5 fix(ci): skip tests requiring openai>=2.x and MCP M2M oauth2_flow
- Skip test_apply_patch_tool_call_converted_to_chat_completion_tool_call
  when openai.types.responses.response_apply_patch_tool_call is unavailable
  (CI uses openai==1.100.1 which doesn't have this module)
- Skip MCP M2M tests (test_m2m_credentials_forwarded_to_server_model,
  test_m2m_drops_incoming_oauth2_headers) that fail because PR #23187
  changed has_client_credentials to require explicit oauth2_flow opt-in
  but _execute_with_mcp_client was not updated to pass it through
- Revert source code change to rest_endpoints.py that auto-inferred
  oauth2_flow (regression risk: this changes MCP OAuth behavior)

Co-authored-by: yuneng-jiang <yuneng-jiang@users.noreply.github.com>
2026-03-13 01:09:56 +00: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
Sameer Kankute cd80213f1c Merge pull request #23151 from BerriAI/litellm_preserve-reasoning-summary-for-responses-api
fix(openai): preserve reasoning_effort summary field for Responses API
2026-03-10 18:18:46 +05:30
Sameer Kankute 9bc7357e7c Merge pull request #23222 from BerriAI/litellm_oss_staging_02_18_2026
Litellm oss staging 02 18 2026
2026-03-10 17:46:06 +05:30
Sameer Kankute 3f17a63b81 Merge branch 'main' into litellm_oss_staging_03_02_2026 2026-03-10 17:19:37 +05:30
Krish Dholakia 992510154c Merge branch 'main' into litellm_oss_staging_02_18_2026 2026-03-09 19:48:46 -07:00
Sameer Kankute 8cf80a14d9 fix(openai): preserve reasoning_effort summary field for Responses API
When reasoning_effort is passed as a dict with additional fields like 'summary' or 'generate_summary', preserve the full dict format instead of normalizing it to a string. This ensures that when requests are routed to the OpenAI Responses API, all reasoning parameters are correctly included.

The normalization to string format now only happens for simple dicts with just the 'effort' key, which is appropriate for the Chat Completions API.

Fixes issue where summary field was being dropped when routing gpt-5.4+ requests with tools + reasoning to Responses API.

Made-with: Cursor
2026-03-09 18:28:11 +05:30
David Steele 39cdd3dc98 test(streaming): add comprehensive parallel tool call integration test
Add test_parallel_tool_calls_comprehensive_streaming_integration which
synthesizes the full 10-event Responses API SSE sequence with split
argument deltas and asserts all fix invariants together:

1. output_item.done emits no finish_reason (no premature stream end)
2. Each call_id appears exactly once (no duplicate tool_call chunks)
3. Split argument deltas assemble to correct final JSON
4. Exactly one finish event, at the terminal response.completed chunk
5. Parallel tool calls have distinct indices (output_index 0 and 1)

All 24 unit tests pass.
2026-03-04 10:17:20 +00:00
David Steele 565a52780b Merge remote-tracking branch 'upstream/main' into pr-22553 2026-03-03 09:48:39 +00:00
Kerem Turgutlu 8c8d1debee fix: preserve usage/cached_tokens in Responses API streaming bridge (#22194)
The response.completed handler in the completion→responses streaming
bridge was discarding the usage object, causing prompt_tokens_details
(and cached_tokens) to always be None when streaming with models that
use the Responses API (e.g. gpt-5.2-codex, gpt-5.3-codex).

Extract usage from the response.completed event and translate it via
the existing _transform_response_api_usage_to_chat_usage helper.

Fixes #22192
2026-03-02 21:51:06 -08:00
David Steele a14ef27009 test: fix copy-paste print message in multi-tool-call test 2026-03-02 09:08:03 +00:00
David Steele a3cdf6c895 fix(streaming): don't emit finish_reason on output_item.done for function_call
The response.output_item.done handler for function_call type was emitting
finish_reason='tool_calls' and a duplicate tool_call delta. This caused
premature stream termination after the first tool call in multi-tool
scenarios — downstream wrappers (e.g. AnthropicStreamWrapper) would close
the stream before subsequent tool calls arrived.

The response.completed event already inspects the response output list and
emits finish_reason='tool_calls' when function_call items are present, so
output_item.done does not need to (and must not) do so.

This mirrors the existing fix for message-type output_item.done (#17246).

Updated test_function_call_done_emits_is_finished (renamed) to assert
finish_reason=None and no duplicate delta. Updated test_text_plus_tool_calls_sequence
to match. Added test_multi_tool_call_stream_no_premature_finish which exercises
a synthetic 2-tool-call stream and verifies no premature termination.
2026-03-02 08:59:59 +00:00
Cesar Garcia 8f02d2d840 Merge pull request #21337 from Chesars/fix/streaming-parallel-tool-call-index
fix(responses): use output_index for parallel tool call streaming indices
2026-02-27 17:54:19 -03:00
jtsaw 8d5db4f712 fix handling of ResponseApplyPatchToolCall in completion bridge (#20913)
* fix handling of ResponseApplyPatchToolCall in completion bridge

* refactor

* style: fix black formatting

* fix: clean up lint errors in test file (unused imports, print statements, formatting)

* refactor: extract _map_optional_params_to_responses_api to fix PLR0915

* what

* this linter cannot be me

* revert cause idk what's going on

* weird

* idk why this got removed

* revert more stuff

* revert pt 3
2026-02-17 21:10:50 -08:00
Chesars 0664ec51d8 fix(responses): use output_index for parallel tool call streaming indices
Fixes #21331 — the Responses API streaming bridge hardcoded index=0 for
all tool call chunks, making parallel tool calls indistinguishable.
Now reads output_index from the Responses API chunk instead.
2026-02-16 18:00:42 -03:00
Felipe Felix 504c70f4e0 fix(responses-api): return finish_reason='tool_calls' when response.completed contains function_call items (#19745)
When using the Responses API (e.g., Azure gpt-5.1-codex-mini), the response.completed
event was always returning finish_reason='stop', even when the response contained
function_call items in its output. This caused agents like OpenCode to incorrectly
conclude the stream ended without tools to execute, breaking tool/function calling
workflows.

The fix inspects the response.output field in the response.completed event to determine
the correct finish_reason:
- 'tool_calls' when output contains function_call items
- 'stop' otherwise (text-only responses)

Added tests to verify:
- response.completed with function_call output returns finish_reason='tool_calls'
- response.completed with message-only output returns finish_reason='stop'
- response.completed with empty output returns finish_reason='stop' (backward compat)

Co-authored-by: Krish Dholakia <krrishdholakia@gmail.com>
2026-02-16 09:19:57 -08:00
Zero Clover 7044512407 Fix responses bridge metadata isolation (#20484) 2026-02-12 19:39:05 +05:30
naaa760 0cb6b58768 fix(proxy): forward extra_headers in chat 2026-02-04 08:56:50 +05:30
Sameer Kankute fdb9679657 Add annotations to completions responses API bridge 2026-01-07 14:30:31 +05:30
Sameer Kankute bb00a53786 Put reasoning summary behind feat flag 2026-01-06 11:36:20 +05:30
Sameer Kankute 0f8e4364d6 Replace summary param as detailed 2026-01-05 11:24:35 +05:30
Sameer Kankute 42d4aab3e7 Add mapping for reasoning effort to summary of responses API 2026-01-05 11:21:34 +05:30
Cesar Garcia 138b415e81 fix(responses-api): use list format with input_text for tool results (#18257)
The Responses API expects tool results to use input_text/input_image types,
not output_text. This fix ensures consistent list format for all tool results:
- String content → [{"type": "input_text", "text": "..."}]
- Image content → [{"type": "input_image", "image_url": "..."}]

This resolves the conflict between tests that expected different formats
and aligns with OpenAI's Responses API requirements.

Fixes the regression introduced in #18226.
2025-12-20 13:46:14 +05:30
Sameer Kankute 84e4fc3fab Merge pull request #18226 from Chesars/fix/responses-api-tool-calls-transformation
fix(responses-api): fix tool calls transformation in completion bridge
2025-12-19 13:41:55 +05:30
Chesars bd36b1261f test: add tests for tool calls transformation fixes
- test_tool_message_output_is_string_not_list: verifies function_call_output.output is a string
- test_multiple_tool_calls_in_single_choice: verifies multiple tool calls are grouped in one choice
2025-12-18 22:01:29 -03:00
Sameer Kankute dafd123756 Fix : tool calling with response api bridge 2025-12-18 19:54:15 +05:30
Krish Dholakia 26fd6d5362 Guardrails API - support LLM tool call response checks on /chat/completions, /v1/responses, /v1/messages on regular + streaming calls (#17619)
* fix(unified_guardrails.py): send all chunks on completion of final stream

* feat(generic_guardrail_api.py): handle tool call response on streaming LLM responses

* fix(anthropic/chat/guardrail_translation): initial commit adding anthropic tool response streaming guardrails

enables guardrail checks on tool response from llm's to work via `/v1/messages`

* feat(anthropic/): working guardrail checks on tool response from LLMs

ensures guardrail checks on anthropic /v1/messages works as expected

* feat(responses/guardrail_translation): support tool call response guardrails on streaming for /v1/responses

ensures complete coverage of tool call responses

* refactor(openai.py): refactor to use consistent pydantic model for responses api tool response on streaming

enables non-openai model tool call response to work correctly with guardrail checks on /v1/responses

* test: update tests

* fix: fix linting error

* fix: fix failing tests

* fix: fix import errors

* fix(openai/chat/guardrail_transformation): fix final chunk returned on streaming
2025-12-15 18:19:52 +05:30
Cesar Garcia 6a3e6465ea fix(completion): transform image content in tool results for Responses API (#17799)
When using litellm.completion() with model="openai/responses/...", images
in tool message content were not being transformed from Chat Completion
format to Responses API format.

Chat Completion format: {"type": "image_url", "image_url": {"url": "..."}}
Responses API format: {"type": "input_image", "image_url": "..."}

This caused OpenAI to reject the request with error 400 since "image_url"
is not a valid type for function_call_output content.
2025-12-11 08:21:05 -08:00
Cesar Garcia fd9ff90307 fix(responses): prevent streaming tool_calls from being dropped when text + tool_calls (#17652)
When OpenAI Responses API returns both text AND tool_calls, the bridge
transformation was emitting is_finished=True after the text message completed,
causing subsequent tool_call chunks to be dropped.

The fix:
- response.output_item.done for messages no longer emits is_finished=True
- Added handler for response.completed to properly signal stream end
2025-12-08 18:51:59 -08:00
Sameer Kankute cd65a84abd Merge pull request #16844 from Chesars/fix/response-format-to-text-format-bridge-conversion
fix: Support response_format parameter in completion -> responses bridge
2025-11-26 08:51:09 +05:30
Alex Huang 3b6f3e48cb Fix optional param mapping (#16852)
* Direct string check instead of tuple string inclusion check

* Add test
2025-11-19 19:10:04 -08:00
Nigel Kukard c5c563c302 fix: fixed openai conversion from responses to completions (#16864)
- Fix blank function name in completions response when using native function calling
- Fix Enum name being used instead of Enum value for comparison in chunk conversion
- Added additional tests to cover changes

Thanks to @mcowger for the invaluable assitance with figuring this issue out!

Fixed #16863
2025-11-19 19:02:52 -08:00
Chesars 3e58fe42b7 fix: Support response_format parameter in completion -> responses bridge
Fixes #16810

## Problem

When using completion() with models that have mode: "responses" (like o3-pro,
gpt-5-codex), the response_format parameter with JSON schemas was being ignored
or incorrectly handled, causing:
- Large schemas (>512 chars) to fail with "metadata.schema_dict_json: string too long" error
- Structured outputs to be silently dropped
- Users' code to break unexpectedly

## Root Cause

The completion -> responses bridge in
litellm/completion_extras/litellm_responses_transformation/transformation.py
was missing the conversion of response_format (Chat Completion format) to
text.format (Responses API format).

The inverse bridge (responses -> completion) already had this conversion
implemented in commit 29f0ed223a, but the completion -> responses direction
was incomplete.

## Solution

Added _transform_response_format_to_text_format() method that converts:
- response_format with json_schema → text.format with json_schema
- response_format with json_object → text.format with json_object
- response_format with text → text.format with text

Updated transform_request() to detect and convert response_format parameter
before sending to litellm.responses().

## Changes

- Added _transform_response_format_to_text_format() method (lines 592-647)
- Modified transform_request() to handle response_format (lines 199-203)
- Added comprehensive tests to validate the conversion

## Testing

- 5 new unit tests covering all conversion scenarios
- Real API test with OpenAI confirming large schemas (>512 chars) work
- No more metadata.schema_dict_json errors

## Impact

Users can now use completion() with models that have mode: "responses" and:
- Use large JSON schemas without hitting metadata 512 char limit
- Get proper structured outputs
- Have their existing code continue working
2025-11-19 17:07:46 -03:00
Sameer Kankute 9e93d65ee2 Add extra_body support for response api params from chat completion (#16765) 2025-11-18 20:05:47 -08:00
Krrish Dholakia fed1ba2891 feat(openai/): convert chat completion tool calls to responses api
enables gpt-5-codex to work on claude code

 Closes LIT-1088
2025-10-10 19:41:11 -07:00
Krrish Dholakia f49f540b6d feat(litellm_responses_transformation/transformation.py): parse thinking content in response<-> chat completion bridge
allows gpt-5 to return thinking content when called via responses api
2025-10-10 18:29:37 -07:00
Ishaan Jaff 7ff93cd1b1 Revert "Merge pull request #12865 from aholmberg/holmberg/default-reasoning"
This reverts commit 68f4847659, reversing
changes made to df39320889.
2025-08-30 13:07:33 -07:00
Adam Holmberg 2ce03d9735 fix: make gemini and openai responses return reasoning by default
This aligns the proxy experience with other models that think
automatically (e.g. Deepseek R1 and grok3). It does so by setting
the necessary request input to return thinking, but not specifying
a budget or effort (thus defaulting to the internal automatic level).
2025-07-22 10:41:29 -05:00
Adam Holmberg 6ff06bb96f fix: handle reasoning parameters and response in responses bridge (#12433)
* fix: handle reasoning parameters and response in responses bridge

Updates the OpenAI completions/responses bridge to map
reasoning_effort to reasoning parameters, and the chunk parser
to return reasoning_content.

ref: 12432

* fix: using type checked objects in responses bridge transform

ref: 12432
2025-07-10 18:06:45 -07:00
Krish Dholakia e5fd313a48 Completion-To-Responses Bridge: Support passing image url's (#11833)
* fix(completion_to_responses_bridge_transformation.py): support passing image urls' to responses api models

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

* fix(base_aws_llm.py): if boto3 present, try and get the configured region name

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

* fix: fix imports

* fix: fix linting error s
2025-06-18 12:48:17 -07:00