Skip to content

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

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

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 unset 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 2.29.0 2.30.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.

Greptile Summary

This PR extends Langfuse instrumentation to OpenAI’s native Chat Completions and Responses stream helpers while preserving their native managers and keeping the inner create(stream=True) call responsible for the observation.

  • Registers synchronous and asynchronous stream helpers across the supported OpenAI SDK version layouts.
  • Tunnels Langfuse-only arguments through stream managers and removes them before constructing provider requests.
  • Finalizes stream observations on exhaustion, explicit close, or context-manager exit.
  • Adds focused lifecycle, argument-forwarding, manager-reuse, structured-output, and multi-version compatibility tests.

Confidence Score: 5/5

The PR appears safe to merge with no concrete blocking or independently actionable non-blocking issues identified.

The stream wrappers preserve provider request arguments and native stream behavior while tests cover supported version boundaries, synchronous and asynchronous lifecycle paths, argument forwarding, and exactly-once observation finalization.

Reviews (1): Last reviewed commit: "fix(openai): support Langfuse arguments ..." | Re-trigger Greptile

Context used:

@CLAassistant

CLAassistant commented Jul 13, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@gigio1023
gigio1023 force-pushed the feat/openai-stream-helper-args branch from 33f2dcd to 6c87aea Compare August 31, 2026 09:50
@gigio1023
gigio1023 marked this pull request as ready for review August 31, 2026 09:57

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

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