Open WebUI: Fix Trailing Slash In OpenAI API URL
Introduction
Hey guys! Today, we're diving deep into a quirky issue in Open WebUI that can cause some headaches when configuring your OpenAI API URL. Specifically, we're talking about the trailing slash and how it can mess things up. If you've been pulling your hair out trying to figure out why your models aren't being detected, you're in the right place. Let's break it down and get you back on track.
The Problem: Trailing Slashes in OpenAI API URLs
So, what's the deal with these trailing slashes? Well, when setting up your Open WebUI configuration, you might define your OPENAI_API_BASE_URL
like this: "https://api.studio.nebius.com/v1/"
. Seems innocent enough, right? But, it turns out that this little slash at the end can cause Open WebUI to fail to detect your models, leaving you with an empty list and a whole lot of frustration. When your models aren't detected as expected, it can be a major roadblock in getting your applications up and running. Understanding and addressing this issue is crucial for a smooth and efficient workflow. This problem highlights the importance of precise configuration and the sometimes subtle nuances that can significantly impact system behavior.
The core issue lies in how Open WebUI constructs the URL for fetching models. Instead of properly joining the base URL with the "/models" endpoint, it naively concatenates them. This can lead to a malformed URL, especially when a trailing slash is present in the base URL. A malformed URL can result in the API endpoint not being found, leading to the failure to retrieve the list of available models. This underscores the need for robust URL handling within Open WebUI to ensure that API requests are correctly formed, regardless of the presence or absence of trailing slashes in the base URL configuration. By addressing this issue, Open WebUI can provide a more seamless and reliable experience for users, reducing potential configuration errors and improving overall usability.
The expectation is simple: when you configure your API URL, everything should just work. You set your OPENAI_API_BASE_URL
, provide your OPENAI_API_KEY
, and expect your models to be detected and usable. But alas, the trailing slash throws a wrench in the gears. Instead of a smooth operation, you're greeted with an empty list of models and a system that just doesn't want to cooperate. This discrepancy between expected and actual behavior is not only frustrating but also highlights the importance of meticulous attention to detail in software configuration. Ensuring that the system behaves as expected under various configurations is crucial for maintaining user trust and confidence in the platform. By resolving issues like this, Open WebUI can enhance its reliability and user-friendliness, making it a more appealing choice for developers and users alike.
Diving into the Code: The Root Cause
The problem lies in this snippet of code from backend/open_webui/routers/openai.py
:
async with session.get(
f"{url}/models",
headers=headers,
Instead of using a proper URL handling method, like urllib.parse.urljoin()
, the code simply concatenates the URL with "/models". This is a recipe for disaster when dealing with trailing slashes. The correct approach would be something like:
import urllib.parse
async with session.get(
urllib.parse.urljoin(url, "models"),
headers=headers,
urllib.parse.urljoin()
intelligently handles trailing slashes, ensuring that the resulting URL is always correct. By using this method, Open WebUI can avoid the pitfalls of naive string concatenation and provide a more robust and reliable way to construct API URLs. This not only fixes the specific issue with trailing slashes but also sets a better precedent for URL handling throughout the codebase. Proper URL handling is essential for ensuring that API requests are correctly formed and that the application behaves predictably under various configurations. This change would contribute to the overall stability and usability of Open WebUI, making it a more trustworthy platform for users.
This issue isn't just about a single trailing slash; it's about the broader need for robust URL handling throughout the Open WebUI codebase. Sloppy URL construction can lead to a variety of unexpected issues, making the system more fragile and difficult to maintain. By adopting best practices for URL handling, Open WebUI can improve its overall reliability and reduce the likelihood of future bugs related to URL formatting. This includes not only using urllib.parse.urljoin()
but also ensuring that all URL-related code is thoroughly tested and reviewed to prevent similar issues from creeping in. A commitment to robust URL handling is a commitment to the long-term stability and maintainability of the project, benefiting both developers and users.
Reproducing the Issue: Step-by-Step
Want to see this issue in action? Hereās how to reproduce it:
- Set up a new Open WebUI installation. Use Docker for easy setup.
- Configure your
OPENAI_API_BASE_URL
with a trailing slash. For example:
OPENAI_API_BASE_URL: "https://api.studio.nebius.com/v1/"
OPENAI_API_KEY: "my_key"
MODEL_FILTER_LIST: '["openai/gpt-oss-120b"]'
DEFAULT_MODELS: "openai/gpt-oss-120b"
- Start Open WebUI.
- Check for available models. Youāll find an empty list.
By following these steps, you can easily reproduce the issue and confirm that the trailing slash is indeed the culprit. This hands-on approach is a great way to understand the problem and verify the effectiveness of any proposed solutions. It also highlights the importance of clear and concise reproduction steps when reporting bugs, as it allows developers to quickly identify and address the issue. So go ahead, give it a try, and see for yourself how a simple trailing slash can cause so much trouble.
Analyzing the Logs: What to Look For
When things go wrong, the logs are your best friend. However, in this case, the logs aren't as helpful as they could be. You might see something like this:
2025-08-20 10:32:05.882 | DEBUG | aiocache.base:get:201 - GET open_webui.routers.openaiget_all_models(<starlette.requests.Request object at 0x7f8054b2ee90>,)[('user', UserModel(id='9a846b07-6005-471c-bd31-c67a4b460756', name='theigel', email='xxxx', role='admin', profile_image_url='data:image/smth', last_active_at=1755685925, updated_at=1755683545, created_at=1755683545, api_key=None, settings=UserSettings(ui={'version': '0.6.22'}), info=None, oauth_sub=None))] False (0.0000)s
2025-08-20 10:32:05.882 | INFO | open_webui.routers.openai:get_all_models:397 - get_all_models()
2025-08-20 10:32:05.950 | DEBUG | open_webui.routers.openai:get_all_models_responses:378 - get_all_models:responses() [{'detail': 'Not Found'}]
2025-08-20 10:32:05.950 | DEBUG | open_webui.routers.openai:merge_models_lists:412 - merge_models_lists <map object at 0x7f80549b6800>
2025-08-20 10:32:05.950 | DEBUG | open_webui.routers.openai:get_all_models:451 - models: {'data': []}
2025-08-20 10:32:05.950 | DEBUG | aiocache.base:set:280 - SET open_webui.routers.openaiget_all_models(<starlette.requests.Request object at 0x7f8054b2ee90>,)[('user', UserModel(id='9a846b07-6005-471c-bd31-c67a4b460756', name='theigel', email=xxxxxx, role='admin', profile_image_url='data:image/smth', last_active_at=1755685925, updated_at=1755683545, created_at=1755683545, api_key=None, settings=UserSettings(ui={'version': '0.6.22'}), info=None, oauth_sub=None))] 1 (0.0000)s
2025-08-20 10:32:05.951 | DEBUG | open_webui.main:get_models:1327 - /api/models returned filtered models accessible to the user: []
The key thing to note is the "Not Found"
error. However, the logs don't tell you the exact URL being requested, which makes debugging harder than it needs to be. It would be much more helpful if the logs included the full URL and used a WARN
level instead of DEBUG
for such critical errors. Improving the verbosity and clarity of the logs would greatly assist in troubleshooting issues like this, saving developers time and effort in identifying the root cause. Clear and informative logs are an essential tool for any software project, and Open WebUI could benefit from enhancing its logging capabilities in this area.
The Fix: Removing the Trailing Slash
The simplest workaround is to remove the trailing slash from your OPENAI_API_BASE_URL
. So, instead of:
OPENAI_API_BASE_URL: "https://api.studio.nebius.com/v1/"
Use:
OPENAI_API_BASE_URL: "https://api.studio.nebius.com/v1"
This should immediately resolve the issue and allow Open WebUI to detect your models. However, this is just a temporary fix. The underlying problem in the code still needs to be addressed to prevent this issue from recurring in the future. While removing the trailing slash is a quick and easy solution, it's important to recognize that it's not a sustainable one. A proper fix requires modifying the code to handle URLs correctly, regardless of whether they contain a trailing slash or not. This ensures that the system is robust and reliable, providing a better experience for all users.
A Proper Solution: URL Handling with urllib.parse.urljoin()
To properly fix this issue, the Open WebUI codebase needs to be updated to use urllib.parse.urljoin()
for constructing URLs. This will ensure that URLs are always correctly formatted, regardless of the presence or absence of trailing slashes. Hereās the proposed change:
import urllib.parse
async with session.get(
urllib.parse.urljoin(url, "models"),
headers=headers,
This simple change will make Open WebUI much more robust and prevent similar issues from arising in the future. It's a small change with a big impact, improving the overall reliability and usability of the platform. By adopting this best practice for URL handling, Open WebUI can avoid the pitfalls of naive string concatenation and provide a more seamless experience for users. This also sets a good precedent for future development, ensuring that URL-related code is always handled correctly and consistently.
Conclusion
The trailing slash issue in Open WebUI's OpenAI API URL handling is a minor but annoying problem that can be easily fixed with a simple code change. By using urllib.parse.urljoin()
for constructing URLs, Open WebUI can avoid this issue and provide a more robust and reliable platform for its users. So, if you're encountering this problem, remember to remove the trailing slash from your OPENAI_API_BASE_URL
and consider contributing the fix to the codebase. Happy coding, folks!
By addressing this issue, Open WebUI can enhance its overall quality and user-friendliness, making it a more appealing choice for developers and users alike. It's a small change that can make a big difference, improving the reliability and stability of the platform. So, let's get this fix implemented and make Open WebUI even better!