{"record":{"id":"48e95d7ea4925a98","repo":"Mintplex-Labs/anything-llm","slug":"azureopenaiendpoint-is-not-a-valid-url-check","errorCode":null,"errorMessage":"\"${azureOpenAiEndpoint}\" is not a valid URL. Check your settings for the Azure OpenAI provider and set a valid endpoint URL.","messagePattern":"\"(.+?)\" is not a valid URL\\. Check your settings for the Azure OpenAI provider and set a valid endpoint URL\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/utils/AiProviders/azureOpenAi/index.js","lineNumber":62,"sourceCode":"      `Initialized. Model \"${this.model}\" @ ${this.promptWindowLimit()} tokens.\\nAPI-Version: ${this.apiVersion}.\\nModel Type: ${this.isOTypeModel ? \"reasoning\" : \"default\"}`\n    );\n  }\n\n  /**\n   * Formats the Azure OpenAI endpoint URL to the correct format.\n   * @param {string} azureOpenAiEndpoint - The Azure OpenAI endpoint URL.\n   * @returns {string} The formatted URL.\n   */\n  static formatBaseUrl(azureOpenAiEndpoint) {\n    try {\n      const url = new URL(azureOpenAiEndpoint);\n      url.pathname = \"/openai/v1\";\n      url.protocol = \"https\";\n      url.search = \"\";\n      url.hash = \"\";\n      return url.href;\n    } catch {\n      throw new Error(\n        `\"${azureOpenAiEndpoint}\" is not a valid URL. Check your settings for the Azure OpenAI provider and set a valid endpoint URL.`\n      );\n    }\n  }\n\n  #log(text, ...args) {\n    console.log(`\\x1b[32m[AzureOpenAi]\\x1b[0m ${text}`, ...args);\n  }\n\n  #appendContext(contextTexts = []) {\n    if (!contextTexts || !contextTexts.length) return \"\";\n    return (\n      \"\\nContext:\\n\" +\n      contextTexts\n        .map((text, i) => {\n          return `[CONTEXT ${i}]:\\n${text}\\n[END CONTEXT ${i}]\\n\\n`;\n        })\n        .join(\"\")","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/3aec848f2885144aa8f1e53b9731a04310d5d558/server/utils/AiProviders/azureOpenAi/index.js#L44-L80","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"# before\nAZURE_OPENAI_ENDPOINT=my-resource.openai.azure.com\n\n# after\nAZURE_OPENAI_ENDPOINT=https://my-resource.openai.azure.com","handlingStrategy":"validation","validationCode":"function isValidEndpointUrl(value) {\n  try {\n    const u = new URL(String(value).trim());\n    return u.protocol === \"http:\" || u.protocol === \"https:\";\n  } catch {\n    return false;\n  }\n}\nif (!isValidEndpointUrl(process.env.AZURE_OPENAI_ENDPOINT)) {\n  return res.status(400).json({ error: \"Endpoint must be a full URL like https://<resource>.openai.azure.com\" });\n}","typeGuard":null,"tryCatchPattern":"try {\n  AzureOpenAiLLM.formatBaseUrl(endpoint);\n} catch (e) {\n  if (/not a valid URL/i.test(e.message)) {\n    return res.status(400).json({ error: \"Fix the endpoint URL format in settings\" });\n  }\n  throw e;\n}","preventionTips":["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"],"tags":["azure-openai","url","validation","configuration"],"backgroundTag":"invalid-endpoint-url","analyzedSha":"3aec848f2885144aa8f1e53b9731a04310d5d558","analyzedAt":"2026-08-18T10:02:21.017Z","contentChangedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}