Skip to content

Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors

fix: use replaceAll for think tags to handle multiple occurrences

AveryanAlexfdaeccf1e52e
diff --git a/open-sse/transformer/responsesTransformer.ts b/open-sse/transformer/responsesTransformer.ts
index 602adcdd1c..6a6f8540ca 100644
--- a/open-sse/transformer/responsesTransformer.ts
+++ b/open-sse/transformer/responsesTransformer.ts
@@ -377,7 +377,7 @@ export function createResponsesApiTransformStream(logger = null) {
if (content.includes("<think>")) {
state.inThinking = true;
- content = content.replace("<think>", "");
+ content = content.replaceAll("<think>", "");
startReasoning(controller, idx);
}
diff --git a/open-sse/translator/response/openai-responses.ts b/open-sse/translator/response/openai-responses.ts
index 745b643de8..40ec923bd4 100644
--- a/open-sse/translator/response/openai-responses.ts
+++ b/open-sse/translator/response/openai-responses.ts
@@ -75,7 +75,7 @@ export function openaiToOpenAIResponsesResponse(chunk, state) {
if (content.includes("<think>")) {
state.inThinking = true;
- content = content.replace("<think>", "");
+ content = content.replaceAll("<think>", "");
startReasoning(state, emit, idx);
}
diff --git a/tests/unit/responses-translation-fixes.test.mjs b/tests/unit/responses-translation-fixes.test.mjs
index 8ecf34f4bd..6d66f7ed73 100644
--- a/tests/unit/responses-translation-fixes.test.mjs
+++ b/tests/unit/responses-translation-fixes.test.mjs
@@ -403,3 +403,20 @@ test("Responses→Chat streaming: reasoning delta emits reasoning_content in Cha
assert.ok(result, "should return a chunk");
assert.equal(result.choices[0].delta.reasoning_content, "thinking step...");
});
+
+test("Chat→Responses streaming: multiple <think> tags in one chunk handled", () => {
+ const state = initState(FORMATS.OPENAI_RESPONSES);
+
+ // Chunk with multiple think tags
+ const chunk = {
+ choices: [{ index: 0, delta: { content: "<think>first</think>middle<think>second</think>end" }, finish_reason: null }],
+ id: "c1",
+ };
+ const events = openaiToOpenAIResponsesResponse(chunk, state);
+ // Should not have literal <think> in any text delta
+ const textDeltas = events
+ .filter((e) => e.event === "response.output_text.delta")
+ .map((e) => e.data.delta);
+ const combined = textDeltas.join("");
+ assert.ok(!combined.includes("<think>"), `text should not contain <think> tag, got: ${combined}`);
+});