Skip to content
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
30bee8a
feat(hosted_vllm): opt in to forwarding assistant reasoning content
jibanez-staticduo Sep 14, 2026
8a82ea7
fix(hosted_vllm): isolate forwarded reasoning in response caches
jibanez-staticduo Sep 14, 2026
9e47c58
feat: configure historical assistant reasoning field
jibanez-staticduo Sep 15, 2026
101537c
fix: preserve Python 3.12 OpenAPI snapshot formatting
jibanez-staticduo Sep 15, 2026
c84c73b
fix: preserve reasoning field on partial model updates
jibanez-staticduo Sep 15, 2026
a1db7d6
fix: preserve reasoning forwarding on partial updates
jibanez-staticduo Sep 15, 2026
624f2f9
fix: support encrypted reasoning field storage
jibanez-staticduo Sep 15, 2026
115f4fd
fix: validate reasoning field before chat dispatch
jibanez-staticduo Sep 15, 2026
a1c4035
merge: sync upstream and preserve model management tests
jibanez-staticduo Sep 15, 2026
a590abf
test: annotate reasoning history test parameters
jibanez-staticduo Sep 16, 2026
4c79d96
merge: preserve reasoning normalization with prompt cache ordering
jibanez-staticduo Sep 16, 2026
2b9268c
merge: bring reasoning-history PR onto current upstream main
jibanez-staticduo Sep 22, 2026
d3a79d8
merge: sync reasoning-history PR onto upstream c19ce71bcd
jibanez-staticduo Sep 25, 2026
c52edca
Merge remote-tracking branch 'upstream/main' into litellm_forward_rea…
jibanez-staticduo Sep 25, 2026
7a6c2ac
test(types): register reasoning transport options in the owned inventory
jibanez-staticduo Sep 25, 2026
eac8c95
Merge remote-tracking branch 'upstream/main' into litellm_forward_rea…
jibanez-staticduo Sep 25, 2026
6716494
test(ci): drop the repeated UNIT_FLAG key in the shard paths test
jibanez-staticduo Sep 25, 2026
04ea8f4
merge: sync upstream with the relocated unit test tree
jibanez-staticduo Sep 26, 2026
b39fd06
merge: sync upstream through the client pool refactor
jibanez-staticduo Sep 30, 2026
1e7d04a
refactor(router): declare the reasoning transport options on the para…
jibanez-staticduo Sep 30, 2026
8897879
test(catalog): validate ultrafast pricing fields in the strict schema
jibanez-staticduo Sep 30, 2026
e5098f6
chore(reasoning): remove narrative comments flagged in review
jibanez-staticduo Sep 30, 2026
82ef0b9
test(interactions): follow operation schemas and declared path parame…
jibanez-staticduo Sep 30, 2026
c7837be
chore: merge upstream main into reasoning history support
jibanez-staticduo Sep 30, 2026
2a7abe8
test: remove duplicate catalog fields after upstream merge
jibanez-staticduo Sep 30, 2026
5b13a21
fix: synchronize trace routes and generated API types
jibanez-staticduo Sep 30, 2026
70fce7d
merge: synchronize upstream and repair batch request fixtures
jibanez-staticduo Sep 30, 2026
7b4df9a
test: harden batches mock scope and MCP cancellation deadline handshake
jibanez-staticduo Oct 1, 2026
1625735
Merge branch 'codex/pr41050-ci-test-timing' into litellm_forward_reas…
jibanez-staticduo Oct 1, 2026
b273b97
style: apply ruff format to MCP client test tree file
jibanez-staticduo Oct 1, 2026
0be9a3d
Merge upstream main f553c80cd3 into litellm_forward_reasoning_content
jibanez-staticduo Oct 1, 2026
0b630f4
fix: update vulnerable GitPython and Tornado dependencies
jibanez-staticduo Oct 1, 2026
9738840
fix(rust_bridge): name NativeTraceStorage.query stub parameter as the…
jibanez-staticduo Oct 1, 2026
b95c3dc
Revert "fix: update vulnerable GitPython and Tornado dependencies"
jibanez-staticduo Oct 1, 2026
57434ae
Merge upstream main 424bfd8758 into litellm_forward_reasoning_content
jibanez-staticduo Oct 1, 2026
8a6eee4
style: ruff format the merged OpenAPI compliance test file
jibanez-staticduo Oct 1, 2026
9c32039
test(traces): align native tests with named read queries
jibanez-staticduo Oct 1, 2026
9f6bfb2
chore: merge upstream main into reasoning history
jibanez-staticduo Oct 1, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions litellm/caching/caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,18 @@ def get_cache_key(self, **kwargs) -> str:
param_value = kwargs[param]
cache_key += f"{param}: {param_value}"

nested_litellm_params: Final = kwargs.get("litellm_params") or {}
forward_reasoning_content: Final = kwargs.get(
"forward_reasoning_content", nested_litellm_params.get("forward_reasoning_content")
)
if forward_reasoning_content is True:
cache_key += "forward_reasoning_content: True"
Comment thread
jibanez-staticduo marked this conversation as resolved.
Resolved
reasoning_content_field: Final = kwargs.get(
"reasoning_content_field", nested_litellm_params.get("reasoning_content_field")
)
if reasoning_content_field == "reasoning":
cache_key += "reasoning_content_field: reasoning"

if is_semantic_cache:
cache_key += self._get_semantic_cache_tenant_scope(kwargs)

Expand Down
6 changes: 4 additions & 2 deletions litellm/litellm_core_utils/get_litellm_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
# Keys `completion()` forwards from its own kwargs into `get_litellm_params`,
# which are otherwise invisible to it because that call site passes explicit
# named arguments rather than `**kwargs`.
FORWARDED_KWARGS_KEYS: Final = AWS_CREDENTIAL_KWARGS_KEYS
FORWARDED_KWARGS_KEYS: Final = AWS_CREDENTIAL_KWARGS_KEYS | frozenset(
{"forward_reasoning_content", "reasoning_content_field"}
)

# Pre-define optional kwargs keys as frozenset for O(1) lookups
# These are extracted from kwargs only if present, avoiding unnecessary .get() calls
Expand Down Expand Up @@ -59,7 +61,7 @@
"use_xai_oauth",
}
)
| AWS_CREDENTIAL_KWARGS_KEYS
| FORWARDED_KWARGS_KEYS
)

# Backward-compatible alias for existing imports/tests.
Expand Down
37 changes: 37 additions & 0 deletions litellm/litellm_core_utils/reasoning_content_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from collections.abc import Mapping, Sequence
from copy import deepcopy
from types import MappingProxyType
from typing import (
Final,
cast, # noqa: TID251 # Preserves arbitrary provider fields without lossy TypedDict validation.
)

from litellm.types.llms.openai import AllMessageValues


def normalize_reasoning_content(
messages: Sequence[AllMessageValues], *, forward: bool = True
) -> list[AllMessageValues]: # mutable-ok: provider request contract
def normalize_message(message: AllMessageValues) -> AllMessageValues:
if message["role"] != "assistant":
return message
history: Final[Mapping[str, object]] = message
reasoning: Final = (
history.get("reasoning") if history.get("reasoning") is not None else history.get("reasoning_content")
)
normalized: Final[Mapping[str, object]] = MappingProxyType(
{
**MappingProxyType(
{key: value for key, value in history.items() if key not in ("reasoning", "reasoning_content")}
),
**(
MappingProxyType({"reasoning": reasoning})
if forward and reasoning is not None
else MappingProxyType({})
),
}
)
result: Final = dict(normalized) # mutable-ok: provider request contract
return cast(AllMessageValues, result) # cast-ok: only optional reasoning keys change

return [normalize_message(message) for message in deepcopy(messages)] # mutable-ok: provider request contract
36 changes: 34 additions & 2 deletions litellm/llms/hosted_vllm/chat/transformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@

import json
from collections.abc import Coroutine
from copy import deepcopy
from typing import Any, Final, Literal, cast, overload

from litellm.litellm_core_utils.prompt_templates.common_utils import (
_get_image_mime_type_from_url,
)
from litellm.litellm_core_utils.prompt_templates.factory import _parse_mime_type
from litellm.litellm_core_utils.reasoning_content_utils import normalize_reasoning_content
from litellm.litellm_core_utils.reasoning_effort_utils import (
reasoning_effort_from_thinking_budget,
)
Expand Down Expand Up @@ -145,6 +147,37 @@ def _convert_file_to_video_url(self, content_item: ChatCompletionFileObject) ->
return ChatCompletionVideoObject(type="video_url", video_url=ChatCompletionVideoUrlObject(url=file_data))
raise ValueError("file_id or file_data is required")

def transform_request(
self,
model: str,
messages: list[AllMessageValues], # mutable-ok: provider request contract
optional_params: dict, # mutable-ok: provider request contract
litellm_params: dict, # mutable-ok: provider request contract
headers: dict, # mutable-ok: provider request contract
Comment thread
jibanez-staticduo marked this conversation as resolved.
Resolved
) -> dict: # mutable-ok: provider request contract
request_messages: Final = (
normalize_reasoning_content(messages, forward=litellm_params.get("forward_reasoning_content") is True)
if litellm_params.get("reasoning_content_field") == "reasoning"
else deepcopy(messages)
)
if litellm_params.get("forward_reasoning_content") is not True:
for message in request_messages:
if message["role"] == "assistant":
message.pop("reasoning_content", None)
Comment thread
jibanez-staticduo marked this conversation as resolved.
Resolved
return super().transform_request(model, request_messages, optional_params, litellm_params, headers)

async def async_transform_request(
self,
model: str,
messages: list[AllMessageValues], # mutable-ok: provider request contract
optional_params: dict, # mutable-ok: provider request contract
litellm_params: dict, # mutable-ok: provider request contract
headers: dict, # mutable-ok: provider request contract
) -> dict: # mutable-ok: provider request contract
return await super().async_transform_request(
model, deepcopy(messages), optional_params, litellm_params, headers
)

@overload
def _transform_messages(
self, messages: list[AllMessageValues], model: str, is_async: Literal[True]
Expand All @@ -164,13 +197,12 @@ def _transform_messages(
"""
Support translating:
- video files from file_id or file_data to video_url
- thinking_blocks and reasoning_content on assistant messages are removed,
- thinking_blocks on assistant messages are removed,
and content lists are converted to strings for vLLM compatibility
"""
for message in messages:
if message["role"] == "assistant":
message.pop("thinking_blocks", None)
message.pop("reasoning_content", None)
existing_content = message.get("content")
if isinstance(existing_content, list):
text_parts = []
Expand Down
17 changes: 15 additions & 2 deletions litellm/llms/openai/chat/gpt_transformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
async_convert_url_to_base64,
convert_url_to_base64,
)
from litellm.litellm_core_utils.reasoning_content_utils import normalize_reasoning_content
from litellm.llms.base_llm.base_model_iterator import BaseModelResponseIterator
from litellm.llms.base_llm.base_utils import BaseLLMModelInfo
from litellm.llms.base_llm.chat.transformation import BaseConfig, BaseLLMException
Expand Down Expand Up @@ -477,7 +478,13 @@ def transform_request(
Returns:
dict: The transformed request. Sent as the body of the API call.
"""
messages = self._transform_messages(messages=messages, model=model)
request_messages: Final = (
normalize_reasoning_content(messages)
if litellm_params.get("custom_llm_provider") == "openai"
and litellm_params.get("reasoning_content_field") == "reasoning"
else messages
)
messages = self._transform_messages(messages=request_messages, model=model)
if not self._should_preserve_cache_control_for_endpoint(
litellm_params.get("custom_llm_provider"), litellm_params.get("api_base")
):
Expand Down Expand Up @@ -506,7 +513,13 @@ async def async_transform_request(
litellm_params: dict,
headers: dict,
) -> dict:
transformed_messages = await self._transform_messages(messages=messages, model=model, is_async=True)
request_messages: Final = (
normalize_reasoning_content(messages)
if litellm_params.get("custom_llm_provider") == "openai"
and litellm_params.get("reasoning_content_field") == "reasoning"
else messages
)
transformed_messages = await self._transform_messages(messages=request_messages, model=model, is_async=True)
if not self._should_preserve_cache_control_for_endpoint(
litellm_params.get("custom_llm_provider"), litellm_params.get("api_base")
):
Expand Down
2 changes: 2 additions & 0 deletions litellm/types/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,8 @@ class GenericLiteLLMParams(CredentialLiteLLMParams, CustomPricingLiteLLMParams):
)
model_config = ConfigDict(extra="allow", arbitrary_types_allowed=True)
merge_reasoning_content_in_choices: bool | None = False
forward_reasoning_content: bool | None = False
reasoning_content_field: Literal["reasoning_content", "reasoning"] | None = None
model_info: dict | None = None
mock_response: str | ModelResponse | Exception | Any | None = None

Expand Down
2 changes: 2 additions & 0 deletions litellm/types/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3826,6 +3826,8 @@ def without_server_derived_pricing(model_info: Mapping[str, Any]) -> Mapping[str
"budget_duration",
"use_in_pass_through",
"merge_reasoning_content_in_choices",
"forward_reasoning_content",
Comment thread
jibanez-staticduo marked this conversation as resolved.
Resolved
"reasoning_content_field",
"litellm_credential_name",
"allowed_openai_params",
"litellm_session_id",
Expand Down
Loading
Loading