{"record":{"id":"393d5866269c1e64","repo":"spring-projects/spring-ai","slug":"vertex-ai-mode-requires-both-project-id-and-loc-393d58","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/image/GoogleGenAiImageConnectionAutoConfiguration.java","lineNumber":75,"sourceCode":"\t\tboolean hasLocation = StringUtils.hasText(connectionProperties.getLocation());\n\t\tboolean hasVertexConfig = hasProject && hasLocation;\n\n\t\t// Ambiguity Guard: Professional logging\n\t\tif (hasApiKey && hasVertexConfig) {\n\t\t\tif (connectionProperties.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 (connectionProperties.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(connectionBuilder, connectionProperties);\n\t\t}\n\t\telse if (hasApiKey) {\n\t\t\tconnectionBuilder.apiKey(connectionProperties.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(connectionBuilder, connectionProperties);\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 connectionBuilder.build();\n\t}","sourceCodeStart":57,"sourceCodeEnd":93,"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/image/GoogleGenAiImageConnectionAutoConfiguration.java#L57-L93","documentation":"The Google GenAI image connection auto-configuration applies the same fail-fast mode validation as the chat one: if vertex-ai mode is enabled for the image connection but either project-id or location is missing, googleGenAiImageConnectionDetails throws this IllegalStateException because a Vertex AI client cannot be constructed.","triggerScenarios":"googleGenAiImageConnectionDetails bean method runs with connectionProperties.isVertexAi() true while spring.ai.google.genai.image (or its connection properties) lacks a non-null project-id or location, so hasVertexConfig is false.","commonSituations":"Enabling vertex-ai on the image properties after previously using api-key, without adding project-id/location; image-specific properties being overridden by a profile that drops the Vertex settings; Kubernetes config missing the GCP project/location env values.","solutions":["Set both project-id and location in the image connection properties (spring.ai.google.genai.image.project-id / .location).","If Vertex AI was not intended, disable vertex-ai and supply spring.ai.google.genai.image.api-key instead.","Confirm the active Spring profile / environment actually carries the Vertex properties at deploy time."],"exampleFix":"// before\nspring.ai.google.genai.image.vertex-ai=true\n# location missing\n// after\nspring.ai.google.genai.image.vertex-ai=true\nspring.ai.google.genai.image.project-id=my-gcp-project\nspring.ai.google.genai.image.location=us-central1","handlingStrategy":"validation","validationCode":"if (imageProps.isVertexAi() && (imageProps.getProjectId() == null || imageProps.getLocation() == null))\n    throw new IllegalStateException(\"image vertex-ai=true requires project-id and location\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Mirror chat Vertex settings (project-id, location) in the image properties when enabling vertex-ai there.","Verify per-feature property overrides in profiles don't drop required Vertex keys.","Document required GCP properties for each GenAI module in your team runbook."],"tags":["google-genai","vertex-ai","image","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"}