Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Decision model: no answer-sized max_tokens cap on the custom chat protocol

Bugfixer 20ecd9e9317b5
diff --git a/server/decider/custom.test.ts b/server/decider/custom.test.ts
index 1708af0ee0..9738f7eb49 100644
--- a/server/decider/custom.test.ts
+++ b/server/decider/custom.test.ts
@@ -107,6 +107,8 @@ describe("a custom decision endpoint", () => {
messages: [{ role: "system" }, { role: "user" }],
});
expect(body).not.toHaveProperty("provider");
+ // A thinking model (Gemini 2.5 and later) counts its thinking against max_tokens; a cap sized for the answer alone could leave it empty.
+ expect(body).not.toHaveProperty("max_tokens");
expect(JSON.stringify(init?.headers)).not.toContain("openrouter");
});
diff --git a/server/decider/custom.ts b/server/decider/custom.ts
index 18ed21d54b..d22f128d11 100644
--- a/server/decider/custom.ts
+++ b/server/decider/custom.ts
@@ -20,7 +20,14 @@ export function customEndpoint(baseUrl: string | undefined, api: CustomApi): URL
function requestBody(api: CustomApi, state: unknown, questions: Record<string, DeciderQuestion>, model: string) {
if (api === "decisions") return decisionsBody(state, questions, model);
- return api === "chat" ? chatRequestBody(state, questions, model) : systemOneBody(state, questions, model);
+ return api === "chat" ? customChatBody(state, questions, model) : systemOneBody(state, questions, model);
+}
+
+/** OpenRouter's chat body without its `max_tokens`: a thinking model behind the gateway (Gemini 2.5 and later) counts its thinking
+ * against that cap, which is sized for the answer alone, and could answer empty. The gateway's own limit applies instead. */
+function customChatBody(state: unknown, questions: Record<string, DeciderQuestion>, model: string) {
+ const { max_tokens: _answerOnly, ...body } = chatRequestBody(state, questions, model);
+ return body;
}
export function systemOneBody(state: unknown, questions: Record<string, DeciderQuestion>, model: string) {