From a275e6d5755fddb8be53321803f5c36cc26dc527 Mon Sep 17 00:00:00 2001 From: Ryan Loney Date: Thu, 20 Aug 2026 12:41:38 -0700 Subject: [PATCH 1/7] fix(cerebras): preserve current request parameters --- litellm/llms/cerebras/chat.py | 43 +++++++++++++++++++----- tests/llm_translation/test_cerebras.py | 46 ++++++++++++++++++++++++++ 2 files changed, 81 insertions(+), 8 deletions(-) create mode 100644 tests/llm_translation/test_cerebras.py diff --git a/litellm/llms/cerebras/chat.py b/litellm/llms/cerebras/chat.py index c3aa26ade35..691d16b365a 100644 --- a/litellm/llms/cerebras/chat.py +++ b/litellm/llms/cerebras/chat.py @@ -17,29 +17,49 @@ class CerebrasConfig(OpenAIGPTConfig): Below are the parameters: """ + max_completion_tokens: int | None = None max_tokens: int | None = None response_format: dict | None = None seed: int | None = None stream: bool | None = None - top_p: int | None = None - tool_choice: str | None = None + top_p: float | None = None + tool_choice: str | dict | None = None tools: list | None = None user: str | None = None reasoning_effort: str | None = None + parallel_tool_calls: bool | None = None + logprobs: bool | None = None + top_logprobs: int | None = None + frequency_penalty: float | None = None + presence_penalty: float | None = None + logit_bias: dict | None = None + service_tier: str | None = None + prompt_cache_key: str | None = None + prediction: dict | None = None def __init__( self, + max_completion_tokens: int | None = None, max_tokens: int | None = None, response_format: dict | None = None, seed: int | None = None, - stop: str | None = None, + stop: str | list[str] | None = None, stream: bool | None = None, temperature: float | None = None, - top_p: int | None = None, - tool_choice: str | None = None, + top_p: float | None = None, + tool_choice: str | dict | None = None, tools: list | None = None, user: str | None = None, reasoning_effort: str | None = None, + parallel_tool_calls: bool | None = None, + logprobs: bool | None = None, + top_logprobs: int | None = None, + frequency_penalty: float | None = None, + presence_penalty: float | None = None, + logit_bias: dict | None = None, + service_tier: str | None = None, + prompt_cache_key: str | None = None, + prediction: dict | None = None, ) -> None: locals_: Final = locals().copy() for key, value in locals_.items(): @@ -70,6 +90,15 @@ class CerebrasConfig(OpenAIGPTConfig): "user", "max_retries", "extra_headers", + "parallel_tool_calls", + "logprobs", + "top_logprobs", + "frequency_penalty", + "presence_penalty", + "logit_bias", + "service_tier", + "prompt_cache_key", + "prediction", ] # Only add reasoning_effort for models that support it @@ -87,8 +116,6 @@ class CerebrasConfig(OpenAIGPTConfig): ) -> dict: supported_openai_params: Final = self.get_supported_openai_params(model=model) for param, value in non_default_params.items(): - if param == "max_completion_tokens": - optional_params["max_tokens"] = value - elif param in supported_openai_params: + if param in supported_openai_params: optional_params[param] = value return optional_params diff --git a/tests/llm_translation/test_cerebras.py b/tests/llm_translation/test_cerebras.py new file mode 100644 index 00000000000..15a500fb1e6 --- /dev/null +++ b/tests/llm_translation/test_cerebras.py @@ -0,0 +1,46 @@ +import pytest + +from litellm.llms.cerebras.chat import CerebrasConfig + + +@pytest.mark.parametrize( + ("parameter", "value"), + [ + ("max_completion_tokens", 64), + ("max_tokens", 32), + ("parallel_tool_calls", False), + ("logprobs", True), + ("top_logprobs", 3), + ("frequency_penalty", 0.2), + ("presence_penalty", 0.3), + ("logit_bias", {"42": -1}), + ("service_tier", "default"), + ("prompt_cache_key", "conversation-1"), + ("prediction", {"type": "content", "content": "expected"}), + ], +) +def test_cerebras_preserves_supported_parameters(parameter, value): + config = CerebrasConfig() + + mapped = config.map_openai_params( + non_default_params={parameter: value}, + optional_params={}, + model="gpt-oss-120b", + drop_params=False, + ) + + assert mapped == {parameter: value} + + +def test_cerebras_does_not_alias_max_completion_tokens(): + config = CerebrasConfig() + + mapped = config.map_openai_params( + non_default_params={"max_completion_tokens": 64}, + optional_params={}, + model="gpt-oss-120b", + drop_params=False, + ) + + assert mapped["max_completion_tokens"] == 64 + assert "max_tokens" not in mapped From 10e69816a7ee377dca42b6ed2103dc51a1de9e4a Mon Sep 17 00:00:00 2001 From: Ryan Loney Date: Thu, 20 Aug 2026 12:51:18 -0700 Subject: [PATCH 2/7] fix(cerebras): satisfy strict Ruff rules --- litellm/llms/cerebras/chat.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/litellm/llms/cerebras/chat.py b/litellm/llms/cerebras/chat.py index 691d16b365a..062955211aa 100644 --- a/litellm/llms/cerebras/chat.py +++ b/litellm/llms/cerebras/chat.py @@ -115,7 +115,11 @@ class CerebrasConfig(OpenAIGPTConfig): drop_params: bool, ) -> dict: supported_openai_params: Final = self.get_supported_openai_params(model=model) - for param, value in non_default_params.items(): - if param in supported_openai_params: - optional_params[param] = value + optional_params.update( + { + param: value + for param, value in non_default_params.items() + if param in supported_openai_params + } + ) return optional_params From c74f8bddf33bf5a8ee7599b4d276994203d5eab4 Mon Sep 17 00:00:00 2001 From: Ryan Loney Date: Thu, 20 Aug 2026 13:50:07 -0700 Subject: [PATCH 3/7] fix(cerebras): strengthen request parameter types --- litellm/llms/cerebras/chat.py | 12 ++++++++---- tests/llm_translation/test_cerebras.py | 4 ++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/litellm/llms/cerebras/chat.py b/litellm/llms/cerebras/chat.py index 062955211aa..d3dd426173a 100644 --- a/litellm/llms/cerebras/chat.py +++ b/litellm/llms/cerebras/chat.py @@ -6,6 +6,10 @@ this is OpenAI compatible - no translation needed / occurs from typing import Final +from openai.types.chat.chat_completion_prediction_content_param import ( + ChatCompletionPredictionContentParam, +) + from litellm.llms.openai.chat.gpt_transformation import OpenAIGPTConfig from litellm.utils import supports_reasoning @@ -32,10 +36,10 @@ class CerebrasConfig(OpenAIGPTConfig): top_logprobs: int | None = None frequency_penalty: float | None = None presence_penalty: float | None = None - logit_bias: dict | None = None + logit_bias: dict[str, float] | None = None service_tier: str | None = None prompt_cache_key: str | None = None - prediction: dict | None = None + prediction: ChatCompletionPredictionContentParam | None = None def __init__( self, @@ -56,10 +60,10 @@ class CerebrasConfig(OpenAIGPTConfig): top_logprobs: int | None = None, frequency_penalty: float | None = None, presence_penalty: float | None = None, - logit_bias: dict | None = None, + logit_bias: dict[str, float] | None = None, service_tier: str | None = None, prompt_cache_key: str | None = None, - prediction: dict | None = None, + prediction: ChatCompletionPredictionContentParam | None = None, ) -> None: locals_: Final = locals().copy() for key, value in locals_.items(): diff --git a/tests/llm_translation/test_cerebras.py b/tests/llm_translation/test_cerebras.py index 15a500fb1e6..82f23dff25a 100644 --- a/tests/llm_translation/test_cerebras.py +++ b/tests/llm_translation/test_cerebras.py @@ -19,7 +19,7 @@ from litellm.llms.cerebras.chat import CerebrasConfig ("prediction", {"type": "content", "content": "expected"}), ], ) -def test_cerebras_preserves_supported_parameters(parameter, value): +def test_cerebras_preserves_supported_parameters(parameter: str, value: object) -> None: config = CerebrasConfig() mapped = config.map_openai_params( @@ -32,7 +32,7 @@ def test_cerebras_preserves_supported_parameters(parameter, value): assert mapped == {parameter: value} -def test_cerebras_does_not_alias_max_completion_tokens(): +def test_cerebras_does_not_alias_max_completion_tokens() -> None: config = CerebrasConfig() mapped = config.map_openai_params( From 389e86a14c4d9d3c063bbeffa7db980bd069ae77 Mon Sep 17 00:00:00 2001 From: Ryan Loney Date: Thu, 20 Aug 2026 14:02:55 -0700 Subject: [PATCH 4/7] style(cerebras): match repository formatter --- litellm/llms/cerebras/chat.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/litellm/llms/cerebras/chat.py b/litellm/llms/cerebras/chat.py index d3dd426173a..887cba047d6 100644 --- a/litellm/llms/cerebras/chat.py +++ b/litellm/llms/cerebras/chat.py @@ -120,10 +120,6 @@ class CerebrasConfig(OpenAIGPTConfig): ) -> dict: supported_openai_params: Final = self.get_supported_openai_params(model=model) optional_params.update( - { - param: value - for param, value in non_default_params.items() - if param in supported_openai_params - } + {param: value for param, value in non_default_params.items() if param in supported_openai_params} ) return optional_params From 722788e13a4f2db53487b82cc2ff461cb4ef82e8 Mon Sep 17 00:00:00 2001 From: Ryan Loney Date: Thu, 20 Aug 2026 17:50:57 -0700 Subject: [PATCH 5/7] fix(cerebras): satisfy type discipline gate --- litellm/llms/cerebras/chat.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/litellm/llms/cerebras/chat.py b/litellm/llms/cerebras/chat.py index 887cba047d6..6327eb2958f 100644 --- a/litellm/llms/cerebras/chat.py +++ b/litellm/llms/cerebras/chat.py @@ -119,7 +119,7 @@ class CerebrasConfig(OpenAIGPTConfig): drop_params: bool, ) -> dict: supported_openai_params: Final = self.get_supported_openai_params(model=model) - optional_params.update( - {param: value for param, value in non_default_params.items() if param in supported_openai_params} - ) + for param in supported_openai_params: + if param in non_default_params: + optional_params[param] = non_default_params[param] return optional_params From 8df315ba841a9f68c24d761a6cdadae783e92932 Mon Sep 17 00:00:00 2001 From: Ryan Loney Date: Mon, 24 Aug 2026 13:46:35 -0700 Subject: [PATCH 6/7] fix(cerebras): satisfy pyright override checks --- litellm/llms/cerebras/chat.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/litellm/llms/cerebras/chat.py b/litellm/llms/cerebras/chat.py index 6327eb2958f..c39469316fe 100644 --- a/litellm/llms/cerebras/chat.py +++ b/litellm/llms/cerebras/chat.py @@ -26,7 +26,7 @@ class CerebrasConfig(OpenAIGPTConfig): response_format: dict | None = None seed: int | None = None stream: bool | None = None - top_p: float | None = None + top_p: float | None = None # pyright: ignore[reportIncompatibleVariableOverride] # Fractions supported. tool_choice: str | dict | None = None tools: list | None = None user: str | None = None @@ -34,8 +34,8 @@ class CerebrasConfig(OpenAIGPTConfig): parallel_tool_calls: bool | None = None logprobs: bool | None = None top_logprobs: int | None = None - frequency_penalty: float | None = None - presence_penalty: float | None = None + frequency_penalty: float | None = None # pyright: ignore[reportIncompatibleVariableOverride] # Fractions supported. + presence_penalty: float | None = None # pyright: ignore[reportIncompatibleVariableOverride] # Fractions supported. logit_bias: dict[str, float] | None = None service_tier: str | None = None prompt_cache_key: str | None = None From c8b48989631c47b7b7d4d8840e2cb80bc8abaa50 Mon Sep 17 00:00:00 2001 From: Ryan Loney Date: Tue, 25 Aug 2026 16:55:29 -0700 Subject: [PATCH 7/7] fix(cerebras): satisfy type discipline gate --- litellm/llms/cerebras/chat.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/litellm/llms/cerebras/chat.py b/litellm/llms/cerebras/chat.py index c39469316fe..0d0ab030132 100644 --- a/litellm/llms/cerebras/chat.py +++ b/litellm/llms/cerebras/chat.py @@ -27,7 +27,7 @@ class CerebrasConfig(OpenAIGPTConfig): seed: int | None = None stream: bool | None = None top_p: float | None = None # pyright: ignore[reportIncompatibleVariableOverride] # Fractions supported. - tool_choice: str | dict | None = None + tool_choice: str | dict | None = None # mutable-ok: API payload. tools: list | None = None user: str | None = None reasoning_effort: str | None = None @@ -36,7 +36,7 @@ class CerebrasConfig(OpenAIGPTConfig): top_logprobs: int | None = None frequency_penalty: float | None = None # pyright: ignore[reportIncompatibleVariableOverride] # Fractions supported. presence_penalty: float | None = None # pyright: ignore[reportIncompatibleVariableOverride] # Fractions supported. - logit_bias: dict[str, float] | None = None + logit_bias: dict[str, float] | None = None # mutable-ok: API payload. service_tier: str | None = None prompt_cache_key: str | None = None prediction: ChatCompletionPredictionContentParam | None = None @@ -47,11 +47,11 @@ class CerebrasConfig(OpenAIGPTConfig): max_tokens: int | None = None, response_format: dict | None = None, seed: int | None = None, - stop: str | list[str] | None = None, + stop: str | list[str] | None = None, # mutable-ok: API payload. stream: bool | None = None, temperature: float | None = None, top_p: float | None = None, - tool_choice: str | dict | None = None, + tool_choice: str | dict | None = None, # mutable-ok: API payload. tools: list | None = None, user: str | None = None, reasoning_effort: str | None = None, @@ -60,7 +60,7 @@ class CerebrasConfig(OpenAIGPTConfig): top_logprobs: int | None = None, frequency_penalty: float | None = None, presence_penalty: float | None = None, - logit_bias: dict[str, float] | None = None, + logit_bias: dict[str, float] | None = None, # mutable-ok: API payload. service_tier: str | None = None, prompt_cache_key: str | None = None, prediction: ChatCompletionPredictionContentParam | None = None,