Skip to content

Commit

Permalink
request retry policy aligned with the one used by Python SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
morisil committed Nov 17, 2024
1 parent 7132763 commit f4548b8
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/commonMain/kotlin/Anthropic.kt
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ class Anthropic internal constructor(

private val client = HttpClient {

val retriableResponses = setOf<HttpStatusCode>(
HttpStatusCode.RequestTimeout,
HttpStatusCode.Conflict,
HttpStatusCode.TooManyRequests,
HttpStatusCode.InternalServerError
)

install(ContentNegotiation) {
json(anthropicJson)
}
Expand All @@ -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
}
}

Expand Down

0 comments on commit f4548b8

Please sign in to comment.