Bug:- websocket_base_url derivation corrupts URLs containing http:// in query params
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 76/100
Research direction
Start in src/openai/_client.py around lines 117–119 and inspect how websocket_base_url is derived when no value is provided. Reproduce the issue with the proxy URL in the report, then verify the resulting URL preserves http:// in the query parameter while changing only the base scheme. Add regression coverage using the reported example and run the relevant client tests.
Written by the indexing model from the issue text.
Description
Confirm this is an issue with the Python library and not an underlying OpenAI API
This is an issue with the Python library
Describe the bug
When no websocket_base_url is provided, the SDK derives one from base_url using Python's str.replace():
base_url.replace("https://", "wss://").replace("http://", "ws://")
str.replace() replaces all occurrences, not just the scheme prefix. If http:// appears anywhere else in the URL (query parameter, path segment, etc.), it gets incorrectly rewritten too.
To Reproduce
from openai import OpenAI
client = OpenAI(
api_key="sk-test",
base_url="https://proxy.com/forward?target=http://backend.internal/v1"
)
print(client.websocket_base_url)
Expected result
wss://proxy.com/forward?target=http://backend.internal/v1
Actual result
wss://proxy.com/forward?target=ws://backend.internal/v1
Suggested fix
Replace only the scheme prefix, not all occurrences:
if base_url.startswith("https://"):
return "wss://" + base_url[len("https://"):]
elif base_url.startswith("http://"):
return "ws://" + base_url[len("http://"):]
Environment
- Library version: latest (main)
- File:
src/openai/_client.pylines ~117–119 - Python version: 3.x
- Dominant language
- Python
- Stars
- 31.7k
- Forks
- 5.8k
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 96
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from openai/openai-python
-
v4
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
openai/openai-python#3837 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
openai/openai-python#3755 · 2 comments ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
openai/openai-python#3556 · 3 comments ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
openai/openai-python#3402 · 2 comments ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
openai/openai-python#2927 · 6 comments ·
All issues in openai/openai-python
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
use-agent-os/agent-os#3314 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
BasedHardware/omi#15662 · 1 comment ·
-
documentation help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
AiursoftWeb/AnduinOS-2#19 ·