From d5de10b56c5349af19fe62d2bff607fef0101b15 Mon Sep 17 00:00:00 2001
From: Puya Daravi <puyadaravi@microsoft.com>
Date: Thu, 6 Mar 2025 03:16:15 -0800
Subject: [PATCH] Add https:// prefix to azure_endpoint when missing to avoid
 faulty URL construction where azure_endpoint is repeated twice

---
 src/openai/lib/azure.py | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/src/openai/lib/azure.py b/src/openai/lib/azure.py
index ea7bd20d99..df586375f7 100644
--- a/src/openai/lib/azure.py
+++ b/src/openai/lib/azure.py
@@ -225,6 +225,10 @@ def __init__(
             if azure_endpoint is not None:
                 raise ValueError("base_url and azure_endpoint are mutually exclusive")
 
+        # if base url does not start with https, we should add it
+        if not base_url.startswith("https://"):
+            base_url = f"https://{base_url}"
+
         if api_key is None:
             # define a sentinel value to avoid any typing issues
             api_key = API_KEY_SENTINEL
@@ -499,6 +503,10 @@ def __init__(
             if azure_endpoint is not None:
                 raise ValueError("base_url and azure_endpoint are mutually exclusive")
 
+        # if base url does not start with https, we should add it
+        if not base_url.startswith("https://"):
+            base_url = f"https://{base_url}"
+
         if api_key is None:
             # define a sentinel value to avoid any typing issues
             api_key = API_KEY_SENTINEL