What this thread does
Do first: Upgrade OpenAI Python SDK to v3.16.2, the release named by the closing maintainer comment.
Symptom
pydantic models left behind which causes memory to accumulate. is savvasp-123's description of repeated AsyncResponses structured-output parsing. The report lists openai==2.31.0, pydantic>=2, and Python 3.13. Other affected users and investigations in the comments include ifplusor, snipd-kevin, and kdincx; snipd-kevin and kdincx describe production memory growth.
Cause
Merged PR #3088 explains that parse_response() passed types parameterized with a free TextFormatT to construct_type_unchecked. Pydantic could not resolve that variable, so model_rebuild(raise_errors=False) returned False, the schema cache stayed empty, and calls allocated new schema objects.
Fix
1. Upgrade to v3.16.2. 2. The SDK change removes [TextFormatT] from the internal type_= arguments for ParsedResponseOutputText, ParsedResponseOutputMessage, and ParsedResponse. PR #3088 states that this changes schema caching without changing the public API or returned object types.
Fixed in
v3.16.2 (released 2026-09-18). PR #3088 merged 2026-09-18 and is explicitly listed in the release notes. marcuswood-oai's closing comment says the fix covers both parsing and streaming.
If you cannot upgrade: snipd-kevin reports avoiding the parsing helpers by using client.responses.create(...), passing the schema as a plain dictionary with "type": "json_schema" and "strict": true, and validating the response in the application. This is the reporter's workaround, not a maintainer guarantee.
If it still fails
- The maintainer asks for further reports if memory still grows after upgrading. The source does not claim that all possible SDK memory growth shares this cause.
- The workaround shifts response validation to application code; it does not retain the parsing helper's automatic validation.
Not for: gating parsed output on complete responses (see openai-python-structured-parse-failure-gates) or the OpenAI TypeScript SDK.
Sources
- Async Responses Structured Outputs Memory leak, savvasp-123, opened 2026-04-14; closed as completed on 2026-09-18: "pydantic models left behind which causes memory to accumulate."
- fix(parsing): drop TextFormatT parameterization in parse_response to fix memory leak (#3084), MukundaKatta; merged 2026-09-18 (closed).
- v3.16.2, published 2026-09-18.
Checked
2026-11-24; read the issue and comments, merged PR API record, and release API record; no command was run.
Started from a post by @savvasp-123, packaged by the editor. Original post