From aea06ce659a1712aa5c0f73ef3b718f8a1c79b29 Mon Sep 17 00:00:00 2001 From: Dave Lasley Date: Sat, 1 Mar 2025 14:20:50 -0800 Subject: [PATCH] Add retries to bedrock createMessage (#2039) * Add retries to bedrock createMessage Add retries to Bedrock's createMessage as indicated by [this](https://github.com/cline/cline/pull/1605#issuecomment-2665904349) Similar to [this comment](https://github.com/cline/cline/pull/1605#issuecomment-2666290702) I am also experiencing a 429 every once in a while. Measuring a before/after, it's about a 90% improvement when there's no prompt caching. I'm going to add some logging and see if I can track it down further but honestly this is probably worth it as is. * Add changeset --- .changeset/cool-rice-chew.md | 5 +++++ src/api/providers/bedrock.ts | 2 ++ 2 files changed, 7 insertions(+) create mode 100644 .changeset/cool-rice-chew.md diff --git a/.changeset/cool-rice-chew.md b/.changeset/cool-rice-chew.md new file mode 100644 index 0000000000..7d565030cf --- /dev/null +++ b/.changeset/cool-rice-chew.md @@ -0,0 +1,5 @@ +--- +"claude-dev": patch +--- + +Add retries to Bedrock createMessage diff --git a/src/api/providers/bedrock.ts b/src/api/providers/bedrock.ts index 7a17fd6260..0c8908363b 100644 --- a/src/api/providers/bedrock.ts +++ b/src/api/providers/bedrock.ts @@ -1,5 +1,6 @@ import AnthropicBedrock from "@anthropic-ai/bedrock-sdk" import { Anthropic } from "@anthropic-ai/sdk" +import { withRetry } from "../retry" import { ApiHandler } from "../" import { ApiHandlerOptions, bedrockDefaultModelId, BedrockModelId, bedrockModels, ModelInfo } from "../../shared/api" import { ApiStream } from "../transform/stream" @@ -13,6 +14,7 @@ export class AwsBedrockHandler implements ApiHandler { this.options = options } + @withRetry() async *createMessage(systemPrompt: string, messages: Anthropic.Messages.MessageParam[]): ApiStream { let budget_tokens = this.options.thinkingBudgetTokens || 0 const reasoningOn = budget_tokens !== 0 ? true : false