Skip to content

fix: handle empty OPENAI_BASE_URL and top-level Responses API error fields#3052

Open
maryamfaizan53 wants to merge 3 commits intoopenai:mainfrom
maryamfaizan53:main
Open

fix: handle empty OPENAI_BASE_URL and top-level Responses API error fields#3052
maryamfaizan53 wants to merge 3 commits intoopenai:mainfrom
maryamfaizan53:main

Conversation

@maryamfaizan53
Copy link
Copy Markdown

Fixes #2927 and #2487.

Fix 1 — Empty OPENAI_BASE_URL breaks the client (_client.py)

If OPENAI_BASE_URL="" is set, os.environ.get("OPENAI_BASE_URL") returns "" not None, so the fallback to the default endpoint never triggers. Changed to os.environ.get("OPENAI_BASE_URL") or None so empty strings are treated as unset.

Fix 2 — Streaming error events silently ignored (_streaming.py)

Per the Responses API spec, streaming error events send message at the top level — not inside a nested "error" key. The old condition data.get("error") never matched spec-compliant errors. Updated to (data.get("error") or data.get("message")) so both formats are handled correctly.

@maryamfaizan53 maryamfaizan53 requested a review from a team as a code owner April 2, 2026 22:43
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d31330621a

ℹ️ 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".

else:
data = sse.json()
if is_mapping(data) and data.get("error"):
if is_mapping(data) and (data.get("error") or data.get("message")):
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Avoid assuming error exists for top-level message events

This branch now triggers when a stream payload has only a top-level message, but the exception construction still reads data["error"]; for spec-compliant error events without an error object, this raises KeyError and bypasses the intended APIError path. In practice, streaming failures can still crash with an internal key lookup error instead of returning a usable API exception (the same pattern is duplicated in the async path).

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Empty OPENAI_BASE_URL prevents fallback to default API endpoint

1 participant