{"id":682,"date":"2026-04-08T09:31:56","date_gmt":"2026-04-08T01:31:56","guid":{"rendered":"https:\/\/connectword.dpdns.org\/?p=682"},"modified":"2026-04-08T09:31:56","modified_gmt":"2026-04-08T01:31:56","slug":"how-to-deploy-open-webui-with-secure-openai-api-integration-public-tunneling-and-browser-based-chat-access","status":"publish","type":"post","link":"https:\/\/connectword.dpdns.org\/?p=682","title":{"rendered":"How to Deploy Open WebUI with Secure OpenAI API Integration, Public Tunneling, and Browser-Based Chat Access"},"content":{"rendered":"<p>In this tutorial, we build a complete<strong> <\/strong><a href=\"https:\/\/github.com\/open-webui\/open-webui\"><strong>Open WebUI<\/strong><\/a> setup in Colab, in a practical, hands-on way, using Python. We begin by installing the required dependencies, then securely provide our OpenAI API key through terminal-based secret input so that sensitive credentials are not exposed directly in the notebook. From there, we configure the environment variables needed for Open WebUI to communicate with the OpenAI API, define a default model, prepare a data directory for runtime storage, and launch the Open WebUI server inside the Colab environment. To make the interface accessible outside the notebook, we also create a public tunnel and capture a shareable URL that lets us open and use the application directly in the browser. Through this process, we get Open WebUI running end-to-end and understand how the key pieces of deployment, configuration, access, and runtime management fit together in a Colab-based workflow.<\/p>\n<div class=\"dm-code-snippet dark dm-normal-version default no-background-mobile\">\n<div class=\"control-language\">\n<div class=\"dm-buttons\">\n<div class=\"dm-buttons-left\">\n<div class=\"dm-button-snippet red-button\"><\/div>\n<div class=\"dm-button-snippet orange-button\"><\/div>\n<div class=\"dm-button-snippet green-button\"><\/div>\n<\/div>\n<div class=\"dm-buttons-right\"><a><span class=\"dm-copy-text\">Copy Code<\/span><span class=\"dm-copy-confirmed\">Copied<\/span><span class=\"dm-error-message\">Use a different Browser<\/span><\/a><\/div>\n<\/div>\n<pre class=\" no-line-numbers\"><code class=\" no-wrap language-php\">import os\nimport re\nimport time\nimport json\nimport shutil\nimport signal\nimport secrets\nimport subprocess\nimport urllib.request\nfrom getpass import getpass\nfrom pathlib import Path\n\n\nprint(\"Installing Open WebUI and helper packages...\")\nsubprocess.check_call([\n   \"python\", \"-m\", \"pip\", \"install\", \"-q\",\n   \"open-webui\",\n   \"requests\",\n   \"nest_asyncio\"\n])\n\n\nprint(\"nEnter your OpenAI API key securely.\")\nopenai_api_key = getpass(\"OpenAI API Key: \").strip()\n\n\nif not openai_api_key:\n   raise ValueError(\"OpenAI API key cannot be empty.\")\n\n\ndefault_model = input(\"Default model to use inside Open WebUI [gpt-4o-mini]: \").strip()\nif not default_model:\n   default_model = \"gpt-4o-mini\"<\/code><\/pre>\n<\/div>\n<\/div>\n<p>We begin by importing all the required Python modules for managing system operations, securing input, handling file paths, running subprocesses, and accessing the network. We then install Open WebUI and the supporting packages needed to run the application smoothly inside Google Colab. After that, we securely enter our OpenAI API key through terminal input and define the default model that we want Open WebUI to use.<\/p>\n<div class=\"dm-code-snippet dark dm-normal-version default no-background-mobile\">\n<div class=\"control-language\">\n<div class=\"dm-buttons\">\n<div class=\"dm-buttons-left\">\n<div class=\"dm-button-snippet red-button\"><\/div>\n<div class=\"dm-button-snippet orange-button\"><\/div>\n<div class=\"dm-button-snippet green-button\"><\/div>\n<\/div>\n<div class=\"dm-buttons-right\"><a><span class=\"dm-copy-text\">Copy Code<\/span><span class=\"dm-copy-confirmed\">Copied<\/span><span class=\"dm-error-message\">Use a different Browser<\/span><\/a><\/div>\n<\/div>\n<pre class=\" no-line-numbers\"><code class=\" no-wrap language-php\">os.environ[\"ENABLE_OPENAI_API\"] = \"True\"\nos.environ[\"OPENAI_API_KEY\"] = openai_api_key\nos.environ[\"OPENAI_API_BASE_URL\"] = \"https:\/\/api.openai.com\/v1\"\nos.environ[\"WEBUI_SECRET_KEY\"] = secrets.token_hex(32)\nos.environ[\"WEBUI_NAME\"] = \"Open WebUI on Colab\"\nos.environ[\"DEFAULT_MODELS\"] = default_model\n\n\ndata_dir = Path(\"\/content\/open-webui-data\")\ndata_dir.mkdir(parents=True, exist_ok=True)\nos.environ[\"DATA_DIR\"] = str(data_dir)\n<\/code><\/pre>\n<\/div>\n<\/div>\n<p>We configure the environment variables that allow Open WebUI to connect properly with the OpenAI API. We store the API key, define the OpenAI base endpoint, generate a secret key for the web interface, and assign a default model and interface name for the session. We also create a dedicated data directory in the Colab environment so that Open WebUI has a structured location to store its runtime data.<\/p>\n<div class=\"dm-code-snippet dark dm-normal-version default no-background-mobile\">\n<div class=\"control-language\">\n<div class=\"dm-buttons\">\n<div class=\"dm-buttons-left\">\n<div class=\"dm-button-snippet red-button\"><\/div>\n<div class=\"dm-button-snippet orange-button\"><\/div>\n<div class=\"dm-button-snippet green-button\"><\/div>\n<\/div>\n<div class=\"dm-buttons-right\"><a><span class=\"dm-copy-text\">Copy Code<\/span><span class=\"dm-copy-confirmed\">Copied<\/span><span class=\"dm-error-message\">Use a different Browser<\/span><\/a><\/div>\n<\/div>\n<pre class=\" no-line-numbers\"><code class=\" no-wrap language-php\">cloudflared_path = Path(\"\/content\/cloudflared\")\nif not cloudflared_path.exists():\n   print(\"nDownloading cloudflared...\")\n   url = \"https:\/\/github.com\/cloudflare\/cloudflared\/releases\/latest\/download\/cloudflared-linux-amd64\"\n   urllib.request.urlretrieve(url, cloudflared_path)\n   cloudflared_path.chmod(0o755)\n\n\nprint(\"nStarting Open WebUI server...\")\n\n\nserver_log = open(\"\/content\/open-webui-server.log\", \"w\")\nserver_proc = subprocess.Popen(\n   [\"open-webui\", \"serve\"],\n   stdout=server_log,\n   stderr=subprocess.STDOUT,\n   env=os.environ.copy()\n)\n<\/code><\/pre>\n<\/div>\n<\/div>\n<p>We prepare the tunnel component by downloading the CloudFlare binary if it is not already available in the Colab environment. Once that is ready, we start the Open WebUI server and direct its output into a log file so that we can inspect its behavior if needed. This part of the tutorial sets up the core application process that powers the browser-based interface.<\/p>\n<div class=\"dm-code-snippet dark dm-normal-version default no-background-mobile\">\n<div class=\"control-language\">\n<div class=\"dm-buttons\">\n<div class=\"dm-buttons-left\">\n<div class=\"dm-button-snippet red-button\"><\/div>\n<div class=\"dm-button-snippet orange-button\"><\/div>\n<div class=\"dm-button-snippet green-button\"><\/div>\n<\/div>\n<div class=\"dm-buttons-right\"><a><span class=\"dm-copy-text\">Copy Code<\/span><span class=\"dm-copy-confirmed\">Copied<\/span><span class=\"dm-error-message\">Use a different Browser<\/span><\/a><\/div>\n<\/div>\n<pre class=\" no-line-numbers\"><code class=\" no-wrap language-php\">local_url = \"http:\/\/127.0.0.1:8080\"\nready = False\nfor _ in range(120):\n   try:\n       import requests\n       r = requests.get(local_url, timeout=2)\n       if r.status_code &lt; 500:\n           ready = True\n           break\n   except Exception:\n       pass\n   time.sleep(2)\n\n\nif not ready:\n   server_log.close()\n   with open(\"\/content\/open-webui-server.log\", \"r\") as f:\n       logs = f.read()[-4000:]\n   raise RuntimeError(\n       \"Open WebUI did not start successfully.nn\"\n       \"Recent logs:n\"\n       f\"{logs}\"\n   )\n\n\nprint(\"Open WebUI is running locally at:\", local_url)\n\n\nprint(\"nCreating public tunnel...\")\n\n\ntunnel_proc = subprocess.Popen(\n   [str(cloudflared_path), \"tunnel\", \"--url\", local_url, \"--no-autoupdate\"],\n   stdout=subprocess.PIPE,\n   stderr=subprocess.STDOUT,\n   text=True\n)\n<\/code><\/pre>\n<\/div>\n<\/div>\n<p>We repeatedly check whether the Open WebUI server has started successfully on the local Colab port. If the server does not start properly, we read the recent logs and raise a clear error so that we can understand what went wrong. Once the server is confirmed to be running, we create a public tunnel to make the local interface accessible from outside Colab.<\/p>\n<div class=\"dm-code-snippet dark dm-normal-version default no-background-mobile\">\n<div class=\"control-language\">\n<div class=\"dm-buttons\">\n<div class=\"dm-buttons-left\">\n<div class=\"dm-button-snippet red-button\"><\/div>\n<div class=\"dm-button-snippet orange-button\"><\/div>\n<div class=\"dm-button-snippet green-button\"><\/div>\n<\/div>\n<div class=\"dm-buttons-right\"><a><span class=\"dm-copy-text\">Copy Code<\/span><span class=\"dm-copy-confirmed\">Copied<\/span><span class=\"dm-error-message\">Use a different Browser<\/span><\/a><\/div>\n<\/div>\n<pre class=\" no-line-numbers\"><code class=\" no-wrap language-php\">public_url = None\nstart_time = time.time()\nwhile time.time() - start_time &lt; 90:\n   line = tunnel_proc.stdout.readline()\n   if not line:\n       time.sleep(1)\n       continue\n   match = re.search(r\"https:\/\/[-a-zA-Z0-9]+.trycloudflare.com\", line)\n   if match:\n       public_url = match.group(0)\n       break\n\n\nif not public_url:\n   with open(\"\/content\/open-webui-server.log\", \"r\") as f:\n       server_logs = f.read()[-3000:]\n   raise RuntimeError(\n       \"Tunnel started but no public URL was captured.nn\"\n       \"Open WebUI server logs:n\"\n       f\"{server_logs}\"\n   )\n\n\nprint(\"n\" + \"=\" * 80)\nprint(\"Open WebUI is ready.\")\nprint(\"Public URL:\", public_url)\nprint(\"Local URL :\", local_url)\nprint(\"=\" * 80)\n\n\nprint(\"nWhat to do next:\")\nprint(\"1. Open the Public URL.\")\nprint(\"2. Create your admin account the first time you open it.\")\nprint(\"3. Go to the model selector and choose:\", default_model)\nprint(\"4. Start chatting with OpenAI through Open WebUI.\")\n\n\nprint(\"nUseful notes:\")\nprint(\"- Your OpenAI API key was passed through environment variables.\")\nprint(\"- Data persists only for the current Colab runtime unless you mount Drive.\")\nprint(\"- If the tunnel stops, rerun the cell.\")\n\n\ndef tail_open_webui_logs(lines=80):\n   log_path = \"\/content\/open-webui-server.log\"\n   if not os.path.exists(log_path):\n       print(\"No server log found.\")\n       return\n   with open(log_path, \"r\") as f:\n       content = f.readlines()\n   print(\"\".join(content[-lines:]))\n\n\ndef stop_open_webui():\n   global server_proc, tunnel_proc, server_log\n   for proc in [tunnel_proc, server_proc]:\n       try:\n           if proc and proc.poll() is None:\n               proc.terminate()\n       except Exception:\n           pass\n   try:\n       server_log.close()\n   except Exception:\n       pass\n   print(\"Stopped Open WebUI and tunnel.\")\n\n\nprint(\"nHelpers available:\")\nprint(\"- tail_open_webui_logs()\")\nprint(\"- stop_open_webui()\")<\/code><\/pre>\n<\/div>\n<\/div>\n<p>We capture the public tunnel URL and print the final access details so that we can open Open WebUI directly in the browser. We also display the next steps for using the interface, including creating an admin account and selecting the configured model. Also, we define helper functions for checking logs and stopping the running processes, which makes the overall setup easier for us to manage and reuse.<\/p>\n<p>In conclusion, we created a fully functional Open WebUI deployment on Colab and connected it to OpenAI in a secure, structured manner. We installed the application and its supporting packages, provided authentication details via protected input, configured the backend connection to the OpenAI API, and started the local web server powering the interface. We then exposed that server through a public tunnel, making the application usable through a browser without requiring local installation on our machine. In addition, we included helper functions for viewing logs and stopping the running services, which makes the setup easier to manage and troubleshoot during experimentation. Overall, we established a reusable, practical workflow that helps us quickly spin up Open WebUI in Colab, test OpenAI-powered chat interfaces, and reuse the same foundation for future prototyping, demos, and interface-driven AI projects.<\/p>\n<hr class=\"wp-block-separator has-alpha-channel-opacity\" \/>\n<p>Check out\u00a0the\u00a0<strong><a href=\"https:\/\/github.com\/Marktechpost\/AI-Tutorial-Codes-Included\/blob\/main\/LLM%20Projects\/open_webui_google_colab_secure_openai_tunnel_setup_tutorial_Marktechpost.ipynb\" target=\"_blank\" rel=\"noreferrer noopener\">Full Codes here<\/a>. \u00a0<\/strong>Also,\u00a0feel free to follow us on\u00a0<strong><a href=\"https:\/\/x.com\/intent\/follow?screen_name=marktechpost\" target=\"_blank\" rel=\"noreferrer noopener\"><mark>Twitter<\/mark><\/a><\/strong>\u00a0and don\u2019t forget to join our\u00a0<strong><a href=\"https:\/\/www.reddit.com\/r\/machinelearningnews\/\" target=\"_blank\" rel=\"noreferrer noopener\">120k+ ML SubReddit<\/a><\/strong>\u00a0and Subscribe to\u00a0<strong><a href=\"https:\/\/www.aidevsignals.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">our Newsletter<\/a><\/strong>. Wait! are you on telegram?\u00a0<strong><a href=\"https:\/\/t.me\/machinelearningresearchnews\" target=\"_blank\" rel=\"noreferrer noopener\">now you can join us on telegram as well.<\/a><\/strong><\/p>\n<p>Need to partner with us for promoting your GitHub Repo OR Hugging Face Page OR Product Release OR Webinar etc.?\u00a0<strong><a href=\"https:\/\/forms.gle\/MTNLpmJtsFA3VRVd9\" target=\"_blank\" rel=\"noreferrer noopener\"><mark>Connect with us<\/mark><\/a><\/strong><\/p>\n<p>The post <a href=\"https:\/\/www.marktechpost.com\/2026\/04\/07\/how-to-deploy-open-webui-with-secure-openai-api-integration-public-tunneling-and-browser-based-chat-access\/\">How to Deploy Open WebUI with Secure OpenAI API Integration, Public Tunneling, and Browser-Based Chat Access<\/a> appeared first on <a href=\"https:\/\/www.marktechpost.com\/\">MarkTechPost<\/a>.<\/p>","protected":false},"excerpt":{"rendered":"<p>In this tutorial, we build a c&hellip;<\/p>\n","protected":false},"author":1,"featured_media":29,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-682","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/connectword.dpdns.org\/index.php?rest_route=\/wp\/v2\/posts\/682","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/connectword.dpdns.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/connectword.dpdns.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/connectword.dpdns.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/connectword.dpdns.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=682"}],"version-history":[{"count":0,"href":"https:\/\/connectword.dpdns.org\/index.php?rest_route=\/wp\/v2\/posts\/682\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/connectword.dpdns.org\/index.php?rest_route=\/wp\/v2\/media\/29"}],"wp:attachment":[{"href":"https:\/\/connectword.dpdns.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=682"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/connectword.dpdns.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=682"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/connectword.dpdns.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=682"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}