This is an automated email from the ASF dual-hosted git repository. nic-6443 pushed a commit to branch feat/ai-proxy-anthropic-converter in repository https://gitbox.apache.org/repos/asf/apisix.git
commit c9ecc0f9a10498b2b6844c2be8441e0773548e11 Author: Nic <[email protected]> AuthorDate: Wed Apr 29 23:10:01 2026 +0800 fix: trim finish_reason before checking for 'null' Whitespace-padded 'null' (e.g. ' null ') would bypass the check and be treated as a valid finish_reason, prematurely stopping the stream. --- .../ai-protocols/converters/anthropic-messages-to-openai-chat.lua | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/apisix/plugins/ai-protocols/converters/anthropic-messages-to-openai-chat.lua b/apisix/plugins/ai-protocols/converters/anthropic-messages-to-openai-chat.lua index e93a79821..97b8e076d 100644 --- a/apisix/plugins/ai-protocols/converters/anthropic-messages-to-openai-chat.lua +++ b/apisix/plugins/ai-protocols/converters/anthropic-messages-to-openai-chat.lua @@ -707,10 +707,9 @@ local function openai_to_anthropic_sse(openai_chunk, state) local finish_reason if choice then local fr = choice.finish_reason - if type(fr) == "string" and fr ~= "" and fr ~= "null" then - -- Strip whitespace + if type(fr) == "string" then local trimmed = fr:match("^%s*(.-)%s*$") - if trimmed and trimmed ~= "" then + if trimmed and trimmed ~= "" and trimmed ~= "null" then finish_reason = trimmed end end
