{"record":{"id":"114c58f9001e3f93","repo":"spring-projects/spring-ai","slug":"vertex-ai-mode-requires-both-project-id-and-loc","errorCode":null,"errorMessage":"Vertex AI mode requires both 'project-id' and 'location' to be configured.","messagePattern":"Vertex AI mode requires both 'project-id' and 'location' to be configured\\.","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":93,"sourceCode":"\t\tboolean hasLocation = StringUtils.hasText(properties.getLocation());\n\t\tboolean hasVertexConfig = hasProject && hasLocation;\n\n\t\t// Ambiguity Guard: Professional logging\n\t\tif (hasApiKey && hasVertexConfig) {\n\t\t\tif (properties.isVertexAi()) {\n\t\t\t\tlogger.info(\n\t\t\t\t\t\t\"Both API Key and Vertex AI config detected. Vertex AI mode is explicitly enabled; the API key will be ignored.\");\n\t\t\t}\n\t\t\telse {\n\t\t\t\tlogger.warn(\"Both API Key and Vertex AI config detected. Defaulting to Gemini Developer API (API Key). \"\n\t\t\t\t\t\t+ \"To use Vertex AI instead, set 'spring.ai.google.genai.vertex-ai=true'.\");\n\t\t\t}\n\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}","sourceCodeStart":75,"sourceCodeEnd":111,"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#L75-L111","documentation":"GoogleGenAiChatAutoConfiguration supports two modes: Gemini Developer API (api-key) and Vertex AI (project-id + location). If properties.isVertexAi() is true but both vertex project-id and location are not present, the fail-fast validation throws this IllegalStateException because the Vertex client cannot be built.","triggerScenarios":"googleGenAiClient bean method runs with spring.ai.google.genai.chat.vertex-ai=true (or equivalent) while either spring.ai.google.genai.project-id or spring.ai.google.genai.location is missing/null, so hasVertexConfig is false.","commonSituations":"Switching from Gemini API to Vertex AI by only flipping the vertex flag and forgetting to add project-id/location; properties defined under the wrong prefix; environment-variable based config where VERTEX_PROJECT is unset in the deployment environment.","solutions":["Set both spring.ai.google.genai.project-id and spring.ai.google.genai.location when vertex-ai=true.","If you intended the Gemini Developer API instead, remove vertex-ai=true and provide spring.ai.google.genai.api-key.","Verify the properties bind correctly (correct prefix, correct profiles, env vars present in the runtime environment)."],"exampleFix":"// before\nspring.ai.google.genai.chat.vertex-ai=true\n# project-id missing\n// after\nspring.ai.google.genai.chat.vertex-ai=true\nspring.ai.google.genai.project-id=my-gcp-project\nspring.ai.google.genai.location=us-central1","handlingStrategy":"validation","validationCode":"if (props.isVertexAi() && (props.getProjectId() == null || props.getLocation() == null))\n    throw new IllegalStateException(\"vertex-ai=true requires spring.ai.google.genai.project-id and .location\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["When toggling vertex-ai=true, add project-id and location in the same change.","Keep GCP settings in env vars and verify they exist in each deployment environment.","Add a startup health check that validates required spring.ai.google.genai properties."],"tags":["google-genai","vertex-ai","configuration"],"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"}