{"record":{"id":"1f030ad6e2495940","repo":"spring-projects/spring-ai","slug":"incomplete-google-genai-configuration-provide-ap","errorCode":null,"errorMessage":"Incomplete Google GenAI configuration: Provide 'api-key' for Gemini API or 'project-id' and 'location' for Vertex AI.","messagePattern":"Incomplete Google GenAI configuration: Provide 'api-key' for Gemini API or 'project-id' and 'location' for Vertex AI\\.","errorType":"validation","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"auto-configurations/models/spring-ai-autoconfigure-model-google-genai/src/main/java/org/springframework/ai/model/google/genai/autoconfigure/chat/GoogleGenAiChatAutoConfiguration.java","lineNumber":106,"sourceCode":"\t\t}\n\n\t\t// Mode Selection with Fail-Fast Validation\n\t\tif (properties.isVertexAi()) {\n\t\t\tif (!hasVertexConfig) {\n\t\t\t\tthrow new IllegalStateException(\n\t\t\t\t\t\t\"Vertex AI mode requires both 'project-id' and 'location' to be configured.\");\n\t\t\t}\n\t\t\tconfigureVertexAi(builder, properties);\n\t\t}\n\t\telse if (hasApiKey) {\n\t\t\tbuilder.apiKey(properties.getApiKey());\n\t\t}\n\t\telse if (hasVertexConfig) {\n\t\t\tlogger.debug(\"Project ID and Location detected. Defaulting to Vertex AI mode.\");\n\t\t\tconfigureVertexAi(builder, properties);\n\t\t}\n\t\telse {\n\t\t\tthrow new IllegalStateException(\"Incomplete Google GenAI configuration: Provide 'api-key' for Gemini API \"\n\t\t\t\t\t+ \"or 'project-id' and 'location' for Vertex AI.\");\n\t\t}\n\n\t\treturn builder.build();\n\t}\n\n\tprivate void configureVertexAi(Client.Builder builder, GoogleGenAiConnectionProperties props) throws IOException {\n\t\tAssert.hasText(props.getProjectId(), \"Google GenAI project-id must be set for Vertex AI mode!\");\n\t\tAssert.hasText(props.getLocation(), \"Google GenAI location must be set for Vertex AI mode!\");\n\n\t\tbuilder.project(props.getProjectId()).location(props.getLocation()).vertexAI(true);\n\n\t\tif (props.getCredentialsUri() != null) {\n\t\t\ttry (var is = props.getCredentialsUri().getInputStream()) {\n\t\t\t\tbuilder.credentials(GoogleCredentials.fromStream(is));\n\t\t\t}\n\t\t}\n\t}","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/auto-configurations/models/spring-ai-autoconfigure-model-google-genai/src/main/java/org/springframework/ai/model/google/genai/autoconfigure/chat/GoogleGenAiChatAutoConfiguration.java#L88-L124","documentation":"When neither Vertex AI credentials (project-id + location) nor a Gemini API key is configured, GoogleGenAiChatAutoConfiguration cannot build any client and throws this IllegalStateException. Unlike error 17, this fires when vertex-ai mode was not explicitly requested but no usable mode could be inferred from the configuration at all.","triggerScenarios":"googleGenAiClient bean method runs where hasApiKey is false, hasVertexConfig is false, and properties.isVertexAi() is false — i.e. spring.ai.google.genai.api-key, project-id, and location are all unset, so the else branch throws.","commonSituations":"Deploying without injecting the API key env var/secret; properties file not loaded (wrong profile); typo in spring.ai.google.genai.* keys so nothing binds; fresh project where the chat starter was added but never configured.","solutions":["Set spring.ai.google.genai.api-key for Gemini Developer API usage.","Or set both spring.ai.google.genai.project-id and spring.ai.google.genai.location for Vertex AI usage.","Verify the configuration source (application.yml, env vars, secret manager) is actually loaded at runtime — check the active profile and property prefix spelling."],"exampleFix":"// before\n# no google genai properties\n// after\nspring.ai.google.genai.api-key=${GEMINI_API_KEY}","handlingStrategy":"validation","validationCode":"if (props.getApiKey() == null && (props.getProjectId() == null || props.getLocation() == null))\n    throw new IllegalStateException(\"Provide spring.ai.google.genai.api-key or project-id + location\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Inject the API key via secret manager, not hardcoded values.","Check the active profile actually loads the properties file.","Add CI config validation to catch missing spring.ai.google.genai keys before deploy."],"tags":["google-genai","gemini","missing-config"],"backgroundTag":"missing-required-config-field","analyzedSha":"98a7beda4f29d80a71c5837eb4053b03a93a46f7","analyzedAt":"2026-09-11T14:15:49.441Z","contentChangedAt":"2026-09-11T14:15:49.441Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}