Skip to content

Commit 6a96c18

Browse files
authored
Handle Gemini Rate Limits (RooCodeInc#3532)
1 parent 9df023b commit 6a96c18

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

.changeset/chatty-emus-marry.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"claude-dev": patch
3+
---
4+
5+
Handle Gemini Rate limiting

src/api/providers/gemini.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Anthropic } from "@anthropic-ai/sdk"
22
// Restore GenerateContentConfig import and add GenerateContentResponseUsageMetadata
3-
import { GoogleGenAI, type Content, type GenerateContentConfig, type GenerateContentResponseUsageMetadata } from "@google/genai"
3+
import { GoogleGenAI, type GenerateContentConfig, type GenerateContentResponseUsageMetadata } from "@google/genai"
44
import { withRetry } from "../retry"
55
import { ApiHandler } from "../"
66
import { ApiHandlerOptions, geminiDefaultModelId, GeminiModelId, geminiModels, ModelInfo } from "@shared/api"
@@ -160,9 +160,20 @@ export class GeminiHandler implements ApiHandler {
160160
}
161161
} catch (error) {
162162
apiSuccess = false
163-
apiError = error instanceof Error ? error.message : String(error)
164163
// Let the error propagate to be handled by withRetry or Task.ts
165164
// Telemetry will be sent in the finally block.
165+
if (error instanceof Error) {
166+
apiError = error.message
167+
168+
// Gemini doesn't include status codes in their errors
169+
// https://github.com/googleapis/js-genai/blob/61f7f27b866c74333ca6331883882489bcb708b9/src/_api_client.ts#L569
170+
if (error.name === "ClientError" && error.message.includes("got status: 429 Too Many Requests.")) {
171+
;(error as any).status = 429
172+
}
173+
} else {
174+
apiError = String(error)
175+
}
176+
166177
throw error
167178
} finally {
168179
const sdkCallEndTime = Date.now()

0 commit comments

Comments
 (0)