Mintplex-Labs/anything-llm · error
" " is not a valid URL. Check your settings for the Azure…
Error message
"${azureOpenAiEndpoint}" is not a valid URL. Check your settings for the Azure OpenAI provider and set a valid endpoint URL. What it means
formatBaseUrl runs new URL(azureOpenAiEndpoint) and converts any parse failure into this error. The normalizer then force-sets protocol https, path /openai/v1, and strips query/hash - so only the scheme + host matter, but the string must still be parseable: a missing scheme, spaces, control characters, or an empty value throw. The input comes from AZURE_OPENAI_ENDPOINT or the provider settings field.
Solutions
- Save the full URL including scheme: https://<resource>.openai.azure.com
- Trim whitespace around the value when loading env
- Validate locally first: new URL(value) must not throw
- Do not append paths, api-version query strings, or keys - formatBaseUrl replaces them
Example fix
# before AZURE_OPENAI_ENDPOINT=my-resource.openai.azure.com # after AZURE_OPENAI_ENDPOINT=https://my-resource.openai.azure.com
Defensive patterns
Strategy: validation
Validate before calling
function isValidEndpointUrl(value) {
try {
const u = new URL(String(value).trim());
return u.protocol === "http:" || u.protocol === "https:";
} catch {
return false;
}
}
if (!isValidEndpointUrl(process.env.AZURE_OPENAI_ENDPOINT)) {
return res.status(400).json({ error: "Endpoint must be a full URL like https://<resource>.openai.azure.com" });
} Try / catch
try {
AzureOpenAiLLM.formatBaseUrl(endpoint);
} catch (e) {
if (/not a valid URL/i.test(e.message)) {
return res.status(400).json({ error: "Fix the endpoint URL format in settings" });
}
throw e;
} Prevention
- Always include the https:// scheme in the endpoint
- Trim env values when loading configuration
- Pre-validate with new URL() in config loaders to fail fast at startup
When it happens
Trigger: Endpoint saved without a scheme ("my-resource.openai.azure.com"); leading/trailing whitespace or newlines from copy-paste; "https//host" missing the colon; template variables injecting empty strings; YAML folded scalars introducing trailing spaces.
Common situations: Copying the resource host from the Azure portal without the scheme; Infrastructure-as-Management templates with optional values left empty; secrets/env pipelines mangling whitespace; localhost-style endpoints getting silently rewritten to https.
Related errors
- No Azure API endpoint was set.
- No Azure API key was set.
- No valid updates provided.
- addToWorkspaces must be a string of comma-separated…
- ApiPie chat: is not valid for chat completion!
AI-assisted analysis of Mintplex-Labs/anything-llm@3aec848f28 (2026-08-18).
Data as JSON: /api/errors/48e95d7ea4925a98.
Report an issue: GitHub.
Appendix: source
Thrown at server/utils/AiProviders/azureOpenAi/index.js:62
`Initialized. Model "${this.model}" @ ${this.promptWindowLimit()} tokens.\nAPI-Version: ${this.apiVersion}.\nModel Type: ${this.isOTypeModel ? "reasoning" : "default"}`
);
}
/**
* Formats the Azure OpenAI endpoint URL to the correct format.
* @param {string} azureOpenAiEndpoint - The Azure OpenAI endpoint URL.
* @returns {string} The formatted URL.
*/
static formatBaseUrl(azureOpenAiEndpoint) {
try {
const url = new URL(azureOpenAiEndpoint);
url.pathname = "/openai/v1";
url.protocol = "https";
url.search = "";
url.hash = "";
return url.href;
} catch {
throw new Error(
`"${azureOpenAiEndpoint}" is not a valid URL. Check your settings for the Azure OpenAI provider and set a valid endpoint URL.`
);
}
}
#log(text, ...args) {
console.log(`\x1b[32m[AzureOpenAi]\x1b[0m ${text}`, ...args);
}
#appendContext(contextTexts = []) {
if (!contextTexts || !contextTexts.length) return "";
return (
"\nContext:\n" +
contextTexts
.map((text, i) => {
return `[CONTEXT ${i}]:\n${text}\n[END CONTEXT ${i}]\n\n`;
})
.join("")View on GitHub (pinned to 3aec848f28)