fix: skip thinking-only OpenAI chat history messages
Closed
PR
5mo ago+48+48+01234567890123456789-1-1-0123456789
- Closes #6138
Summary
This updates the OpenAI Chat Completions message mapping to skip model responses that only contain mapped thinking parts and no text or tool calls. Custom reasoning fields such as reasoning_content do not satisfy Chat Completions' requirement for assistant messages to include content unless tool_calls is populated, so sending those responses back in history can produce content=null request errors.
Tests
py -3.11 -m uv run --python 3.11 pytest tests/models/test_openai.py::test_empty_response_skipped_in_history tests/models/test_openai.py::test_thinking_only_response_skipped_in_historypy -3.11 -m uv run --python 3.11 ruff format --check pydantic_ai_slim/pydantic_ai/models/openai.py tests/models/test_openai.pypy -3.11 -m uv run --python 3.11 ruff check pydantic_ai_slim/pydantic_ai/models/openai.py tests/models/test_openai.py
Checklist
- Any AI generated code has been reviewed line-by-line by the human PR author, who stands by it.
- No breaking changes in accordance with the version policy.
- PR title is fit for the release changelog.