Skip to content

fix(openai): support Langfuse arguments in stream helpers#1755

Draft
gigio1023 wants to merge 1 commit into
langfuse:mainfrom
gigio1023:feat/openai-stream-helper-args
Draft

fix(openai): support Langfuse arguments in stream helpers#1755
gigio1023 wants to merge 1 commit into
langfuse:mainfrom
gigio1023:feat/openai-stream-helper-args

Conversation

@gigio1023

@gigio1023 gigio1023 commented Jul 13, 2026

Copy link
Copy Markdown

What does this PR do?

Allows the native Chat Completions and Responses stream() helpers to accept Langfuse-specific arguments. The inner create(stream=True) call remains the single owner of the generation observation.

  • Covers sync and async Chat helpers from OpenAI 1.40, using the legacy beta registration before 1.92, and Responses helpers from 1.66.
  • Preserves native stream managers, structured-output and final-result helpers, user-provided extra_body, and sync manager reuse.
  • Finalizes each observation once on exhaustion, explicit close, or context-manager exit after partial or no consumption.
  • Treats OpenAI Omit defaults as absent so inputs, metadata, and model parameters remain clean. Actual Responses retrieval streams remain uninstrumented.

Fixes langfuse/langfuse#15018

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Refactor
  • Documentation update
  • Tooling, CI, or repo maintenance

Verification

uv run --frozen pytest -q tests/unit/test_openai.py tests/unit/test_openai_stream_compatibility.py
for version in 1.40.0 1.66.0 1.92.0; do uv run --frozen --with "openai==$version" pytest -q tests/unit/test_openai_stream_compatibility.py; done
LANGFUSE_PUBLIC_KEY=test-public-key LANGFUSE_SECRET_KEY=test-secret-key LANGFUSE_BASE_URL=http://localhost:3000 bash scripts/codex/quick-check.sh

Checklist

  • I self-reviewed the diff using code_review.md.
  • I added or updated tests for behavior changes.
  • I updated docs, examples, or .env.template if needed.
  • I did not hand-edit generated files; if generated files changed, I used the upstream regeneration path.
  • I did not commit secrets or credentials.

@CLAassistant

CLAassistant commented Jul 13, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

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.

bug(sdk-python): OpenAI stream helpers reject Langfuse-specific arguments

2 participants