From 2709c1fb255282321fab296e709651a79017fe37 Mon Sep 17 00:00:00 2001 From: Robert Craigie Date: Tue, 5 Nov 2024 11:30:35 +0000 Subject: [PATCH] fix(vertex): don't mutate request body inputs --- packages/vertex-sdk/src/client.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/vertex-sdk/src/client.ts b/packages/vertex-sdk/src/client.ts index 61f67582..06231649 100644 --- a/packages/vertex-sdk/src/client.ts +++ b/packages/vertex-sdk/src/client.ts @@ -114,6 +114,12 @@ export class AnthropicVertex extends Core.APIClient { url: string; timeout: number; } { + if (Core.isObj(options.body)) { + // create a shallow copy of the request body so that code that mutates it later + // doesn't mutate the original user-provided object + options.body = { ...options.body }; + } + if (Core.isObj(options.body)) { if (!options.body['anthropic_version']) { options.body['anthropic_version'] = DEFAULT_VERSION;