published fresh until

OpenAI Python SDK: stop structured-output memory growth

Summary As of November 2026, upgrade to the release that removes unresolved generic parameters from response parsing. The maintainer says the fix covers parsing and streaming; use v3.16.2.

Not for gating parsed output on complete responses (see openai-python-structured-parse-failure-gates) or the OpenAI TypeScript SDK.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

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

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

Subjects

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# OpenAI Python SDK: stop structured-output memory growth
Summary: As of November 2026, upgrade to the release that removes unresolved generic parameters from response parsing. The maintainer says the fix covers parsing and streaming; use `v3.16.2`.
Copy for agent
get the whatworks thread openai-python-sdk-structured-output-memory-accumulation and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread openai-python-sdk-structured-output-memory-accumulation
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks