Skip to content

Commit 7692aab

Browse files
committed
fix: strip thinking tokens from non-streaming responses (v0.12.84)
Free models leak <think>...</think> blocks in non-streaming responses. stripThinkingTokens() was only called in the streaming path — now also applied to non-streaming JSON responses before notice injection.
1 parent 8ce39a6 commit 7692aab

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@blockrun/clawrouter",
3-
"version": "0.12.83",
3+
"version": "0.12.84",
44
"description": "Smart LLM router — save 85% on inference costs. 55+ models (11 free), one wallet, x402 micropayments.",
55
"type": "module",
66
"main": "dist/index.js",

src/proxy.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4415,6 +4415,24 @@ async function proxyRequest(
44154415

44164416
let responseBody = Buffer.concat(bodyParts);
44174417

4418+
// Strip thinking tokens from non-streaming responses (same as streaming path)
4419+
if (responseBody.length > 0) {
4420+
try {
4421+
const parsed = JSON.parse(responseBody.toString()) as {
4422+
choices?: Array<{ message?: { content?: string } }>;
4423+
};
4424+
if (parsed.choices?.[0]?.message?.content) {
4425+
const stripped = stripThinkingTokens(parsed.choices[0].message.content);
4426+
if (stripped !== parsed.choices[0].message.content) {
4427+
parsed.choices[0].message.content = stripped;
4428+
responseBody = Buffer.from(JSON.stringify(parsed));
4429+
}
4430+
}
4431+
} catch {
4432+
/* not JSON, skip */
4433+
}
4434+
}
4435+
44184436
// Prepend balance fallback notice to response content
44194437
if (balanceFallbackNotice && responseBody.length > 0) {
44204438
try {

0 commit comments

Comments
 (0)