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

  1. Save the full URL including scheme: https://<resource>.openai.azure.com
  2. Trim whitespace around the value when loading env
  3. Validate locally first: new URL(value) must not throw
  4. 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

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


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)