{"record":{"id":"2f040cbd7530dc69","repo":"spring-projects/spring-ai","slug":"base-url-must-be-provided-for-microsoft-foundry","errorCode":null,"errorMessage":"Base URL must be provided for Microsoft Foundry.","messagePattern":"Base URL must be provided for Microsoft Foundry\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"models/spring-ai-openai/src/main/java/org/springframework/ai/openai/setup/OpenAiSetup.java","lineNumber":325,"sourceCode":"\t\tif (modelProvider == ModelProvider.OPEN_AI) {\n\t\t\tif (baseUrl == null || baseUrl.isBlank()) {\n\t\t\t\treturn OPENAI_URL;\n\t\t\t}\n\t\t\treturn baseUrl;\n\t\t}\n\t\telse if (modelProvider == ModelProvider.GITHUB_MODELS) {\n\t\t\tif (baseUrl == null || baseUrl.isBlank()) {\n\t\t\t\treturn GITHUB_MODELS_URL;\n\t\t\t}\n\t\t\tif (baseUrl.startsWith(GITHUB_MODELS_URL)) {\n\t\t\t\t// To support GitHub Models for specific orgs\n\t\t\t\treturn baseUrl;\n\t\t\t}\n\t\t\treturn GITHUB_MODELS_URL;\n\t\t}\n\t\telse if (modelProvider == ModelProvider.MICROSOFT_FOUNDRY) {\n\t\t\tif (baseUrl == null || baseUrl.isBlank()) {\n\t\t\t\tthrow new IllegalArgumentException(\"Base URL must be provided for Microsoft Foundry.\");\n\t\t\t}\n\t\t\tString tmpUrl = baseUrl;\n\t\t\tif (baseUrl.endsWith(\"/\") || baseUrl.endsWith(\"?\")) {\n\t\t\t\ttmpUrl = baseUrl.substring(0, baseUrl.length() - 1);\n\t\t\t}\n\t\t\treturn tmpUrl;\n\t\t}\n\t\telse {\n\t\t\tthrow new IllegalArgumentException(\"Unknown model provider: \" + modelProvider);\n\t\t}\n\t}\n\n\tstatic Credential azureAuthentication() {\n\t\ttry {\n\t\t\treturn AzureInternalOpenAiHelper.getAzureCredential();\n\t\t}\n\t\tcatch (NoClassDefFoundError e) {\n\t\t\tthrow new IllegalArgumentException(\"Microsoft Foundry was detected, but no credential was provided. \"","sourceCodeStart":307,"sourceCodeEnd":343,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/models/spring-ai-openai/src/main/java/org/springframework/ai/openai/setup/OpenAiSetup.java#L307-L343","documentation":"OpenAiSetup.calculateBaseUrl validates that a base URL is present when the configured ModelProvider is MICROSOFT_FOUNDRY. Unlike GitHub Models or OpenAI, a Microsoft Foundry deployment has no default endpoint, so the library requires an explicit base URL (the Foundry resource endpoint). It throws IllegalArgumentException to fail fast during client setup rather than producing an unresolvable endpoint later.","triggerScenarios":"Setting spring.ai.openai... model-provider to MICROSOFT_FOUNDRY (or calling OpenAiSetup/calculatedBaseUrl with ModelProvider.MICROSOFT_FOUNDRY) while leaving the base URL property null, empty, or whitespace-only.","commonSituations":"Developers switch from OpenAI to Microsoft Foundry via properties but forget to set the base-url; the base-url is read from an environment variable that is unset; trailing config refactoring removed the URL; YAML/properties key typo means baseUrl resolves to null.","solutions":["Set the Microsoft Foundry base URL (e.g. https://<resource-name>.services.ai.azure.com) in the OpenAI chat/embedding base-url property or OpenAiApi builder.","If using an env var for the URL, verify it is exported and spelled correctly before starting the app.","If you did not intend to use Microsoft Foundry, correct the model-provider setting back to OPEN_AI or GITHUB_MODELS."],"exampleFix":"// before\nOpenAiApi.builder().modelProvider(ModelProvider.MICROSOFT_FOUNDRY).build();\n// after\nOpenAiApi.builder()\n    .modelProvider(ModelProvider.MICROSOFT_FOUNDRY)\n    .baseUrl(\"https://<resource-name>.services.ai.azure.com\")\n    .build();","handlingStrategy":"validation","validationCode":"if (modelProvider == ModelProvider.MICROSOFT_FOUNDRY && (baseUrl == null || baseUrl.isBlank())) {\n    throw new IllegalStateException(\"base-url must be set when using Microsoft Foundry\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pair MICROSOFT_FOUNDRY with an explicit base-url in configuration.","Use Assert.hasText in @ConfigurationProperties setters to fail at binding time.","Write an application-startup smoke test that builds the OpenAiApi bean."],"tags":["configuration","azure","missing-value"],"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-14T05:17:10.506Z"}