{"record":{"id":"38389311b766886b","repo":"spring-projects/spring-ai","slug":"both-api-key-and-vertex-ai-config-detected-defaul","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/chat/GoogleGenAiChatAutoConfiguration.java","lineNumber":85,"sourceCode":"\n\t@Bean\n\t@ConditionalOnMissingBean\n\tpublic Client googleGenAiClient(GoogleGenAiConnectionProperties properties) throws IOException {\n\t\tClient.Builder builder = Client.builder();\n\n\t\tboolean hasApiKey = StringUtils.hasText(properties.getApiKey());\n\t\tboolean hasProject = StringUtils.hasText(properties.getProjectId());\n\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);","sourceCodeStart":67,"sourceCodeEnd":103,"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#L67-L103","documentation":"Spring AI's Google GenAI chat auto-configuration detected credentials for both the Gemini Developer API (API key) and Vertex AI in the configuration. Since both are present, the library defaults to the Gemini Developer API (API key) mode and warns that Vertex AI will not be used unless spring.ai.google.genai.vertex-ai=true is explicitly set.","triggerScenarios":"Both an API key (e.g. spring.ai.google.genai.api-key or GOOGLE_API_KEY/GEMINI_API_KEY env var) and Vertex AI config (project id/location and OAuth credentials) are present while spring.ai.google.genai.vertex-ai is false or unset, when googleGenAiClient bean is created.","commonSituations":"GOOGLE_API_KEY or GEMINI_API_KEY set in the environment on GCP machines where ADC (Application Default Credentials) are also configured; copying example properties that include both options; migrating between the two APIs without removing the old credential.","solutions":["Set spring.ai.google.genai.vertex-ai=true if Vertex AI is the intended backend.","Remove spring.ai.google.genai.api-key (and GOOGLE_API_KEY/GEMINI_API_KEY env vars) if Vertex AI should be used implicitly.","Remove the Vertex AI project/location config if the Developer API with an API key is intended.","Set spring.ai.google.genai.api-key explicitly (not via environment) to make intent unambiguous."],"exampleFix":"// before (ambiguous: both credentials present)\nspring.ai.google.genai.api-key=${GEMINI_API_KEY}\nspring.ai.google.genai.project-id=my-gcp-project\n// after (explicit Vertex AI mode)\nspring.ai.google.genai.vertex-ai=true\nspring.ai.google.genai.project-id=my-gcp-project\n# api-key removed","handlingStrategy":"validation","validationCode":"boolean hasApiKey = env.containsProperty(\"spring.ai.google.genai.api-key\") || env.getProperty(\"GOOGLE_API_KEY\") != null;\nboolean hasVertex = env.containsProperty(\"spring.ai.google.genai.project-id\");\nif (hasApiKey && hasVertex && !env.getProperty(\"spring.ai.google.genai.vertex-ai\", Boolean.class, false)) {\n    throw new IllegalStateException(\"Provide only one GenAI credential mode or set vertex-ai=true\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep only one credential mode per Spring profile.","Unset GOOGLE_API_KEY/GEMINI_API_KEY on GCP hosts using ADC.","Always set spring.ai.google.genai.vertex-ai explicitly.","Add a config test that asserts exactly one GenAI mode is configured."],"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"}