From 9fa4562774f6daf0ebd06e4975b47a60fff3b33e Mon Sep 17 00:00:00 2001 From: Piotr Wilkin Date: Mon, 9 Mar 2026 12:42:02 +0100 Subject: [PATCH] Support refusal content for Responses API --- tools/server/server-common.cpp | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/tools/server/server-common.cpp b/tools/server/server-common.cpp index 13ea8c690f..4e54ffa660 100644 --- a/tools/server/server-common.cpp +++ b/tools/server/server-common.cpp @@ -1257,17 +1257,28 @@ json convert_responses_to_chatcmpl(const json & response_body) { for (const auto & output_text : item.at("content")) { const std::string type = json_value(output_text, "type", std::string()); - if (type != "output_text") { - throw std::invalid_argument("'type' must be 'output_text'"); + if (type != "output_text" && type != "refusal") { + throw std::invalid_argument("'type' must be 'output_text' or 'refusal'"); } - if (!exists_and_is_string(output_text, "text")) { - throw std::invalid_argument("'Output text' requires 'text'"); + if (type == "output_text") { + if (!exists_and_is_string(output_text, "text")) { + throw std::invalid_argument("'Output text' requires 'text'"); + // Ignore annotations and logprobs for now + chatcmpl_content.push_back({ + {"text", output_text.at("text")}, + {"type", "text"}, + }); + } + } else if (type == "refusal") { + if (!exists_and_is_string(output_text, "refusal")) { + throw std::invalid_argument("'Refusal' requires 'refusal'"); + // Ignore annotations and logprobs for now + chatcmpl_content.push_back({ + {"refusal", output_text.at("refusal")}, + {"type", "refusal"}, + }); + } } - // Ignore annotations and logprobs for now - chatcmpl_content.push_back({ - {"text", output_text.at("text")}, - {"type", "text"}, - }); } if (merge_prev) {