continuedev/continue · error · Error
data.error.message
Error message
data.error.message
What it means
Thrown by processGeminiResponse when the Gemini API response JSON contains an 'error' field; the error message from the payload is re-thrown directly. This surfaces Google's own error text (e.g. API key issues, safety blocks, quota, invalid model) during chat streaming.
Source
Thrown at core/llm/llms/Gemini.ts:400
if (buffer.startsWith(",")) {
buffer = buffer.slice(1);
}
const parts = buffer.split("\n,");
let foundIncomplete = false;
for (let i = 0; i < parts.length; i++) {
const part = parts[i];
let data: GeminiChatResponse;
try {
data = JSON.parse(part) as GeminiChatResponse;
} catch (e) {
foundIncomplete = true;
continue; // yo!
}
if ("error" in data) {
throw new Error(data.error.message);
}
// In case of max tokens reached, gemini will sometimes return content with no parts, even though that doesn't match the API spec
const contentParts = data?.candidates?.[0]?.content?.parts;
if (contentParts) {
const textParts: MessagePart[] = [];
const toolCalls: ToolCallDelta[] = [];
for (const part of contentParts) {
if ("text" in part) {
textParts.push({ type: "text", text: part.text });
} else if ("functionCall" in part) {
const thoughtSignature = part.thoughtSignature;
toolCalls.push({
type: "function",
id: part.functionCall.id ?? uuidv4(),
function: {
name: part.functionCall.name,View on GitHub (pinned to 5522c6f44c)
Solutions
- Match the message text: 'API key not valid' -> fix GEMINI_API_KEY; RESOURCE_EXHAUSTED -> backoff/quota; 'not found' -> fix model name
- Test the key with a curl call to generativelanguage.googleapis.com
- Add exponential backoff for RESOURCE_EXHAUSTED quota messages
- Use the current model name (e.g. gemini-1.5-pro/gemini-2.0-flash) from Google's docs
Example fix
// before
new Gemini({ apiKey: process.env.GEMINI_API_KEY, model: 'gemini-pro' });
// after
new Gemini({ apiKey: process.env.GEMINI_API_KEY?.trim(), model: 'gemini-2.0-flash' }); Defensive patterns
Strategy: try-catch
Validate before calling
const key = process.env.GEMINI_API_KEY?.trim();
if (!key) throw new Error('GEMINI_API_KEY required'); Type guard
function isGeminiApiError(e: unknown): boolean {
return e instanceof Error && /API key|quota|safety|RESOURCE_EXHAUSTED|PERMISSION|not found/i.test(e.message);
} Try / catch
try { for await (const m of geminiStream) { /* ... */ } }
catch (e) {
if (isGeminiApiError(e)) { handleConfigOrQuota(e); return; }
throw e;
} Prevention
- Validate GEMINI_API_KEY at startup
- Handle RESOURCE_EXHAUSTED with backoff
- Retry safety-block responses with adjusted safetySettings
When it happens
Trigger: Streaming chat with an invalid GEMINI_API_KEY (API key not valid), quota exhaustion (429 RESOURCE_EXHAUSTED), requesting a nonexistent/deprecated model, or region-blocked API access, each returned as an error object in the response body.
Common situations: Expired/truncated GEMINI_API_KEY, free-tier keys hitting RPM/TPM limits during indexing loops, using gemini-pro after deprecation, or calling from an unsupported region/VPN.
Related errors
- MCP Connection ${serverId} not found
- Error getting prompt: MCP Connection ${serverName} not found
- no url found
- no query params found
- Depth must be a number
AI-assisted analysis of continuedev/continue@5522c6f44c (2026-08-27).
Data as JSON: /api/errors/83e626cf6353e5e6.
Report an issue: GitHub.