From 3de0c84d1d19f2e9624528a01eb6fbccbe1607a2 Mon Sep 17 00:00:00 2001 From: diegosouzapw Date: Sat, 9 May 2026 21:05:08 -0300 Subject: [PATCH] fix(providers): strip OpenAI-specific fields in Kiro translator to prevent 400 errors (#2037) --- open-sse/executors/kiro.ts | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/open-sse/executors/kiro.ts b/open-sse/executors/kiro.ts index f4b7b2a1e2..c39abec5c7 100644 --- a/open-sse/executors/kiro.ts +++ b/open-sse/executors/kiro.ts @@ -197,11 +197,23 @@ export class KiroExecutor extends BaseExecutor { transformRequest(model: string, body: unknown, stream: boolean, credentials: unknown): unknown { void stream; void credentials; - // Kiro uses conversationState.currentMessage.userInputMessage.modelId, - // not a top-level "model" field. chatCore injects translatedBody.model - // which Kiro API rejects as unknown top-level field. - const { model: _model, ...rest } = body as Record; - return rest; + const b = body as Record; + + // Kiro API is strict and rejects any unknown top-level fields (like 'tools', 'stream', 'model', etc.) + // We only preserve the fields specifically built by the openai-to-kiro translator. + const kiroPayload: Record = {}; + if (b.conversationState !== undefined) kiroPayload.conversationState = b.conversationState; + if (b.profileArn !== undefined) kiroPayload.profileArn = b.profileArn; + if (b.inferenceConfig !== undefined) kiroPayload.inferenceConfig = b.inferenceConfig; + + // Fallback: if somehow conversationState isn't there, return the rest without model + // (for backward compatibility if something else bypasses the translator) + if (!kiroPayload.conversationState) { + const { model: _model, ...rest } = b; + return rest; + } + + return kiroPayload; } /**