From f4548b87d44b3ac048feb27426f4ae27b7bebb11 Mon Sep 17 00:00:00 2001 From: Kazik Pogoda Date: Sun, 17 Nov 2024 16:10:03 +0100 Subject: [PATCH] request retry policy aligned with the one used by Python SDK --- src/commonMain/kotlin/Anthropic.kt | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/commonMain/kotlin/Anthropic.kt b/src/commonMain/kotlin/Anthropic.kt index 65fef1d..c77561a 100644 --- a/src/commonMain/kotlin/Anthropic.kt +++ b/src/commonMain/kotlin/Anthropic.kt @@ -116,6 +116,13 @@ class Anthropic internal constructor( private val client = HttpClient { + val retriableResponses = setOf( + HttpStatusCode.RequestTimeout, + HttpStatusCode.Conflict, + HttpStatusCode.TooManyRequests, + HttpStatusCode.InternalServerError + ) + install(ContentNegotiation) { json(anthropicJson) } @@ -129,12 +136,10 @@ class Anthropic internal constructor( } install(HttpRequestRetry) { - retryOnServerErrors(maxRetries = 5) exponentialDelay() maxRetries = 5 retryIf { _, response -> - response.status == HttpStatusCode.TooManyRequests - || response.status.value == 529 // Overloaded + response.status in retriableResponses || response.status.value >= 500 } }