fix: properly handle extra_body parameter to match OpenAI SDK behavior#416
Open
fix: properly handle extra_body parameter to match OpenAI SDK behavior#416
Conversation
When users pass extra_body={'a': 'b'} to API methods, the contents should be
merged at the top level of the request body, not nested under an 'extra_body' key.
Previously, the SDK was passing kwargs directly to the OpenAI SDK's extra_body
parameter, which meant extra_body={'a': 'b'} would result in the request body
containing {'extra_body': {'a': 'b'}} instead of just {'a': 'b'}.
This fix:
- Adds extract_extra_params() helper in utils.py that properly extracts and
merges extra_body, extra_headers, extra_query, and timeout from kwargs
- Updates 11 API files to use the new helper:
- chat_complete.py
- complete.py
- embeddings.py
- moderations.py
- models.py
- audio.py
- images.py
- batches.py
- fine_tuning.py
- uploads.py
- evals.py
The fix ensures that:
- extra_body={'a': 'b'} adds 'a' at the top level of the request body
- Additional kwargs are also merged into the request body
- extra_headers, extra_query, and timeout are properly passed through
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
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.
Problem
When users pass
extra_body={'a': 'b'}to API methods likeclient.chat.completions.create(), the contents should be merged at the top level of the request body. Instead, the SDK was nesting it under anextra_bodykey.Expected request body:
{"model": "...", "messages": [...], "a": "b"}Actual (buggy) request body:
{"model": "...", "messages": [...], "extra_body": {"a": "b"}}This breaks compatibility with OpenAI SDK conventions and causes issues when users try to pass provider-specific parameters like Anthropic's
thinkingparameter.Root Cause
The SDK was passing
kwargsdirectly to the OpenAI SDK'sextra_bodyparameter:Solution
Added
extract_extra_params()helper inutils.pythat:extra_bodyfrom kwargsFiles Changed
utils.py- Addedextract_extra_params()helper functionchat_complete.pycomplete.pyembeddings.pymoderations.pymodels.pyaudio.pyimages.pybatches.pyfine_tuning.pyuploads.pyevals.pyTesting
Note
5 files still have the old pattern and may need fixing in a follow-up PR:
assistants.pythreads.pymain_files.pyvector_stores.pybeta_chat.py