From bf133568c016d129d6b0d5bf9786726f0b2d2828 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Tue, 19 May 2026 07:59:46 +0000 Subject: [PATCH] fix(oci/cohere): mark logprobs/logit_bias unsupported and normalize unknown stream finish reasons Co-authored-by: Yassin Kortam --- litellm/llms/oci/chat/cohere.py | 6 ++++++ litellm/llms/oci/chat/transformation.py | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/litellm/llms/oci/chat/cohere.py b/litellm/llms/oci/chat/cohere.py index ce3560cd2bb..39caebba03a 100644 --- a/litellm/llms/oci/chat/cohere.py +++ b/litellm/llms/oci/chat/cohere.py @@ -294,6 +294,12 @@ def handle_cohere_stream_chunk(dict_chunk: dict) -> ModelResponseStream: finish_reason = "length" elif finish_reason == "TOOL_CALL": finish_reason = "tool_calls" + elif finish_reason is not None: + # OCI Cohere can emit error/cancel finish reasons (e.g. ``ERROR``, + # ``ERROR_TOXIC``, ``ERROR_LIMIT``, ``USER_CANCEL``) that aren't part + # of OpenAI's standard set. Normalize them to ``"stop"`` so downstream + # consumers switching on ``finish_reason`` keep working. + finish_reason = "stop" return ModelResponseStream( choices=[ diff --git a/litellm/llms/oci/chat/transformation.py b/litellm/llms/oci/chat/transformation.py index f8ecc479cae..1bf960e5efc 100644 --- a/litellm/llms/oci/chat/transformation.py +++ b/litellm/llms/oci/chat/transformation.py @@ -209,6 +209,12 @@ class OCIChatConfig(BaseConfig): # the param dropped under drop_params, rather than silently passing # through and tripping Pydantic validation on CohereChatRequest. self.openai_to_oci_cohere_param_map["reasoning_effort"] = False + # CohereChatRequest has no logProbs/logitBias fields, so passing these + # through would be silently dropped by Pydantic. Mark them unsupported + # so get_supported_openai_params doesn't advertise them and callers + # get a clear error (or drop_params behaviour) instead. + self.openai_to_oci_cohere_param_map["logprobs"] = False + self.openai_to_oci_cohere_param_map["logit_bias"] = False def get_supported_openai_params(self, model: str) -> List[str]: param_map = (