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): conditional thinking strip to preserve valid Anthropic shape

OmniRoute Opsf946f6e0a73d
diff --git a/open-sse/executors/cliproxyapi.ts b/open-sse/executors/cliproxyapi.ts
index 36106b15ab..601d100e03 100644
--- a/open-sse/executors/cliproxyapi.ts
+++ b/open-sse/executors/cliproxyapi.ts
@@ -231,7 +231,6 @@ export class CliproxyapiExecutor extends BaseExecutor {
// Mirrors the runtime "Patch I2/I4" effect previously applied via patch.mjs.
// Strips are no-op when fields are absent (OpenAI-shape passthrough).
if (this.isAnthropicShape(transformed)) {
- delete transformed.thinking;
delete transformed.output_config;
delete transformed.context_management;
delete transformed.client_info;
@@ -239,6 +238,23 @@ export class CliproxyapiExecutor extends BaseExecutor {
delete transformed.safety_identifier;
delete transformed.metadata;
+ // Conditional thinking strip: preserve Anthropic-valid shapes
+ // ({type:"enabled"|"disabled", budget_tokens:N}) that applyThinkingBudget
+ // already normalized. Strip non-Anthropic shapes (e.g. Capy's
+ // {type:"adaptive", display:"summarized"}) which trigger Anthropic 400
+ // "Extra usage required" / "out of extra usage". The `display` field is
+ // a Capy-specific hint Anthropic doesn't accept.
+ const thinking = transformed.thinking;
+ if (thinking && typeof thinking === "object") {
+ const t = thinking as Record<string, unknown>;
+ const validType = t.type === "enabled" || t.type === "disabled";
+ const hasValidBudget = typeof t.budget_tokens === "number" && t.budget_tokens >= 0;
+ const hasInvalidExtras = "display" in t;
+ if (!validType || !hasValidBudget || hasInvalidExtras) {
+ delete transformed.thinking;
+ }
+ }
+
// Rewrite tool names matching Anthropic's reserved ^mcp_[^_] namespace.
// Anthropic returns "out of extra usage" / "Extra usage required" 400
// when a client-declared tool name collides with their server-side MCP
diff --git a/tests/unit/cliproxyapi-executor.test.ts b/tests/unit/cliproxyapi-executor.test.ts
index cc37ccb8a3..640372eb2d 100644
--- a/tests/unit/cliproxyapi-executor.test.ts
+++ b/tests/unit/cliproxyapi-executor.test.ts
@@ -129,6 +129,65 @@ describe("CliproxyapiExecutor", () => {
const result = exec.transformRequest("model", null, true, {});
assert.equal(result, null);
});
+
+ it("preserves Anthropic-valid thinking shape on /v1/messages routing", () => {
+ const exec = new CliproxyapiExecutor();
+ const body = {
+ model: "claude-opus-4-7",
+ system: [{ type: "text", text: "Be helpful" }],
+ messages: [{ role: "user", content: [{ type: "text", text: "hi" }] }],
+ thinking: { type: "enabled", budget_tokens: 10240 },
+ };
+ const result = exec.transformRequest("claude-opus-4-7", body, true, {});
+ assert.deepEqual(result.thinking, { type: "enabled", budget_tokens: 10240 });
+ });
+
+ it("preserves disabled thinking shape on /v1/messages routing", () => {
+ const exec = new CliproxyapiExecutor();
+ const body = {
+ model: "claude-opus-4-7",
+ system: [{ type: "text", text: "x" }],
+ messages: [{ role: "user", content: [{ type: "text", text: "hi" }] }],
+ thinking: { type: "disabled", budget_tokens: 0 },
+ };
+ const result = exec.transformRequest("claude-opus-4-7", body, true, {});
+ assert.deepEqual(result.thinking, { type: "disabled", budget_tokens: 0 });
+ });
+
+ it("strips Capy-style adaptive thinking on /v1/messages routing", () => {
+ const exec = new CliproxyapiExecutor();
+ const body = {
+ model: "claude-opus-4-7",
+ system: [{ type: "text", text: "x" }],
+ messages: [{ role: "user", content: [{ type: "text", text: "hi" }] }],
+ thinking: { type: "adaptive", display: "summarized" },
+ };
+ const result = exec.transformRequest("claude-opus-4-7", body, true, {});
+ assert.equal(result.thinking, undefined);
+ });
+
+ it("strips thinking carrying display field even with enabled type", () => {
+ const exec = new CliproxyapiExecutor();
+ const body = {
+ model: "claude-opus-4-7",
+ system: [{ type: "text", text: "x" }],
+ messages: [{ role: "user", content: [{ type: "text", text: "hi" }] }],
+ thinking: { type: "enabled", budget_tokens: 10240, display: "summarized" },
+ };
+ const result = exec.transformRequest("claude-opus-4-7", body, true, {});
+ assert.equal(result.thinking, undefined);
+ });
+
+ it("does not touch thinking on OpenAI-shape bodies", () => {
+ const exec = new CliproxyapiExecutor();
+ const body = {
+ model: "gpt-5.5",
+ messages: [{ role: "user", content: "hi" }],
+ thinking: { type: "adaptive", display: "summarized" },
+ };
+ const result = exec.transformRequest("gpt-5.5", body, true, {});
+ assert.deepEqual(result.thinking, { type: "adaptive", display: "summarized" });
+ });
});
describe("execute", () => {