conductor-oss/conductor · error · RuntimeException

Gemini generateContent failed: {message}

Error message

Gemini generateContent failed: {message}

What it means

GeminiChatModel.call() wraps any java.io.IOException from GeminiApi.generateContent() into a RuntimeException. The underlying IOException (transport failure, HTTP error from the Gemini/Vertex endpoint) is preserved as the cause. This is the sole catch for all failures during a Gemini chat completion request.

Source

Thrown at ai/src/main/java/org/conductoross/conductor/ai/providers/gemini/GeminiChatModel.java:166

                        );

        String model =
                opts != null ? opts.getModel() : (options != null ? options.getModel() : null);
        if (model == null) {
            model = "gemini-2.5-flash";
        }

        GeminiApi.GenerateContentResponse result;
        try {
            result =
                    api.generateContent(
                            model,
                            contents,
                            systemInstruction,
                            toolList.isEmpty() ? null : toolList,
                            config);
        } catch (java.io.IOException e) {
            throw new RuntimeException("Gemini generateContent failed: " + e.getMessage(), e);
        }

        return toSpringChatResponse(result, model);
    }

    private List<GeminiApi.Tool> buildTools(GeminiChatOptions opts) {
        List<GeminiApi.Tool> tools = new ArrayList<>();
        if (opts == null) {
            return tools;
        }

        // Google Search
        if (opts.isGoogleSearchRetrieval()) {
            tools.add(GeminiApi.Tool.withGoogleSearch());
        }

        // Code execution
        if (opts.isCodeExecution()) {

View on GitHub (pinned to cf7c3e4a8a)

Solutions

  1. Inspect getCause() and its message for the specific failure.
  2. For API-key mode: verify config.getApiKey() is valid and has the Generative Language API enabled.
  3. For Vertex AI mode: verify config.getProjectId(), config.getLocation(), and that the GoogleCredentials have the aiplatform.endpoints.predict permission.
  4. Verify the model name is available in your region (Vertex AI model availability varies by location).
  5. Increase OkHttp timeouts for large-context requests.

Example fix

// before — may fail silently on transient network error
ChatResponse response = geminiChatModel.call(prompt);

// after — retry once on transient IOException
ChatResponse response;
try {
    response = geminiChatModel.call(prompt);
} catch (RuntimeException e) {
    if (e.getCause() instanceof java.io.IOException && isTransient(e.getMessage())) {
        Thread.sleep(2000);
        response = geminiChatModel.call(prompt);
    } else throw e;
}
Defensive patterns

Strategy: retry

Validate before calling

// Validate Gemini/Vertex config before calling chat model
void validateGeminiConfig(GeminiVertexConfiguration config) {
    boolean hasApiKey = config.getApiKey() != null && !config.getApiKey().isBlank();
    boolean hasVertexCreds = config.getGoogleCredentials() != null
        && config.getProjectId() != null && config.getLocation() != null;
    if (!hasApiKey && !hasVertexCreds) {
        throw new IllegalArgumentException(
            "Either apiKey or Vertex AI credentials (projectId + location + googleCredentials) required");
    }
}

Try / catch

// Retry on transient network failure
for (int attempt = 0; attempt < 3; attempt++) {
    try {
        return geminiChatModel.call(prompt);
    } catch (RuntimeException e) {
        if (e.getCause() instanceof java.io.IOException
                && attempt < 2) {
            Thread.sleep((long) Math.pow(2, attempt) * 1000);
            continue;
        }
        throw new RuntimeException(
            "Gemini chat failed — check API key, project, location, network", e);
    }
}

Prevention

When it happens

Trigger: The OkHttp call to the Gemini generateContent endpoint (generativelanguage.googleapis.com for API-key mode, or a Vertex AI regional endpoint for service-account mode) fails at the transport layer: timeout, DNS failure, connection reset, or a non-2xx HTTP status returned by Google's API.

Common situations: Invalid or expired Gemini API key. Wrong Vertex AI project ID or location. OAuth token for Vertex AI expired or lacks permissions. Network firewall blocking Google APIs. Rate limiting (429) from Google. Model name not available in the configured region for Vertex AI.

Related errors


AI-assisted analysis of conductor-oss/conductor@cf7c3e4a8a (2026-08-14). Data as JSON: /api/errors/a1f50722f1479dc8. Report an issue: GitHub.