-
Notifications
You must be signed in to change notification settings - Fork 4.3k
fix(client): normalize and strip model names before request #2633
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Summary This change improves how model names are handled inside `_base_client.py`. Previously, if a developer passed a model name with uppercase letters (e.g. `"GPT-4O-MINI"`) or extra spaces (e.g. `" gpt-4o-mini "`), the client would send it directly to the API. Since the backend is strict and only accepts exact lowercase identifiers (like `"gpt-4o-mini"`), this would cause: ``` BadRequestError: unexpected model name format ``` --- ## Changes - Added a normalization step in `BaseClient._build_request`: - Automatically converts model names to lowercase. - Removes leading/trailing whitespace. --- ## Why This small improvement: - Prevents confusing **400 errors** when users accidentally use uppercase or spacing. - Makes the SDK more developer-friendly and forgiving without altering API behavior. - Increases compatibility across both **OpenAI** and **Gemini** endpoints (since Gemini APIs accessed through the OpenAI Agent SDK also require strict lowercase model identifiers). - Keeps compatibility with existing OpenAI models — now `"GPT-4"`, `" gPt-4 "`, and `"gpt-4"` all resolve correctly. --- ## Examples ### Before (OpenAI model) ```python client.chat.completions.create(model="GPT-4O-MINI", messages=[...]) # ❌ Error: unexpected model name format ``` ### After (OpenAI model) ```python client.chat.completions.create(model="GPT-4O-MINI", messages=[...]) # ✅ Works: normalized to "gpt-4o-mini" ``` --- ### Before (Gemini model used with `OpenAIChatCompletionsModel`) ```python client = AsyncOpenAI( api_key=API_KEY, base_url="https://generativelanguage.googleapis.com/v1beta/openai/" ) model = OpenAIChatCompletionsModel( model=" Gemini-2.5-flash ", # note extra spaces / mixed casing openai_client=client, ) # ❌ Error: unexpected model name format ``` ### After (Gemini model with fix applied) ```python model = OpenAIChatCompletionsModel( model=" GeMiNi-2.5-flAsH ", openai_client=client, ) # ✅ Works: normalized to "gemini-2.5-flash" ``` --- ## Impact - 🚫 No breaking changes. - ✅ Safer and more user-friendly client behavior. - ✅ Prevents tricky case/spacing bugs for both OpenAI and Gemini model IDs. - ✅ Helps beginners and production apps avoid unnecessary API errors. --- ## 🔑 Why This Matters Whether using standard **OpenAI models** (`gpt-4o`, `gpt-4o-mini`, etc.) or integrating **Google Gemini models** via the OpenAI Agent SDK, developers will no longer run into frustrating case/format errors just because of casing or whitespace. This makes the SDK **robust, cross-compatible, and beginner-friendly**.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
Summary
This change improves how model names are handled inside
_base_client.py
.Previously, if a developer passed a model name with uppercase letters (e.g.
"GPT-4O-MINI"
) or extra spaces (e.g." gpt-4o-mini "
), the client would send it directly to the API. Since the backend is strict and only accepts exact lowercase identifiers (like"gpt-4o-mini"
), this would cause:Changes
BaseClient._build_request
:Why
This small improvement:
"GPT-4"
," gPt-4 "
, and"gpt-4"
all resolve correctly.Examples
Before (OpenAI model)
After (OpenAI model)
Before (Gemini model used with
OpenAIChatCompletionsModel
)After (Gemini model with fix applied)
Impact
🔑 Why This Matters
Whether using standard OpenAI models (
gpt-4o
,gpt-4o-mini
, etc.) or integrating Google Gemini models via the OpenAI Agent SDK, developers will no longer run into frustrating case/format errors just because of casing or whitespace.This makes the SDK robust, cross-compatible, and beginner-friendly.
Changes being requested
Additional context & links
"I’m aware this repo is auto-generated. If this should instead be fixed in the generator or spec, I’m happy to move the patch there. Please advise."