Fix false results for whitespace-padded true responses (#3854)
- [x] I understand that this repository is auto-generated and my pull
request may not be merged
## Changes being requested
A JSON `true` with a trailing newline is parsed as `False`. Both
response parsers now trim whitespace and keep case-insensitive parsing.
## Additional context & links
| # | Scenario | Command | Result |
| --- | --- | --- | --- |
| 1 | Local file download | Program below | `true\n`: `False` before,
`True` after |
<details><summary>Reproducer and raw logs</summary>
```bash
PYTHONPATH=src python - <<'PY'
from http import HTTPStatus
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
from threading import Thread
import httpx2
from openai import OpenAI
FILES: dict[str, bytes] = {"file_false": b"false\n", "file_true": b"true\n"}
class Handler(BaseHTTPRequestHandler):
def do_GET(self) -> None:
body = FILES[self.path.split("/")[3]]
self.send_response(HTTPStatus.OK)
self.send_header("Content-Type", "application/json")
self.send_header("Content-Length", str(len(body)))
self.end_headers()
self.wfile.write(body)
def log_message(self, format: str, *args: object) -> None:
pass
server = ThreadingHTTPServer(server_address=("127.0.0.1", 0), RequestHandlerClass=Handler)
thread = Thread(target=server.serve_forever)
thread.start()
try:
with OpenAI(api_key="local", base_url=f"http://127.0.0.1:{server.server_port}/v1",
http_client=httpx2.Client(trust_env=False)) as client:
for file_id in FILES:
raw = client.files.with_raw_response.content(file_id=file_id)
with client.files.with_streaming_response.content(file_id=file_id) as streamed:
values = (raw.parse(to=bool), streamed.parse(to=bool))
print(file_id, raw.status_code, values, flush=True)
expected = file_id == "file_true"
assert values == (expected, expected), "Incorrect boolean result"
finally:
server.shutdown()
server.server_close()
thread.join()
PY
```
Before:
```text
file_false 200 (False, False)
file_true 200 (False, False)
Traceback (most recent call last):
File "<stdin>", line 34, in <module>
AssertionError: Incorrect boolean result
exit=1
```
After:
```text
file_false 200 (False, False)
file_true 200 (True, True)
exit=0
```
</details>
Both parser modules hit the same existing `AttributeError: module 'rich'
has no attribute 'console'` in the display helper before and after this
change.
Signed-off-by: 1fanwang <1fannnw@gmail.com>
Co-authored-by: Marcus Wood <marcuswood@openai.com> S
Stefan Wang committed
5a4bb9658ddb54f2b4033349ae621d4d879cc40f
Parent: 49e4366
Committed by GitHub <noreply@github.com>
on 9/29/2026, 9:56:50 PM