{"record":{"id":"b59cad3f47675802","repo":"spring-projects/spring-ai","slug":"microsoft-foundry-was-detected-but-no-credential","errorCode":null,"errorMessage":"Microsoft Foundry was detected, but no credential was provided. If you want to use passwordless authentication, you need to add the Azure Identity library (groupId=`com.azure`, artifactId=`azure-identity`) to your classpath.","messagePattern":"Microsoft Foundry was detected, but no credential was provided\\. If you want to use passwordless authentication, you need to add the Azure Identity library \\(groupId=`com\\.azure`, artifactId=`azure-identity`\\) to your classpath\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"models/spring-ai-openai/src/main/java/org/springframework/ai/openai/setup/OpenAiSetup.java","lineNumber":343,"sourceCode":"\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. \"\n\t\t\t\t\t+ \"If you want to use passwordless authentication, you need to add the Azure Identity library (groupId=`com.azure`, artifactId=`azure-identity`) to your classpath.\");\n\t\t}\n\t}\n\n\tstatic @Nullable String detectApiKey(ModelProvider modelProvider) {\n\t\tif (modelProvider == ModelProvider.OPEN_AI && System.getenv(OPENAI_API_KEY) != null) {\n\t\t\treturn System.getenv(OPENAI_API_KEY);\n\t\t}\n\t\telse if (modelProvider == ModelProvider.MICROSOFT_FOUNDRY && System.getenv(MICROSOFT_FOUNDRY_API_KEY) != null) {\n\t\t\treturn System.getenv(MICROSOFT_FOUNDRY_API_KEY);\n\t\t}\n\t\telse if (modelProvider == ModelProvider.MICROSOFT_FOUNDRY && System.getenv(OPENAI_API_KEY) != null) {\n\t\t\treturn System.getenv(OPENAI_API_KEY);\n\t\t}\n\t\telse if (modelProvider == ModelProvider.GITHUB_MODELS && System.getenv(GITHUB_TOKEN) != null) {\n\t\t\treturn System.getenv(GITHUB_TOKEN);\n\t\t}\n\t\treturn null;","sourceCodeStart":325,"sourceCodeEnd":361,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/models/spring-ai-openai/src/main/java/org/springframework/ai/openai/setup/OpenAiSetup.java#L325-L361","documentation":"azureAuthentication calls AzureInternalOpenAiHelper.getAzureCredential(), which requires the Azure Identity library on the classpath for passwordless (DefaultAzureCredential) authentication. When the JVM raises NoClassDefFoundError because azure-identity is absent, it is rethrown as an IllegalArgumentException explaining that Microsoft Foundry was detected but no credential is available.","triggerScenarios":"Configuring ModelProvider.MICROSOFT_FOUNDRY and calling azureAuthentication (via buildClientOptions) when com.azure:azure-identity is not on the runtime classpath and no explicit API key/credential is supplied.","commonSituations":"Using the light spring-ai starter that does not transitively pull azure-identity; a dependency-exclusion removed azure-identity; running a fat jar that omitted the optional dependency; expecting passwordless auth in production without adding the library.","solutions":["Add the dependency com.azure:azure-identity to your build (e.g. implementation 'com.azure:azure-identity:1.x').","Alternatively provide an explicit API key / credential so passwordless DefaultAzureCredential resolution is not attempted.","Verify the packaged artifact (fat jar/container image) actually includes azure-identity classes."],"exampleFix":"// before (Gradle)\ndependencies { implementation 'org.springframework.ai:spring-ai-openai' }\n// after\ndependencies {\n    implementation 'org.springframework.ai:spring-ai-openai'\n    implementation 'com.azure:azure-identity:1.15.0'\n}","handlingStrategy":"validation","validationCode":"try {\n    Class.forName(\"com.azure.identity.DefaultAzureCredential\");\n} catch (ClassNotFoundException e) {\n    throw new IllegalStateException(\"Add com.azure:azure-identity for Microsoft Foundry passwordless auth\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    client = buildClient();\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"azure-identity\")) {\n        throw new IllegalStateException(\"Missing azure-identity dependency or explicit credential\", e);\n    }\n    throw e;\n}","preventionTips":["Add com.azure:azure-identity whenever Microsoft Foundry is targeted.","Or configure an explicit API key so credential resolution is deterministic.","Verify runtime classpath in fat jars/containers includes azure-identity."],"tags":["azure","authentication","classpath","dependency"],"backgroundTag":"missing-dependency","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"}