Commit graph

299 commits

Author SHA1 Message Date
Mateo Wang
a1b1f1ef9d
Merge pull request #34455 from BerriAI/litellm_lit4767_empty_choices_streaming_guard
fix(responses): guard empty-choices chunks in the Responses API streaming bridge
2026-09-16 12:28:46 -07:00
kerry
ff878e7df0 refactor(responses): copy the terminal event instead of mutating stubbed chunks
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-09-16 03:54:04 +00:00
kerry
7cc07d437a fix(responses): build the billed terminal response immutably and guard the cache dump
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-09-16 03:47:03 +00:00
kerry
7121e64db4 fix(responses): type the dict terminal response so the estimated usage is billed
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-09-16 03:13:53 +00:00
kerry
7680d3de86 fix(responses): tolerate dict terminal responses when estimating usage
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-09-16 02:05:44 +00:00
kerry
7ed20406d7 test(responses): narrow the ValueError assertion to satisfy PT011
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-09-16 01:47:45 +00:00
kerry
a6d2332f7a test(responses): drive the usage-estimate failure path without patching litellm
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-09-16 01:24:35 +00:00
kerry
5a9fe56aff fix(responses): count custom-tool and MCP argument deltas in the streamed usage fallback
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-09-16 01:24:05 +00:00
kerry
1484fd7600 fix(responses): keep the usage estimate best-effort when token counting raises
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-09-16 01:13:26 +00:00
kerry
de9aa48cd6 fix(responses): count multimodal input and tool-call output in the streamed usage fallback
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-09-16 01:02:29 +00:00
kerry
f5c1c82f81 fix(responses): estimate usage from text when streamed completed event omits usage
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-09-16 00:32:24 +00:00
mateo-berri
69e9edb91a test(responses): fold the empty-choices regression tests into the mapped streaming iterator test file
Some checks failed
ai-gateway image / ai-gateway release image (push) Has been cancelled
LiteLLM Rust / rust-lint (push) Has been cancelled
LiteLLM Rust / rust-test (push) Has been cancelled
Terraform Modules / fmt, validate, test (aws) (push) Has been cancelled
Terraform Modules / fmt, validate, test (gcp) (push) Has been cancelled
Terraform Provider / gofmt, vet, build, test (push) Has been cancelled
Terraform Provider / Provider endpoints vs proxy OpenAPI schema (push) Has been cancelled
2026-09-15 15:31:38 -07:00
mateo-berri
a6b0d4266f Merge origin/main into litellm_lit4767_empty_choices_streaming_guard
Takes main's Anthropic Messages adapter iterator, transformation, and
combined-chunk tests as-is: #35314 already skips choiceless chunks at the
top of both adapter loops, so the adapter-side guards this branch carried
are superseded. The Responses bridge guards stay
2026-09-15 15:20:16 -07:00
yassin
cbd72ff6d8 Merge remote-tracking branch 'origin/main' into litellm_responses_bridge_filters_unknown_params 2026-09-15 18:15:19 +00:00
Mateo Wang
1ce66e98a2
Merge pull request #40989 from BerriAI/litellm_responses_bridge_hoist_additional_tools
fix(responses): hoist Codex additional_tools input items into the chat bridge tools
2026-09-14 23:33:38 -07:00
mateo-berri
e3152c011d fix(responses): classify streamed tool calls on the chat name and strip guardrail edits around the grammar block
The streaming bridge restored the namespace before deciding whether a tool call was a custom tool, so a namespaced function sharing a short name with a nested custom tool streamed back as a custom_tool_call. Classify on the raw chat tool name first, the way the non-streaming path already does.

The guardrail merge only stripped the namespace prefix and grammar suffix from the ends of the edited description, so a guardrail appending text after the grammar block left the block in the member description and the chat conversion appended it a second time. Strip the first occurrence of each instead.
2026-09-14 22:58:25 -07:00
Mateo Wang
d2859e18d7
Merge pull request #40988 from BerriAI/litellm_responses_stream_error_exception_mapping
fix(responses): route mid-stream error events through exception_type so content_policy_fallbacks fire
2026-09-14 18:36:20 -07:00
yassin
cc872c760a test(responses): route the bridge regression through real providers instead of patching ProviderConfigManager
Drops the helper docstring and the test docstrings. The passthrough case now
uses together_ai, which has no native Responses config on main, so the test no
longer monkeypatches ProviderConfigManager at the class level

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-09-14 23:27:05 +00:00
yassin
04c003c098 fix(responses): filter bridged kwargs like the native Responses path
A Responses request for a provider with a native Responses config that is served
through the chat-completions bridge (use_chat_completions_api or the
openai/chat_completions/ prefix) forwarded every raw kwarg, so a deployment-level
chat_template_kwargs reached OpenAI chat completions and got a 400. The bridge
now keeps only the keys a native dispatch would forward plus allowed_openai_params.
Providers with no native Responses config keep the passthrough

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-09-14 22:56:58 +00:00
mateo-berri
fff7a2cecf fix(responses): keep context-window events out of mid-stream fallback and fix stale exception assertions 2026-09-13 03:18:59 -07:00
mateo-berri
c246372859 fix(responses): import BaseLLMException lazily and collect stream chunks via anext
Move the BaseLLMException import into _map_error_event_exception so the
module no longer imports it at load time, clearing the module-level cyclic
import CodeQL flagged. The class is used only on the cold error path.

Replace the mutable list-append test collector with aiter/anext so the
regression tests read the stream immutably.
2026-09-13 02:35:53 -07:00
mateo-berri
e732a484f6 fix(responses): hoist Codex additional_tools input items into the chat bridge tools 2026-09-13 02:11:59 -07:00
mateo-berri
073d4fe2b0 fix(responses): route mid-stream error events through exception_type so content_policy_fallbacks fire
Mid-stream error events on the streaming Responses API were all raised as
APIError, so a content_policy_violation event never matched the router's
content-policy fallback dispatch and the client got the raw error instead
of the fallback model's answer. Map each error event's code and status
through the existing exception_type mapping, matching the non-streaming
path, and unwrap the typed ContentPolicyViolationError and
ContextWindowExceededError so the router routes them to the configured
content_policy_fallbacks and context_window_fallbacks.
2026-09-13 02:11:06 -07:00
shivam
a28e595a9d Merge remote-tracking branch 'origin/main' into litellm_fix_realtime_cached_audio_cost 2026-09-13 04:24:18 +00:00
ryan-crabbe-berri
0c83e831db fix(responses): carry the reasoning summary as an alias, not inside reasoning_effort
The bridge probe asked `responses_api_bridge_check` with the summary read straight off
the Responses object, but `litellm.completion` reads it from `optional_params` via
`peek_reasoning_summary_aliases`, which the bridged request never populated. So gpt-5,
gpt-5.1 and azure/gpt-5 answered "bridging" to the probe and "not bridging" for real,
and the object still landed on Chat Completions, which only takes a string

`reasoning_effort` is now always the effort string, and `summary` rides the
`reasoning_summary` alias that main.py already reassembles into `{effort, summary}` on
the bridged path. The alias is emitted only when the probe says the model bridges, so
no chat provider ever sees it, and the probe is now asked with the exact params this
transform emits
2026-09-12 17:49:30 -07:00
Joshua Garnett
1d5ed79931 fix(responses): translate the reasoning object into a chat-completion reasoning effort
The Responses API takes reasoning as an object, {effort, summary}. Chat
Completions takes reasoning_effort as a string enum and has no equivalent of
summary, but the completion bridge forwarded the whole object whenever summary
was set, which agentic clients set on every request.

Bedrock Converse guards its mapping with isinstance(value, str) and has no else
branch, so the object fell through, thinking was never enabled, and the caller
was billed for a non-thinking turn with nothing in the response to explain it.

The object is still forwarded for the one caller that can consume it: a model
whose cost-map mode is responses, which litellm.completion bridges back onto the
Responses API and reassembles {effort, summary} there. That decision is delegated
to responses_api_bridge_check, the same check litellm.completion runs, rather
than a second copy of the rule that could drift from it. An object carrying no
effort now yields no reasoning_effort at all.
2026-09-12 17:42:05 -07:00
mateo-berri
9fd1ef01fe Merge remote-tracking branch 'origin/litellm_internal_staging' into litellm_fix_realtime_cached_audio_cost
# Conflicts:
#	litellm/responses/litellm_completion_transformation/transformation.py
2026-09-12 12:46:37 -07:00
devin-ai-integration[bot]
eddfb5fb20
fix(responses): preserve hosted web search calls (#40828)
* fix(responses): preserve hosted web search calls

Co-Authored-By: Claude Code <noreply@anthropic.com>
(cherry picked from commit 09183b3346)

* chore: remove unrelated generated schema documentation changes

(cherry picked from commit ca6a860757)

* fix(responses): preserve hosted search context during replay

(cherry picked from commit 425f1e9b3a)

* chore: regenerate dashboard API types

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

---------

Co-authored-by: Tin Chi Lo <tin@berri.ai>
Co-authored-by: Claude Code <noreply@anthropic.com>
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-09-12 09:52:19 -07:00
shivam
67fc9e4e3d fix(responses): only emit cache_write_tokens when reported
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-09-10 22:10:06 +00:00
shivam
302a8d43da fix(cost): bill cached realtime audio tokens at the audio cache-read rate
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-09-10 22:02:58 +00:00
moe-berri
d266b76a8b fix(router): honor Codex reminders and map classifier failures 2026-09-10 13:48:21 -07:00
Mateo Wang
db7ca65b69
Merge pull request #40462 from BerriAI/litellm_fix_responses_stream_named_tool_choice
fix(responses): echo a named tool_choice in the Responses API shape on the chat-completions bridge
2026-09-09 18:48:32 -07:00
Mateo Wang
aefa1040a0
Merge pull request #40249 from BerriAI/litellm_fix_responses_bridge_reasoning_effort
fix: keep reasoning_effort for mode: responses bridge deployments
2026-09-09 18:46:58 -07:00
mateo-berri
4adf99557f fix(responses): echo "auto" for a tool_choice the bridge cannot express instead of failing after the provider call 2026-09-09 18:27:12 -07:00
mateo-berri
a68fe4e4d9 fix(responses): keep the client's usage shape when the logging copy cannot re-validate the response 2026-09-09 16:31:48 -07:00
mateo-berri
7563d94e65 test(responses): assert the streamed response.completed event echoes the named tool_choice 2026-09-09 16:29:55 -07:00
mateo-berri
96e46ba8ff fix(responses): stamp streamed usage cost when the provider usage arrives as a dict
Perplexity's Responses payload fails ResponsesAPIResponse validation on
truncation "" and is kept as an unvalidated model, so its usage stays a
plain dict and _stamp_responses_usage_cost raised AttributeError on every
streamed completion once reasoning made the cost non-zero. Validate the
dict into ResponseAPIUsage before stamping, keeping a provider-reported
cost when it carries one.

Resolves LIT-7391
2026-09-09 16:06:55 -07:00
mateo-berri
f5a410585a fix(responses): keep a custom tool_choice type in the bridged echo and type the new tests 2026-09-09 15:44:29 -07:00
mateo-berri
cce1d2087b fix(responses): echo a named tool_choice in the Responses API shape on the chat-completions bridge
A streamed /v1/responses request with tool_choice {"type": "function", "name": ...}
that reaches a chat-completions-only deployment failed with HTTP 500 before the
first byte: the synthetic response.created and response.in_progress events copied
the chat-shaped tool_choice into ResponsesAPIResponse, whose ToolChoice type expects
the flat Responses API shape. The non-streamed path echoed "auto" regardless of the
request.

Both paths now normalize the request's tool_choice through the existing chat
transform and map it back to the Responses API vocabulary, validated by a
TypeAdapter(ToolChoice), so a named function is echoed as {"type": "function",
"name": ...} and a missing tool_choice is echoed as "auto".

Fixes #33689
2026-09-09 14:22:22 -07:00
mateo-berri
2400f1befe Merge remote-tracking branch 'origin/litellm_internal_staging' into litellm_lit_4116_drop_params_string_coerce
# Conflicts:
#	tests/test_litellm/test_utils.py
2026-09-08 15:08:38 -07:00
mateo-berri
2f397fa128 fix(drop_params): honor string flags in litellm_settings and responses, and fail open on non-flag values 2026-09-07 18:06:29 -07:00
mateo-berri
5e4dec4b88 merge: bring litellm_internal_staging into litellm_fix_agent_mcp_grants
Take staging's test_bedrock_knowledgebase_hook.py, which drops the duplicate
embedding_executor parameter that turned the lint check red, and make the two
cross-module helpers this branch added public (raise_denied_scoped_mcp_access
and routes_through_gateway) so the private-usage budget stays at its base count
2026-09-07 16:35:40 -07:00
mateo-berri
18aa52d5e1 chore: merge litellm_internal_staging into litellm_lit_6348_fireworks_responses_api 2026-09-07 15:43:08 -07:00
Mateo Wang
3dac0ba79b
Merge pull request #39850 from BerriAI/litellm_fix_realtime_reasoning_double_bill
fix(cost): bill realtime reasoning tokens nested in text_tokens once
2026-09-07 10:55:20 -07:00
yujonglee
217cb12623
refactor(rust): remove per-request enablement arguments (#39928)
* refactor(rust): remove per-request enablement arguments

* fix(rust): remove ignored transcription enablement

* refactor(rust): remove OCR-specific bridge controls
2026-09-07 10:43:45 -07:00
devin-ai-integration[bot]
f66b3ebe0d
feat(responses): honor supported_endpoints /v1/responses opt-in for OpenAI-compatible deployments (#39725)
* feat(responses): honor supported_endpoints /v1/responses opt-in for OpenAI-compatible deployments

custom_openai and other generic OpenAI-compatible deployments have no native
Responses API config, so every /v1/responses call is bridged through
/v1/chat/completions. When model_info.supported_endpoints lists /v1/responses,
resolve OpenAILikeResponsesConfig instead so the request is forwarded to
{api_base}/responses, for streaming, non-streaming and mode: responses
deployments alike. Providers with their own Responses config are unchanged.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix(responses): drop deployment supported_endpoints opt-in after cross-provider prompt swap

A prompt manager that moves the request to another provider leaves kwargs['model_info']
describing the original deployment; without this the swapped provider was sent an
OpenAI-like /responses request it does not serve.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* refactor(responses): carry prompt-swap deployment metadata as a return value instead of a kwargs marker

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

---------

Co-authored-by: yassin <yassin@berri.ai>
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-09-05 11:40:00 -07:00
mateo-berri
e1d900d1c2 fix(realtime): store text_tokens without the nested reasoning share
The realtime usage writer passed the provider's output_token_details through as sent, so spend logs and callbacks kept a text_tokens that still contained reasoning_tokens while every other completion_tokens_details producer stores the partitioned share. The writer now applies the same rule the cost calculator uses, moved to litellm/types/utils.py so both read one definition, and the calculator keeps it for usage objects that arrive nested from elsewhere
2026-09-04 22:47:09 -07:00
mateo-berri
1fef5d1240 Merge remote-tracking branch 'origin/litellm_internal_staging' into litellm_lit_6348_fireworks_responses_api
# Conflicts:
#	basedpyright-code-budget.json
#	type-discipline-budget.json
2026-09-04 17:46:06 -07:00
mateo-berri
4b950cd94f feat(fireworks_ai): add native Responses API config 2026-09-04 17:01:14 -07:00
mateo-berri
4b24e3b727 Merge remote-tracking branch 'origin/litellm_internal_staging' into litellm_mcp_stateless_follow_up_zdr 2026-09-04 16:56:47 -07:00