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(cliproxyapi): detect Anthropic shape on minimal Capy bodies (#2192)

Anton607ae5ca5e74
diff --git a/open-sse/executors/cliproxyapi.ts b/open-sse/executors/cliproxyapi.ts
index 601d100e03..df14e8ff80 100644
--- a/open-sse/executors/cliproxyapi.ts
+++ b/open-sse/executors/cliproxyapi.ts
@@ -178,6 +178,20 @@ export class CliproxyapiExecutor extends BaseExecutor {
// entry inside messages[], not at body level. Accept both string and
// array-of-content-blocks forms (Anthropic supports both per the docs).
if (b.system !== undefined) return true;
+ // Strong signal: top-level `thinking` field is Anthropic-only. OpenAI
+ // uses `reasoning` / `reasoning_effort`. Even adaptive/raw Capy shapes
+ // emit thinking, so this catches minimal Capy bodies (string content,
+ // no system block) that would otherwise miss the messages[0].content
+ // array check below.
+ if (b.thinking !== undefined) return true;
+ // Strong signal: top-level `metadata.user_id` is the CC wire-image
+ // identifier; OpenAI request bodies don't carry it.
+ if (
+ b.metadata &&
+ typeof b.metadata === "object" &&
+ (b.metadata as Record<string, unknown>).user_id !== undefined
+ )
+ return true;
// Strong signal: messages[0].content is an array of Anthropic content blocks
const msgs = b.messages;
if (Array.isArray(msgs) && msgs.length > 0) {
diff --git a/tests/unit/cliproxyapi-executor.test.ts b/tests/unit/cliproxyapi-executor.test.ts
index 0d65bf2431..a66c39f9c5 100644
--- a/tests/unit/cliproxyapi-executor.test.ts
+++ b/tests/unit/cliproxyapi-executor.test.ts
@@ -178,15 +178,22 @@ describe("CliproxyapiExecutor", () => {
assert.equal(result.thinking, undefined);
});
- it("does not touch thinking on OpenAI-shape bodies", () => {
+ it("does not strip OpenAI-shape bodies (no thinking, no system, string content)", () => {
const exec = new CliproxyapiExecutor();
const body = {
model: "gpt-5.5",
- messages: [{ role: "user", content: "hi" }],
- thinking: { type: "adaptive", display: "summarized" },
+ messages: [
+ { role: "system", content: "be brief" },
+ { role: "user", content: "hi" },
+ ],
+ reasoning_effort: "medium",
};
const result = exec.transformRequest("gpt-5.5", body, true, {});
- assert.deepEqual(result.thinking, { type: "adaptive", display: "summarized" });
+ // No Anthropic indicators present, so strips are skipped. Body
+ // passes through with its OpenAI fields preserved.
+ assert.equal(result.reasoning_effort, "medium");
+ assert.equal(result.thinking, undefined);
+ assert.equal(result.output_config, undefined);
});
});