From 2bd759142023a3cb6e4dd2fd838816d83bb51f95 Mon Sep 17 00:00:00 2001 From: Christopher Pruijsen Date: Thu, 10 Sep 2026 19:13:36 +0100 Subject: [PATCH] fix(js/plugins/compat-oai): omit visualDetailLevel from OpenAI request bodies visualDetailLevel is applied to image_url.detail, but was then spread into the Chat Completions body via restOfConfig and rejected as an unknown parameter. --- js/plugins/compat-oai/src/model.ts | 1 + .../compat-oai/tests/compat_oai_test.ts | 41 +++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/js/plugins/compat-oai/src/model.ts b/js/plugins/compat-oai/src/model.ts index c5c7df7a96..1c5070e140 100644 --- a/js/plugins/compat-oai/src/model.ts +++ b/js/plugins/compat-oai/src/model.ts @@ -578,6 +578,7 @@ export function toOpenAIRequestBody( version: modelVersion, tools: toolsFromConfig, apiKey, + visualDetailLevel, ...restOfConfig } = request.config ?? {}; diff --git a/js/plugins/compat-oai/tests/compat_oai_test.ts b/js/plugins/compat-oai/tests/compat_oai_test.ts index 47ba29c5de..a9209c769f 100644 --- a/js/plugins/compat-oai/tests/compat_oai_test.ts +++ b/js/plugins/compat-oai/tests/compat_oai_test.ts @@ -1500,6 +1500,47 @@ describe('toOpenAiRequestBody', () => { }, }); }); + + it('applies visualDetailLevel to image URLs without leaking it into the request body', () => { + const request = { + messages: [ + { + role: 'user', + content: [ + { text: 'describe this image' }, + { + media: { + contentType: 'image/jpeg', + url: 'https://example.com/image.jpg', + }, + }, + ], + }, + ], + config: { + visualDetailLevel: 'high', + }, + } as GenerateRequest; + + const actualOutput = toOpenAIRequestBody('gpt-4o', request); + + expect(actualOutput).not.toHaveProperty('visualDetailLevel'); + expect(actualOutput.messages).toStrictEqual([ + { + role: 'user', + content: [ + { type: 'text', text: 'describe this image' }, + { + type: 'image_url', + image_url: { + url: 'https://example.com/image.jpg', + detail: 'high', + }, + }, + ], + }, + ]); + }); }); describe('openAIModelRunner', () => {