From f49efd0686a9902c0a21c635d41ef8277bd4521f Mon Sep 17 00:00:00 2001 From: Junhyuk Lee Date: Thu, 30 Apr 2026 07:42:40 +0000 Subject: [PATCH 1/2] Advance OSS contribution for BadRequestError: 400 - max_tokens or model output limit reached when using beta.chat.completions.parse() with Azure OpenAI GPT-5, even without setting max_tokens Nightly Codex produced a focused contribution for https://github.com/openai/openai-python/issues/2886. Constraint: Automated nightly run; keep changes small and reviewable. Confidence: medium Scope-risk: narrow Tested: See uploaded nightly artifacts and workflow logs. Not-tested: Maintainer CI beyond this workflow. --- NIGHTLY_CODEX_FINAL_ATTEMPT_1.md | 11 +++++++ tests/lib/test_azure.py | 55 ++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 NIGHTLY_CODEX_FINAL_ATTEMPT_1.md diff --git a/NIGHTLY_CODEX_FINAL_ATTEMPT_1.md b/NIGHTLY_CODEX_FINAL_ATTEMPT_1.md new file mode 100644 index 0000000000..b5ac2d08ba --- /dev/null +++ b/NIGHTLY_CODEX_FINAL_ATTEMPT_1.md @@ -0,0 +1,11 @@ +Implemented a focused regression test for [openai/openai-python#2886](https://github.com/openai/openai-python/issues/2886). + +Changed: +- [tests/lib/test_azure.py](/home/runner/work/oss-nightly-control/oss-nightly-control/target/tests/lib/test_azure.py): added an Azure `AsyncAzureOpenAI.beta.chat.completions.parse()` test that asserts `max_tokens` and `max_completion_tokens` are not sent unless explicitly provided. +- [NIGHTLY_REPORT.md](/home/runner/work/oss-nightly-control/oss-nightly-control/target/NIGHTLY_REPORT.md): summarized the work, tests, and remaining risk. + +Verification: +- `uv run --with pytest --with pytest-asyncio --with pytest-xdist --with respx --with inline-snapshot pytest tests/lib/test_azure.py::test_parse_does_not_send_default_token_limits_to_azure` +- `uv run --with ruff ruff check tests/lib/test_azure.py` + +Both passed. Existing untracked `.codex-nightly-prompt.md` and `uv.lock` were left alone. \ No newline at end of file diff --git a/tests/lib/test_azure.py b/tests/lib/test_azure.py index 52c24eba27..4a82f8626c 100644 --- a/tests/lib/test_azure.py +++ b/tests/lib/test_azure.py @@ -1,5 +1,6 @@ from __future__ import annotations +import json import logging from typing import Union, cast from typing_extensions import Literal, Protocol @@ -7,6 +8,7 @@ import httpx import pytest from respx import MockRouter +from pydantic import BaseModel from openai._utils import SensitiveHeadersFilter, is_dict from openai._models import FinalRequestOptions @@ -32,6 +34,59 @@ class MockRequestCall(Protocol): request: httpx.Request +@pytest.mark.respx() +async def test_parse_does_not_send_default_token_limits_to_azure(respx_mock: MockRouter) -> None: + class ParsedResult(BaseModel): + answer: str + + respx_mock.post( + "https://example-resource.azure.openai.com/openai/deployments/gpt-5/chat/completions?api-version=2024-02-01" + ).mock( + return_value=httpx.Response( + 200, + json={ + "id": "chatcmpl-example", + "object": "chat.completion", + "created": 1727346142, + "model": "gpt-5", + "choices": [ + { + "index": 0, + "message": { + "role": "assistant", + "content": '{"answer":"ok"}', + "refusal": None, + }, + "finish_reason": "stop", + } + ], + }, + ) + ) + + client = AsyncAzureOpenAI( + api_version="2024-02-01", + api_key="example API key", + azure_endpoint="https://example-resource.azure.openai.com", + ) + + completion = await client.beta.chat.completions.parse( + model="gpt-5", + messages=[{"role": "user", "content": "Return JSON."}], + response_format=ParsedResult, + reasoning_effort="minimal", + ) + + calls = cast("list[MockRequestCall]", respx_mock.calls) + assert len(calls) == 1 + + request_body = json.loads(calls[0].request.content) + assert request_body["reasoning_effort"] == "minimal" + assert "max_tokens" not in request_body + assert "max_completion_tokens" not in request_body + assert completion.choices[0].message.parsed == ParsedResult(answer="ok") + + @pytest.mark.parametrize("client", [sync_client, async_client]) def test_implicit_deployment_path(client: Client) -> None: req = client._build_request( From b2f2e25dad888f879d329b1e5bf47a1a2e3eff70 Mon Sep 17 00:00:00 2001 From: Junhyuk Lee <58055473+xodn348@users.noreply.github.com> Date: Thu, 30 Apr 2026 11:45:48 -0500 Subject: [PATCH 2/2] Remove nightly runner artifact from PR branch --- NIGHTLY_CODEX_FINAL_ATTEMPT_1.md | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 NIGHTLY_CODEX_FINAL_ATTEMPT_1.md diff --git a/NIGHTLY_CODEX_FINAL_ATTEMPT_1.md b/NIGHTLY_CODEX_FINAL_ATTEMPT_1.md deleted file mode 100644 index b5ac2d08ba..0000000000 --- a/NIGHTLY_CODEX_FINAL_ATTEMPT_1.md +++ /dev/null @@ -1,11 +0,0 @@ -Implemented a focused regression test for [openai/openai-python#2886](https://github.com/openai/openai-python/issues/2886). - -Changed: -- [tests/lib/test_azure.py](/home/runner/work/oss-nightly-control/oss-nightly-control/target/tests/lib/test_azure.py): added an Azure `AsyncAzureOpenAI.beta.chat.completions.parse()` test that asserts `max_tokens` and `max_completion_tokens` are not sent unless explicitly provided. -- [NIGHTLY_REPORT.md](/home/runner/work/oss-nightly-control/oss-nightly-control/target/NIGHTLY_REPORT.md): summarized the work, tests, and remaining risk. - -Verification: -- `uv run --with pytest --with pytest-asyncio --with pytest-xdist --with respx --with inline-snapshot pytest tests/lib/test_azure.py::test_parse_does_not_send_default_token_limits_to_azure` -- `uv run --with ruff ruff check tests/lib/test_azure.py` - -Both passed. Existing untracked `.codex-nightly-prompt.md` and `uv.lock` were left alone. \ No newline at end of file