Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active
TypeScript aianthropicartifactsawsazurechatgptchatgpt-cloneclaudeclonedeepseekgeminigooglegpt-5librechatmcpo1openairesponses-apivisionwebui
🎫 fix: Strip Reserved Fields From Bedrock `additionalModelRequestFields` (#14246)
Danny Avila91658339ec39
diff --git a/packages/data-provider/specs/bedrock.spec.ts b/packages/data-provider/specs/bedrock.spec.tsindex 7952925131..9f3cf81e31 100644--- a/packages/data-provider/specs/bedrock.spec.ts+++ b/packages/data-provider/specs/bedrock.spec.ts@@ -1372,6 +1372,89 @@ describe('bedrockInputParser', () => {});});+ // Regression for #14029: `system` is a reserved top-level Converse field, so a+ // copy left inside additionalModelRequestFields makes Bedrock reject the request+ // ("The additional field system conflicts with an existing field").+ describe('system field (issue #14029)', () => {+ test('promotes system to root without duplicating it in additionalModelRequestFields', () => {+ const parsed = bedrockInputParser.parse({+ model: 'some-other-model',+ system: 'You are a helpful assistant.',+ }) as Record<string, unknown>;+ expect((parsed.additionalModelRequestFields as Record<string, unknown>).system).toBe(+ 'You are a helpful assistant.',+ );++ const output = bedrockOutputParser(parsed);+ expect(output.system).toBe('You are a helpful assistant.');+ expect(output.additionalModelRequestFields).toBeUndefined();+ });++ test('strips system from additionalModelRequestFields while preserving other fields', () => {+ const parsed = bedrockInputParser.parse({+ model: 'anthropic.claude-3-7-sonnet',+ system: 'You are a helpful assistant.',+ }) as Record<string, unknown>;++ const output = bedrockOutputParser(parsed);+ const amrf = output.additionalModelRequestFields as Record<string, unknown> | undefined;+ expect(output.system).toBe('You are a helpful assistant.');+ expect(amrf?.system).toBeUndefined();+ expect(amrf?.thinking).toBeDefined();+ });++ // DocumentType permits scalars, so a saved preset can carry a non-object+ // additionalModelRequestFields; the `system` cleanup must not throw on it.+ test.each([['a-scalar-string'], [42], [true]])(+ 'tolerates a scalar additionalModelRequestFields (%p) without throwing',+ (scalar) => {+ expect(() =>+ bedrockOutputParser({+ model: 'some-other-model',+ additionalModelRequestFields: scalar,+ }),+ ).not.toThrow();+ },+ );++ // `system` is not the only reserved name: the input parser's catch-all routes+ // ANY unknown preset key into additionalModelRequestFields, and each reserved+ // Converse field collides the same way when the request sends it top-level.+ test.each([['messages'], ['modelId'], ['toolConfig'], ['inferenceConfig']])(+ 'strips reserved Converse field %p from additionalModelRequestFields',+ (reserved) => {+ const parsed = bedrockInputParser.parse({+ model: 'some-other-model',+ [reserved]: { some: 'value' },+ }) as Record<string, unknown>;+ expect(+ (parsed.additionalModelRequestFields as Record<string, unknown>)[reserved],+ ).toBeDefined();++ const output = bedrockOutputParser(parsed);+ const amrf = output.additionalModelRequestFields as Record<string, unknown> | undefined;+ expect(amrf?.[reserved]).toBeUndefined();+ },+ );++ test('keeps non-reserved passthrough fields intact while stripping reserved ones', () => {+ const output = bedrockOutputParser({+ model: 'some-other-model',+ additionalModelRequestFields: {+ system: 'dup',+ messages: [],+ anthropic_beta: ['context-1m-2025-08-07'],+ top_k: 40,+ },+ });+ const amrf = output.additionalModelRequestFields as Record<string, unknown>;+ expect(amrf.system).toBeUndefined();+ expect(amrf.messages).toBeUndefined();+ expect(amrf.anthropic_beta).toEqual(['context-1m-2025-08-07']);+ expect(amrf.top_k).toBe(40);+ });+ });+describe('Model switching cleanup', () => {test('should strip anthropic_beta when switching from Anthropic to non-Anthropic model', () => {const staleConversationData = {diff --git a/packages/data-provider/src/bedrock.ts b/packages/data-provider/src/bedrock.tsindex 3aad248075..69b9b9fa7b 100644--- a/packages/data-provider/src/bedrock.ts+++ b/packages/data-provider/src/bedrock.ts@@ -737,6 +737,25 @@ function configureThinking(data: AnthropicInput): AnthropicInput {return updatedData;}+/** Top-level Converse request fields (issue #14029: `system` from a preset).+ * The input parser's catch-all routes unknown keys into+ * additionalModelRequestFields, and Bedrock rejects any that collide with a+ * field the request already sends (`messages`/`modelId` always,+ * `inferenceConfig` whenever maxTokens is set, `toolConfig` for agents). */+const RESERVED_CONVERSE_FIELDS = [+ 'system',+ 'messages',+ 'modelId',+ 'toolConfig',+ 'inferenceConfig',+ 'guardrailConfig',+ 'promptVariables',+ 'requestMetadata',+ 'performanceConfig',+ 'additionalModelRequestFields',+ 'additionalModelResponseFieldPaths',+];+export const bedrockOutputParser = (data: Record<string, unknown>) => {const knownKeys = [...Object.keys(s.tConversationSchema.shape), 'topK', 'top_k'];let result: Record<string, unknown> = {};@@ -776,7 +795,21 @@ export const bedrockOutputParser = (data: Record<string, unknown>) => {}result = configureThinking(result as AnthropicInput);- const amrf = result.additionalModelRequestFields as Record<string, unknown> | undefined;+ let amrf = result.additionalModelRequestFields as Record<string, unknown> | undefined;+ // Reserved top-level Converse request fields; a copy inside+ // additionalModelRequestFields makes Bedrock reject the request+ // ("The additional field <name> conflicts with an existing field").+ // Guard against non-object values, which the schema's DocumentType permits.+ if (amrf && typeof amrf === 'object') {+ const reserved = RESERVED_CONVERSE_FIELDS.filter((key) => key in (amrf ?? {}));+ if (reserved.length > 0) {+ amrf = { ...amrf };+ for (const key of reserved) {+ delete amrf[key];+ }+ result.additionalModelRequestFields = amrf;+ }+ }if (!amrf || Object.keys(amrf).length === 0) {delete result.additionalModelRequestFields;}