Skip to content

OpenAI streaming silently not traced when extra_headers=None is passed explicitly #7731

Description

@Shailendra005

Description

weave.integrations.openai.openai_sdk.should_use_accumulator crashes (and the crash is swallowed by the op wrapper) when a streaming call is made with an explicit extra_headers=None. extra_headers is typed Headers | None, so None is a valid value. When it's passed, the accumulator check raises AttributeError, the exception is caught silently, and the streaming response is not accumulated — the trace stores the raw un-consumed iterator instead of the assembled content/usage. Silent observability loss with no error surfaced to the user.

weave version: 0.53.5.dev0 (master @ 1213bfa) · python 3.13 · openai 2.30.0

Reproducer

from weave.integrations.openai.openai_sdk import should_use_accumulator
# extra_headers: Headers | None  ->  None is valid and reaches here
should_use_accumulator({"stream": True, "extra_headers": None})
# AttributeError: 'NoneType' object has no attribute 'get'

Equivalent end-user trigger:

client.chat.completions.create(model="gpt-4o", messages=[...], stream=True, extra_headers=None)

Root cause

weave/integrations/openai/openai_sdk.py:374

and not inputs.get("extra_headers", {}).get("X-Stainless-Raw-Response") == "true"

The {} default only applies when the key is absent; an explicit None value passes through, so None.get(...) raises.

Fix

(inputs.get("extra_headers") or {}).get(...). Happy to open a PR (branch ready, test included).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions