Skip to content

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

API reasoning levels: reach gpt-6 models, and keep the level on the Responses route

milind-sonid28335cec79d
diff --git a/server/drivers/openai-chat.ts b/server/drivers/openai-chat.ts
index 279b5021e1..ec7c60171d 100644
--- a/server/drivers/openai-chat.ts
+++ b/server/drivers/openai-chat.ts
@@ -282,7 +282,7 @@ export function createOpenAIChatRuntime<Config>(options: RuntimeOptions<Config>)
const served = options.servedModel ? await options.servedModel(model) : model;
const payload = JSON.stringify(route === "responses"
- ? responsesRequest({ model: served, messages, tools, replay: (message) => responseOutputs.get(message), summaries: routes.summaries(model) })
+ ? responsesRequest({ model: served, messages, tools, replay: (message) => responseOutputs.get(message), summaries: routes.summaries(model), effort: options.requestBody(served, messages, stream, variant).reasoning_effort })
: {
...options.requestBody(served, messages, stream, variant),
...(route === "chat-reasoning-off" ? { reasoning_effort: "none" } : {}),
diff --git a/server/drivers/openai-compat-reasoning.test.ts b/server/drivers/openai-compat-reasoning.test.ts
index 38c4aae527..5fd0e918a4 100644
--- a/server/drivers/openai-compat-reasoning.test.ts
+++ b/server/drivers/openai-compat-reasoning.test.ts
@@ -46,11 +46,14 @@ afterEach(() => vi.unstubAllGlobals());
describe("reasoning effort on an API key", () => {
it("offers OpenAI's reasoning models the levels, and sends the one picked as reasoning_effort", async () => {
- const chats = server([{ id: "gpt-5.2", created: 3 }, { id: "gpt-5-chat-latest", created: 2 }, { id: "gpt-4.1", created: 1 }, { id: "o1-mini", created: 0 }]);
+ const chats = server([{ id: "gpt-6.1-sol", created: 5 }, { id: "gpt-5.1-chat-latest", created: 4 }, { id: "gpt-5.2", created: 3 }, { id: "gpt-5-chat-latest", created: 2 }, { id: "gpt-4.1", created: 1 }, { id: "o1-mini", created: 0 }]);
const instance = await create({ url: "https://llm.example.test/v1", catalog: "openai" });
try {
expect(instance.adapter.capabilities.modelVariants).toBe(true);
- expect(variantsOf(instance)).toEqual({ "gpt-5.2": ["low", "medium", "high"], "gpt-5-chat-latest": undefined, "gpt-4.1": undefined, "o1-mini": undefined });
+ expect(variantsOf(instance)).toEqual({
+ "gpt-6.1-sol": ["low", "medium", "high"], "gpt-5.1-chat-latest": undefined,
+ "gpt-5.2": ["low", "medium", "high"], "gpt-5-chat-latest": undefined, "gpt-4.1": undefined, "o1-mini": undefined,
+ });
await turn(instance, "gpt-5.2", "low");
await turn(instance, "gpt-5.2");
await turn(instance, "gpt-4.1", "low");
diff --git a/server/drivers/openai-compat.ts b/server/drivers/openai-compat.ts
index 1d36513e27..f5fa8fc112 100644
--- a/server/drivers/openai-compat.ts
+++ b/server/drivers/openai-compat.ts
@@ -45,8 +45,8 @@ const OLLAMA_FIRST_LIST_MS = 2_000;
const withEffort = (effort: string | undefined) => effort ? { reasoning_effort: effort } : {};
const EFFORT_CHOICES = ["low", "medium", "high"].map((id) => ({ id, label: titleCaseModelId(id, /[-_ ]+/) }));
-/** OpenAI's reasoning models. o1-mini, o1-preview and the gpt-5 chat alias refuse `reasoning_effort`. */
-const OPENAI_REASONING = /^(?:o1(?!-mini|-preview)|o[3-9]|gpt-5(?!-chat))/i;
+/** OpenAI's reasoning models, gpt-5 onward. o1-mini, o1-preview and the chat aliases refuse `reasoning_effort`. */
+const OPENAI_REASONING = /^(?:o1(?!-mini|-preview)|o[3-9]|gpt-(?:[5-9]|[1-9]\d)(?![\d.]*-chat))/i;
const localFacts = ({ bytes, parameters, quantization, tools, vision }: OllamaModel) => ({
...(bytes ? { bytes } : {}), ...(parameters ? { parameters } : {}), ...(quantization ? { quantization } : {}),
diff --git a/server/drivers/openai-responses.test.ts b/server/drivers/openai-responses.test.ts
index 7a98d2aebd..c4c8876cd5 100644
--- a/server/drivers/openai-responses.test.ts
+++ b/server/drivers/openai-responses.test.ts
@@ -95,14 +95,14 @@ afterEach(async () => {
forgetKey(KEY);
});
-async function fixture(script: Script, apiUrl = OPENAI) {
+async function fixture(script: Script, apiUrl = OPENAI, models: unknown[] = []) {
vi.spyOn(console, "warn").mockImplementation(() => {});
const directory = mkdtempSync(join(tmpdir(), "omb-responses-"));
const calls: Call[] = [];
const server = createServer(async (request, response) => {
if (request.url === "/v1/models") {
response.setHeader("content-type", "application/json");
- response.end('{"data":[]}');
+ response.end(JSON.stringify({ data: models }));
return;
}
let data = "";
@@ -247,6 +247,20 @@ describe("a model that refuses tools over Chat Completions, at OpenAI's address"
expect(f.paths()).toEqual(["/v1/chat/completions", "/v1/responses", "/v1/responses"]);
});
+ it("keeps the reasoning level the person picked when it moves to Responses", async () => {
+ const f = await fixture((call, response) => {
+ if (call.path.endsWith("/chat/completions")) reject(response, 400, refusalOf(MODEL));
+ else answer(response, "Hello there.");
+ }, OPENAI, [{ id: MODEL, created: 1 }]);
+ await f.instance.refreshModels?.();
+ expect(await f.turn({ variant: "low" })).toMatchObject({ end: { ok: true } });
+ expect(await f.turn()).toMatchObject({ end: { ok: true } });
+ expect(f.paths()).toEqual(["/v1/chat/completions", "/v1/responses", "/v1/responses"]);
+ expect(f.calls[0]!.body).toMatchObject({ reasoning_effort: "low" });
+ expect(f.calls[1]!.body.reasoning).toEqual({ effort: "low", summary: "auto" });
+ expect(f.calls[2]!.body.reasoning).toEqual({ summary: "auto" });
+ });
+
it("leaves a model that accepts tools on Chat Completions", async () => {
const f = await fixture((_call, response) => {
response.writeHead(200, { "content-type": "text/event-stream" });
diff --git a/server/drivers/openai-responses.ts b/server/drivers/openai-responses.ts
index 42ecfa1af7..ebed66822c 100644
--- a/server/drivers/openai-responses.ts
+++ b/server/drivers/openai-responses.ts
@@ -114,6 +114,8 @@ export function responsesRequest(input: {
tools: readonly ChatToolDefinition[];
replay: (message: OpenAIChatMessage) => ResponseItem[] | undefined;
summaries: boolean;
+ /** The reasoning level the person picked, as the Chat Completions body would carry it in `reasoning_effort`. */
+ effort?: unknown;
}): Record<string, unknown> {
const instructions = input.messages.filter((message) => message.role === "system" && typeof message.content === "string")
.map((message) => message.content).join("\n\n");
@@ -123,7 +125,9 @@ export function responsesRequest(input: {
store: false,
...(instructions ? { instructions } : {}),
input: input.messages.flatMap((message) => inputItems(message, input.replay(message))),
- ...(input.summaries ? { reasoning: { summary: "auto" } } : {}),
+ ...(input.summaries || typeof input.effort === "string" ? { reasoning: {
+ ...(typeof input.effort === "string" ? { effort: input.effort } : {}), ...(input.summaries ? { summary: "auto" } : {}),
+ } } : {}),
tools: input.tools.map(({ function: { name, description, parameters } }) => ({ type: "function", name, description, parameters, strict: false })),
};
}