Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

Merge remote-tracking branch 'origin/litellm_internal_staging' into litellm_together_reasoning_effort

mateo-berri5931ef452597
diff --cc litellm/llms/together_ai/chat/transformation.py
index ee6a813490e,3162a34f1b9..6d5c84a2da3
--- a/litellm/llms/together_ai/chat/transformation.py
+++ b/litellm/llms/together_ai/chat/transformation.py
@@@ -4,89 -4,67 +4,128 @@@ Translates from OpenAI's `/v1/chat/comp
Docs: https://docs.together.ai/docs/chat-overview
"""
- from collections.abc import Mapping
-from collections.abc import Container
++from collections.abc import Container, Mapping
from types import MappingProxyType
from typing import Final
+from typing_extensions import ReadOnly, TypedDict
+
+ import litellm
from litellm._logging import verbose_logger
+ from litellm.exceptions import UnsupportedParamsError
-from litellm.utils import supports_function_calling
+from litellm.utils import supports_function_calling, supports_reasoning
from ...openai.chat.gpt_transformation import OpenAIGPTConfig
- FUNCTION_CALLING_ONLY_PARAMS: Final = ("tools", "tool_choice", "function_call", "response_format")
+ TOOL_CALLING_PARAMS: Final = ("tools", "tool_choice", "function_call")
PLAIN_TEXT_RESPONSE_FORMAT: Final = MappingProxyType({"type": "text"})
+ FUNCTION_CALLING_DOCS_URL: Final = "https://docs.together.ai/docs/function-calling"
+ADJUSTABLE_EFFORT_REASONING_MODELS: Final = frozenset(
+ {
+ "openai/gpt-oss-120b",
+ "openai/gpt-oss-20b",
+ }
+)
+HYBRID_REASONING_MODELS: Final = frozenset(
+ {
+ "MiniMaxAI/MiniMax-M3",
+ "Qwen/Qwen3.5-9B",
+ "Qwen/Qwen3.6-Plus",
+ "deepseek-ai/DeepSeek-V4-Pro",
+ "moonshotai/Kimi-K3",
+ "nvidia/nemotron-3-ultra-550b-a55b",
+ "zai-org/GLM-5.2",
+ }
+)
+HIGH_MAX_EFFORT_MODEL_PREFIX: Final = "deepseek-ai/DeepSeek-V4-Pro"
+EFFORT_TRANSLATION: Final = MappingProxyType({"minimal": "low", "xhigh": "high", "max": "high"})
+HIGH_MAX_EFFORT_TRANSLATION: Final = MappingProxyType(
+ {"minimal": "high", "low": "high", "medium": "high", "high": "max", "xhigh": "max"}
+)
+
+
+class TogetherReasoningToggle(TypedDict):
+ enabled: ReadOnly[bool]
+
+ def _function_calling_verdict(model: str) -> bool | None:
+ try:
+ if supports_function_calling(model, custom_llm_provider="together_ai"):
+ return True
+ except Exception as e:
+ verbose_logger.debug("Error checking together_ai function calling support for %s: %s", model, e)
+ registry_entry: Final = litellm.model_cost.get(f"together_ai/{model}")
+ if isinstance(registry_entry, dict) and registry_entry.get("supports_function_calling") is False:
+ return False
+ return None
+
+
+ def _tool_params_to_drop(passed_params: Container[str], model: str, drop_params: bool) -> tuple[str, ...]:
+ passed_tool_params: Final = tuple(param for param in TOOL_CALLING_PARAMS if param in passed_params)
+ if not passed_tool_params:
+ return ()
+ verdict: Final = _function_calling_verdict(model)
+ if verdict is True:
+ return ()
+ if verdict is None:
+ verbose_logger.warning(
+ "together_ai model %s has no function calling entry in the model registry; passing %s through for Together to validate. Docs - %s",
+ model,
+ ", ".join(passed_tool_params),
+ FUNCTION_CALLING_DOCS_URL,
+ )
+ return ()
+ if drop_params or litellm.drop_params:
+ verbose_logger.warning(
+ "together_ai model %s does not support function calling per the model registry; dropping %s. Docs - %s",
+ model,
+ ", ".join(passed_tool_params),
+ FUNCTION_CALLING_DOCS_URL,
+ )
+ return passed_tool_params
+ raise UnsupportedParamsError(
+ status_code=500,
+ message=f"together_ai does not support parameters: {', '.join(passed_tool_params)}, for model={model}. To drop it from the call, set `litellm.drop_params = True`.",
+ )
+
+
+def _supports_together_reasoning(model: str) -> bool:
+ if model in ADJUSTABLE_EFFORT_REASONING_MODELS or model in HYBRID_REASONING_MODELS:
+ return True
+ if model.startswith(HIGH_MAX_EFFORT_MODEL_PREFIX):
+ return True
+ return supports_reasoning(model, custom_llm_provider="together_ai")
+
+
+def _adjustable_effort(effort: str, model: str) -> str:
+ if effort == "none":
+ verbose_logger.debug(
+ "together_ai model %s cannot disable reasoning; mapping reasoning_effort=none to low", model
+ )
+ return "low"
+ return EFFORT_TRANSLATION.get(effort, effort)
+
+
+def _reasoning_effort_payload(effort: str, model: str) -> Mapping[str, object]:
+ if effort == "default":
+ return MappingProxyType({})
+ if model in ADJUSTABLE_EFFORT_REASONING_MODELS:
+ return MappingProxyType({"reasoning_effort": _adjustable_effort(effort, model)})
+ if effort == "none":
+ disable_reasoning: Final[TogetherReasoningToggle] = {"enabled": False}
+ return MappingProxyType({"reasoning": disable_reasoning})
+ if model.startswith(HIGH_MAX_EFFORT_MODEL_PREFIX):
+ return MappingProxyType({"reasoning_effort": HIGH_MAX_EFFORT_TRANSLATION.get(effort, effort)})
+ return MappingProxyType({"reasoning_effort": EFFORT_TRANSLATION.get(effort, effort)})
+
+
class TogetherAIChatConfig(OpenAIGPTConfig):
def get_supported_openai_params(self, model: str) -> list:
- supports_fc: bool | None = None
- try:
- supports_fc = supports_function_calling(model, custom_llm_provider="together_ai")
- except Exception as e:
- verbose_logger.debug("Error getting supported openai params: %s", e)
-
+ supports_fc: Final = _function_calling_verdict(model)
supported_params: Final = super().get_supported_openai_params(model)
+ if _supports_together_reasoning(model):
+ supported_params.append("reasoning_effort")
if supports_fc is True:
return supported_params
verbose_logger.debug(
@@@ -104,13 -82,8 +143,14 @@@
drop_params: bool,
) -> dict:
mapped_openai_params: Final = super().map_openai_params(non_default_params, optional_params, model, drop_params)
-
+ for param in _tool_params_to_drop(mapped_openai_params, model, drop_params):
+ mapped_openai_params.pop(param)
if mapped_openai_params.get("response_format") == PLAIN_TEXT_RESPONSE_FORMAT:
mapped_openai_params.pop("response_format")
+ effort: Final = mapped_openai_params.get("reasoning_effort")
+ if not isinstance(effort, str):
+ return mapped_openai_params
+ mapped_openai_params.pop("reasoning_effort")
+ for key, value in _reasoning_effort_payload(effort, model).items():
+ mapped_openai_params.setdefault(key, value)
return mapped_openai_params
diff --cc tests/test_litellm/llms/together_ai/chat/test_together_ai_chat_transformation.py
index e99bbc46523,0b9fd5364f9..e1516dbfc0f
--- a/tests/test_litellm/llms/together_ai/chat/test_together_ai_chat_transformation.py
+++ b/tests/test_litellm/llms/together_ai/chat/test_together_ai_chat_transformation.py
@@@ -14,26 -16,14 +16,29 @@@ from litellm.types.utils import LlmProv
TOOL_CALLING_MODEL = "openai/gpt-oss-20b"
REASONING_MODEL = "deepseek-ai/DeepSeek-V3.1"
+PLAIN_MODEL = "Qwen/Qwen3-235B-A22B-fp8-tput"
- UNMAPPED_MODEL = "MiniMaxAI/MiniMax-M3"
+ UNMAPPED_MODEL = "example-org/brand-new-model"
+ NO_TOOLS_MODEL = "example-org/no-tools-model"
+ADJUSTABLE_REASONING_MODEL = "openai/gpt-oss-120b"
+HYBRID_REASONING_MODEL = "Qwen/Qwen3.5-9B"
+HIGH_MAX_REASONING_MODEL = "deepseek-ai/DeepSeek-V4-Pro"
+REGISTRY_FLAGGED_REASONING_MODEL = "zai-org/GLM-4.6"
+NON_REASONING_MODEL = "meta-llama/Llama-3.3-70B-Instruct-Turbo"
- FUNCTION_CALLING_PARAMS = ("tools", "tool_choice", "function_call", "response_format")
+ TOOL_PARAMS = ("tools", "tool_choice", "function_call")
+
+ WEATHER_TOOLS = [{"type": "function", "function": {"name": "get_weather", "parameters": {}}}]
+def _map_reasoning_effort(model: str, effort: str) -> dict:
+ return TogetherAIChatConfig().map_openai_params(
+ non_default_params={"reasoning_effort": effort},
+ optional_params={},
+ model=model,
+ drop_params=False,
+ )
+
+
@pytest.fixture(autouse=True)
def force_local_model_cost(monkeypatch):
monkeypatch.setenv("LITELLM_LOCAL_MODEL_COST_MAP", "True")