Skip to content

fix(models): allow extra_args when chat completions kwarg is omitted - #3200

Closed
adityasingh2400 wants to merge 1 commit into
openai:mainfrom
adityasingh2400:fix/chat-extra-args-omit
Closed

adityasingh2400 wants to merge 1 commit into
openai:mainfrom
adityasingh2400:fix/chat-extra-args-omit

Conversation

@adityasingh2400

Copy link
Copy Markdown
Contributor

Summary

Mirror of #3185 (Responses API fix) for the Chat Completions path.

When a user supplies a first-class request parameter (e.g. temperature, top_p, max_tokens, metadata, ...) through ModelSettings.extra_args without also setting the corresponding ModelSettings field, the chat completions path falsely raises:

TypeError: chat.completions.create() got multiple values for keyword argument 'temperature'

This happens because the field in create_kwargs resolves to OpenAI's omit sentinel (not absent), and the duplicate-key check uses a plain set intersection. The Responses API path had the same bug, fixed in #3185 by skipping keys whose first-class value is Omit/NotGiven. The same pattern still exists in openai_chatcompletions.py::_fetch_response — this PR applies the same fix here.

Behavior change

  • Before: ModelSettings(extra_args={"temperature": 0.25}) raised TypeError unless temperature was also None-by-default normalization.
  • After: the extra_args value passes through.
  • Genuine collisions (e.g. ModelSettings(temperature=0.5, extra_args={"temperature": 0.25})) still raise TypeError as before.

Test plan

  • uv run pytest tests/models/test_openai_chatcompletions.py tests/models/test_openai_chatcompletions_stream.py tests/models/test_openai_chatcompletions_converter.py tests/models/test_kwargs_functionality.py (59 passed)
  • ruff check + ruff format --check clean
  • New tests:
    • test_fetch_response_allows_extra_arg_when_explicit_arg_is_omitted — fails on main, passes after fix
    • test_fetch_response_rejects_duplicate_extra_args_with_explicit_value — guards regression on the genuine-collision case

Issue number

N/A (parallel of #3185 for chat completions)

Checks

  • I've added new tests
  • I've added/updated the relevant documentation (none needed)
  • I've run make lint / make format equivalent (ruff check / ruff format --check)
  • I've made sure tests pass

Mirror the Responses API fix from openai#3185 in the chat completions path.
Previously, supplying any optional first-class field (e.g. `temperature`)
through `ModelSettings.extra_args` would falsely raise a duplicate-argument
TypeError whenever the corresponding model setting was unset (resolved to
the OpenAI `omit` sentinel). Now we only flag a duplicate when the
first-class kwarg holds a real value, while still rejecting genuine
collisions.
@github-actions github-actions Bot added bug Something isn't working feature:chat-completions labels May 8, 2026
@seratch

seratch commented May 8, 2026

Copy link
Copy Markdown
Member

#3192 already suggested this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working feature:chat-completions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants