fix: handle null text values in Response.output_text#3057
fix: handle null text values in Response.output_text#3057akhilc08 wants to merge 2 commits intoopenai:mainfrom
Conversation
When OPENAI_BASE_URL is set to an empty string, os.environ.get() returns "" rather than None, so the `if base_url is None` fallback to the default API endpoint never triggers. Change the check to `if not base_url` so that both None and empty string fall through to the default https://api.openai.com/v1 endpoint. Applied to both OpenAI (sync) and AsyncOpenAI classes. Closes openai#2927 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Skip content items where text is None to prevent TypeError when joining strings. Some models return output_text content items with null text fields. Closes openai#3011 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 56e915d7a0
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| if base_url is None: | ||
| base_url = os.environ.get("OPENAI_BASE_URL") | ||
| if base_url is None: | ||
| if not base_url: |
There was a problem hiding this comment.
Do not default explicit empty base_url values
Using if not base_url here changes semantics for explicitly provided values: OpenAI(base_url="") (and the async constructor’s equivalent branch) now silently targets https://api.openai.com/v1 instead of surfacing an invalid configuration. This can turn a caller/config bug into unintended traffic to production, which is harder to detect than a startup failure. The fallback should apply only when base_url is missing (None/unset env), not when the caller passed an explicit empty string.
Useful? React with 👍 / 👎.
Summary
TypeErrorinResponse.output_textwhen content items havetext: nullNonecheck before appending text to the list, so null text values are skipped instead of causing"".join()to failProblem
Some models return
output_textcontent items where thetextfield isnull. Whenoutput_textiterates over these items, it appendsNoneto the list and then"".join(texts)raises:Fix
Changed the condition in the
output_textproperty from:to:
Closes #3011
Test plan
test_output_text_with_null_text— verifies mixed null/non-null text items produce correct outputtest_output_text_all_null_text— verifies all-null text items return empty string🤖 Generated with Claude Code