can1357/oh-my-pi · error · SearchProviderError

Gemini Cloud Code API error (${status}): ${errorText}

Error message

Gemini Cloud Code API error (${status}): ${errorText}

What it means

callGeminiSearch() (Cloud Code Assist path) throws this when the Gemini HTTP response is missing or not ok and no more specific classified error applied. The message includes the HTTP status and the raw error body, with the OAuth access token redacted from the text. If there was no response at all (network failure), it reports status 502 with 'Network error'.

Source

Thrown at packages/coding-agent/src/web/search/providers/gemini.ts:525

				if (!isLastEndpoint) {
					continue;
				}
			}
			break;
		} catch (error) {
			if (isLastEndpoint) {
				throw error;
			}
		}
	}

	if (!response?.ok) {
		const rawErrorText = response ? await response.text() : "Network error";
		const errorText = auth.accessToken ? rawErrorText.split(auth.accessToken).join("[redacted]") : rawErrorText;
		const status = response?.status ?? 502;
		const classified = classifyProviderHttpError("gemini", status, errorText);
		if (classified) throw classified;
		throw new SearchProviderError("gemini", `Gemini Cloud Code API error (${status}): ${errorText}`, status);
	}

	if (!response.body) {
		throw new SearchProviderError("gemini", "Gemini API returned no response body", 500);
	}

	return finalizeGeminiSearchResult(await parseGeminiSearchStream(response.body, model), fetchImpl, signal);
}

async function callGeminiDeveloperSearch(
	apiKey: string,
	endpoint: GeminiDeveloperEndpoint,
	model: string,
	query: string,
	systemPrompt: string | undefined,
	maxOutputTokens: number | undefined,
	temperature: number | undefined,
	toolParams: GeminiToolParams,

View on GitHub (pinned to 9690622007)

Solutions

  1. Read the embedded status and errorText — 401/403 means re-authenticate (refresh Google Cloud credentials / re-run the login flow), 429 means back off, 5xx means retry later
  2. Re-authenticate: refresh or regenerate the access token used for the Cloud Code Assist API
  3. Check network connectivity/proxy settings if the message shows the 502 'Network error' variant
  4. Retry with exponential backoff for transient statuses (429, 500, 503)
Defensive patterns

Strategy: retry

Validate before calling

// Detect an expired token before searching:
function isTokenExpired(auth: { accessToken?: string; expiresAt?: number }): boolean {
  return !auth.accessToken || (auth.expiresAt !== undefined && Date.now() >= auth.expiresAt);
}
if (isTokenExpired(auth)) await refreshAccessToken();

Try / catch

import { SearchProviderError } from "...";
try {
  results = await searchGemini(query);
} catch (err) {
  if (err instanceof SearchProviderError && (err.status === 401 || err.status === 403)) {
    await refreshGoogleAuth();
    results = await searchGemini(query);
  } else if (err instanceof SearchProviderError && (err.status === 429 || err.status >= 500)) {
    await Bun.sleep(backoffMs);
    results = await searchGemini(query);
  } else throw err;
}

Prevention

When it happens

Trigger: Non-OK HTTP status from the Gemini Cloud Code endpoint (401/403 expired OAuth token, 429 quota, 5xx outages), or a fetch that threw/returned no response yielding the 502 'Network error' variant.

Common situations: Expired Google Cloud OAuth access tokens, project not provisioned for Code Assist API, quota exhaustion, corporate proxy breaking TLS, or Google-side incidents.

Related errors


AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31). Data as JSON: /api/errors/0c2dfe5a67095ebd. Report an issue: GitHub.