{"record":{"id":"b501d37afa7bd51a","repo":"apache/beam","slug":"error-during-gemini-inference-request","errorCode":null,"errorMessage":"Error during Gemini inference request","messagePattern":"Error during Gemini inference request","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"sdks/java/ml/inference/gemini/src/main/java/org/apache/beam/sdk/ml/inference/gemini/GeminiModelHandler.java","lineNumber":83,"sourceCode":"  }\n\n  @Override\n  public Iterable<PredictionResult<InputT, OutputT>> request(List<InputT> input) {\n    try {\n      GeminiRequestFunction<InputT, OutputT> requestFn = modelParameters.getRequestFn();\n      List<OutputT> responses = requestFn.apply(modelParameters.getModelName(), input, client);\n\n      if (responses.size() != input.size()) {\n        throw new IllegalStateException(\"Number of responses must match number of inputs\");\n      }\n\n      List<PredictionResult<InputT, OutputT>> results = new ArrayList<>();\n      for (int i = 0; i < input.size(); i++) {\n        results.add(PredictionResult.create(input.get(i), responses.get(i)));\n      }\n      return results;\n    } catch (Exception e) {\n      throw new RuntimeException(\"Error during Gemini inference request\", e);\n    }\n  }\n}\n","sourceCodeStart":65,"sourceCodeEnd":87,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/ml/inference/gemini/src/main/java/org/apache/beam/sdk/ml/inference/gemini/GeminiModelHandler.java#L65-L87","documentation":"Any exception thrown while executing the Gemini inference call (network errors, API errors, deserialization problems) is caught in GeminiModelHandler.request() and rethrown as a RuntimeException with the message \"Error during Gemini inference request\", preserving the original as the cause. It is a generic wrapper so callers get a uniform failure type from the handler.","triggerScenarios":"modelHandler.request(inputs) invoked when the underlying GeminiRequestFunction throws: connectivity failures, 4xx/5xx from the Gemini or Vertex AI endpoint, invalid model name, auth failures, or response parsing errors.","commonSituations":"Expired or missing credentials, wrong model name, quota exhaustion (429), transient network outages, and SDK response-shape changes after upgrading the Google GenAI client library.","solutions":["Inspect the cause (e.getCause()) to identify the real failure.","Verify API key / Vertex AI credentials and network reachability to the endpoint.","Check the model name and request size against current Gemini API limits and quotas.","Pin/upgrade the Google GenAI SDK version to one compatible with your response parsing."],"exampleFix":"// before\n} catch (Exception e) { LOG.error(\"inference failed\"); }\n// after\ntry { results = handler.request(batch); }\ncatch (RuntimeException e) { LOG.error(\"Gemini inference failed\", e.getCause()); throw e; }","handlingStrategy":"try-catch","validationCode":"if (apiKeyOrCredentialsMissing()) throw new IllegalStateException(\"configure Gemini credentials before inference\");","typeGuard":null,"tryCatchPattern":"try { results = handler.request(batch); } catch (RuntimeException e) { Throwable cause = e.getCause(); if (cause instanceof java.net.ConnectException) { /* backoff/retry */ } else if (cause instanceof com.google.genai.ApiException apiEx && apiEx.code() == 429) { /* rate-limit backoff */ } else { throw e; } }","preventionTips":["Verify credentials and model names before running the pipeline","Keep batch sizes within API limits","Pin the Google GenAI SDK version and test parsing after upgrades","Add retry with backoff around transient failures"],"tags":["java","inference","wrapped-exception"],"backgroundTag":"api-request-failed","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}