{"record":{"id":"4ae1a7755e6f62d8","repo":"spring-projects/spring-ai","slug":"both-api-key-and-vertex-ai-config-detected-defaul-4ae1a7","errorCode":null,"errorMessage":"Both API Key and Vertex AI config detected. Defaulting to Gemini Developer API (API Key). To use Vertex AI instead, set 'spring.ai.google.genai.vertex-ai=true'.","messagePattern":"Both API Key and Vertex AI config detected\\. Defaulting to Gemini Developer API \\(API Key\\)\\. To use Vertex AI instead, set 'spring\\.ai\\.google\\.genai\\.vertex-ai=true'\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"auto-configurations/models/spring-ai-autoconfigure-model-google-genai/src/main/java/org/springframework/ai/model/google/genai/autoconfigure/image/GoogleGenAiImageConnectionAutoConfiguration.java","lineNumber":67,"sourceCode":"\t@ConditionalOnMissingBean\n\tpublic GoogleGenAiImageConnectionDetails googleGenAiImageConnectionDetails(\n\t\t\tGoogleGenAiImageConnectionProperties connectionProperties) throws IOException {\n\n\t\tvar connectionBuilder = GoogleGenAiImageConnectionDetails.builder();\n\n\t\tboolean hasApiKey = StringUtils.hasText(connectionProperties.getApiKey());\n\t\tboolean hasProject = StringUtils.hasText(connectionProperties.getProjectId());\n\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);","sourceCodeStart":49,"sourceCodeEnd":85,"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#L49-L85","documentation":"Same ambiguity as the chat variant but raised by the Google GenAI image connection auto-configuration: both an API key and Vertex AI configuration are detected, so the connection defaults to the Gemini Developer API (API key) and warns how to switch to Vertex AI.","triggerScenarios":"Both spring.ai.google.genai.image (or shared) api-key and Vertex AI project/location credentials are present while spring.ai.google.genai.image.vertex-ai (vertex-ai property) is false/unset, when the googleGenAiImageConnectionDetails bean is created.","commonSituations":"GOOGLE_API_KEY/GEMINI_API_KEY present in the environment on a GCP VM with ADC; shared GenAI properties carrying credentials for both backends; switching image generation from Developer API to Vertex AI without deleting the API key.","solutions":["Set the vertex-ai property to true to explicitly select Vertex AI for image generation.","Remove the API key property/env var if Vertex AI credentials should be used.","Remove Vertex AI project/location settings if the Developer API is intended.","Keep only one credential source per profile to avoid ambiguity."],"exampleFix":"// before (image config, ambiguous)\nspring.ai.google.genai.image.api-key=${GOOGLE_API_KEY}\nspring.ai.google.genai.image.project-id=my-gcp-project\n// after (explicit Developer API mode)\nspring.ai.google.genai.image.api-key=${GOOGLE_API_KEY}\n# remove project-id/location, or set vertex-ai=true to use Vertex AI","handlingStrategy":"validation","validationCode":"boolean hasApiKey = env.containsProperty(\"spring.ai.google.genai.image.api-key\");\nboolean hasVertex = env.containsProperty(\"spring.ai.google.genai.image.project-id\");\nif (hasApiKey && hasVertex && !env.getProperty(\"spring.ai.google.genai.image.vertex-ai\", Boolean.class, false)) {\n    throw new IllegalStateException(\"Image GenAI config is ambiguous: pick API key or Vertex AI explicitly\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Configure image GenAI credentials in a single, mode-specific property block.","Do not rely on inherited environment credentials when switching modes.","Set the vertex-ai flag explicitly in every profile using Vertex AI.","Smoke-test image generation at startup to verify the intended backend is selected."],"tags":["configuration","google-genai","credentials","ambiguity"],"backgroundTag":"conflicting-config-options","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"}