SIGN IN SIGN UP

fix(chat): preserve single-pass tool iterables (#3770)

Passing a generator to `chat.completions.parse()` or `.stream()` can
send an empty tools array or lose parsed function arguments. Materialize
the iterable once and reuse it for validation, serialization, and
response parsing across sync and async helpers.

The public `Iterable` type stays unchanged. `.parse()` retains
strict-tool validation; async `.stream()` now accepts non-strict tools
without auto-parsing them, matching existing sync behavior. Two
parametrized tests cover all four helper paths and non-strict streaming.

Validation: chat suite passed with Pydantic v2 (77 tests) and v1 (76
passed, 1 skipped); all four strict-tool regressions fail against main.
Ruff lint, changed-file formatting, Pyright, mypy, and the custom-code
budget passed. Security review found no new concerns.

---------

Co-authored-by: Marcus Wood <marcuswood@openai.com>
H
HughChaw committed
33ffa1f9fa4f49553ab0287b9359283be818fe40
Parent: 5e39766
Committed by GitHub <noreply@github.com> on 9/23/2026, 5:40:07 PM