{"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":"Error","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/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/utils/AiProviders/azureOpenAi/index.js#L44-L80","documentation":"Thrown by the static `AzureOpenAiLLM.formatBaseUrl` when `new URL(azureOpenAiEndpoint)` raises — i.e. the string is not an absolute, parseable URL. formatBaseUrl normalizes the endpoint by forcing https, setting pathname to /openai/v1, and clearing query/hash; if the input cannot even be parsed as a URL, normalization is impossible and the catch rethrows a descriptive message.","triggerScenarios":"AZURE_OPENAI_ENDPOINT is truthy but malformed: missing scheme (e.g. `my-resource.openai.azure.com`), has spaces, is a relative path, or contains invalid characters. The constructor calls formatBaseUrl(process.env.AZURE_OPENAI_ENDPOINT), so this surfaces at construction time, after the key guard.","commonSituations":"User pasted just the hostname without `https://`; copied the endpoint with a trailing path/query that breaks URL parsing; trailing whitespace/newline in the env value; accidental paste of the deployment name instead of the endpoint URL.","solutions":["Set AZURE_OPENAI_ENDPOINT to a full URL including scheme: `https://<resource>.openai.azure.com` (no path, no query).","Trim any trailing whitespace, quotes, or newlines from the value in .env.","Validate it parses before deploy: `node -e \"new URL(process.env.AZURE_OPENAI_ENDPOINT)\"`.","Re-copy the endpoint from the Azure portal > resource > Keys and Endpoint to avoid transcription errors."],"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 isValidAzureEndpoint(raw) {\n  if (typeof raw !== \"string\" || raw.trim().length === 0) return false;\n  try {\n    const u = new URL(raw.trim());\n    return u.protocol === \"https:\" && /\\.openai\\.azure\\.com$/.test(u.hostname);\n  } catch {\n    return false;\n  }\n}\nif (!isValidAzureEndpoint(process.env.AZURE_OPENAI_ENDPOINT)) {\n  throw new Error(\"AZURE_OPENAI_ENDPOINT must be a valid https://*.openai.azure.com URL.\");\n}","typeGuard":"/** @param {string} raw @returns {boolean} */\nfunction isValidHttpsUrl(raw) {\n  try { return new URL(raw).protocol === \"https:\"; } catch { return false; }\n}","tryCatchPattern":"try {\n  const base = AzureOpenAiLLM.formatBaseUrl(process.env.AZURE_OPENAI_ENDPOINT);\n} catch (e) {\n  if (/is not a valid URL/.test(e.message)) {\n    return { ok: false, reason: \"bad-endpoint-url\", hint: \"Include https:// and the .openai.azure.com host.\" };\n  }\n  throw e;\n}","preventionTips":["Validate the endpoint URL at config-save time, not at first request.","Always include the https:// scheme in stored values.","Trim whitespace and strip quotes when reading endpoint env vars.","Unit-test formatBaseUrl against scheme-less, query-laden, and host-only inputs."],"tags":["config","url-validation","azure","constructor"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}