Skip to content

Commit 2c5f956

Browse files
authored
Parse the retry out of the gemini 429 response (#2118)
1 parent a7d31aa commit 2c5f956

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/core/Cline.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1230,7 +1230,21 @@ export class Cline extends EventEmitter<ClineEvents> {
12301230
}
12311231

12321232
const baseDelay = requestDelaySeconds || 5
1233-
const exponentialDelay = Math.ceil(baseDelay * Math.pow(2, retryAttempt))
1233+
let exponentialDelay = Math.ceil(baseDelay * Math.pow(2, retryAttempt))
1234+
1235+
// If the error is a 429, and the error details contain a retry delay, use that delay instead of exponential backoff
1236+
if (error.status === 429) {
1237+
const geminiRetryDetails = error.errorDetails?.find(
1238+
(detail: any) => detail["@type"] === "type.googleapis.com/google.rpc.RetryInfo",
1239+
)
1240+
if (geminiRetryDetails) {
1241+
const match = geminiRetryDetails?.retryDelay?.match(/^(\d+)s$/)
1242+
if (match) {
1243+
exponentialDelay = Number(match[1]) + 1
1244+
}
1245+
}
1246+
}
1247+
12341248
// Wait for the greater of the exponential delay or the rate limit delay
12351249
const finalDelay = Math.max(exponentialDelay, rateLimitDelay)
12361250

0 commit comments

Comments
 (0)