Inconsistent base_url behavior with module client and OpenAIClient
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 31.6k
- Forks
- 5.7k
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 96
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
The issue is that the base_url in the OpenAI client enforces a trailing slash whereas setting the module openai.base_url does not enforce.
This is 100% reproducible and while it can be worked around, the inconsistency in clients causes issues in scripts that use both clients.
To Reproduce
- Create a module client and use a
base_urlwithout a trailing slash. See error with URL for completions - Create an OpenAIClient and use a
base_urlwithout a trailing slash. See no erros.
Code snippets
This works
client = openai.OpenAI(
api_key=my_key,
base_url="https://myllmserver.com/api/v1"
)
print(client.completions.create(
model="mistralai/Mistral-7B-Instruct-v0.2",
prompt="test"
))
This does not:
openai.base_url="https://myllmserver.com/api/v1"
openai.api_key=my_key
print(openai.completions.create(
model="mistralai/Mistral-7B-Instruct-v0.2",
prompt="test"
))
Error:
https://myllmserver.com/api/v1completions "HTTP/1.1 404 Not Found"
OS
macOS
Python version
Python v3.12
Library version
openai v1.23.6
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.
Research direction
Start by tracing how base_url is handled for the module client and OpenAI client, using the two reproduction snippets as the behavioral comparison. Make both clients construct the same valid completion URL when the base URL lacks a trailing slash, then verify the two call paths produce consistent requests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100