Responses.retrieve is not instrumented, so background responses lose output, usage and cost
Maintainers usually reply within 1 day
@hassiebp is already working on this.
Since Aug 24, 2026.
Assessment
This issue has not been assessed yet.
Description
Summary
Responses.create and Responses.parse are instrumented, but Responses.retrieve is not. For background responses that is the call that carries the actual result, so the generation in the trace never receives its output, token counts or cost.
Why this path matters
With background=True the API returns immediately with status="queued" and no usage. The result is collected later, either with client.responses.retrieve(response_id) or by resuming the stream with client.responses.stream(response_id=...).
The second one is easy to miss: stream() has two branches. Creating a new response goes through partial(self.create, ..., stream=True) and is traced correctly. Resuming an existing one goes through self.retrieve(response_id=..., stream=True) and is not.
Reproduction
No API key needed — this shows which method each path resolves to:
import openai, langfuse.openai
from openai.resources.responses import Responses
calls = []
Responses.create = lambda self, **kw: calls.append(("create", kw.get("stream"))) or iter(())
Responses.retrieve = lambda self, **kw: calls.append(("retrieve", kw.get("stream"))) or iter(())
c = openai.OpenAI(api_key="sk-test", base_url="http://localhost:9")
with c.responses.stream(model="gpt-5.6", input="hi"): # new response
pass
with c.responses.stream(response_id="resp_123"): # resumed response
pass
print(calls) # [('create', True), ('retrieve', True)]
And which of those the SDK patches:
import openai
from openai.resources.responses import Responses
before = {m: getattr(Responses, m) for m in ("create", "parse", "retrieve")}
import langfuse.openai
for m in before:
print(m, before[m] is not getattr(Responses, m))
# create True
# parse True
# retrieve False
grep -c background langfuse/openai.py returns 0, and tests/unit/test_openai.py covers neither retrieve nor .stream(.
Impact
A background response produces a generation with an input and a model, and then nothing else: no output, no usage_details, no cost. On a dashboard that reads as a call that was free, which is worse than a call that is missing — the trace looks complete.
Proposed fix
Add Responses.retrieve / AsyncResponses.retrieve to OPENAI_METHODS_V1. retrieve() carries no prompt of its own, so the response id can serve as the generation input; model, output and usage are already extracted from the response object, and the existing streaming extraction handles stream=True.
One open question for maintainers: retrieving a response that was already traced at creation time (non-background usage) would then record its usage a second time. Options are to instrument every retrieve, or only the stream=True path, or to skip usage when the response was not queued. Happy to follow whichever you prefer — PR attached implements the straightforward version.
Version info
- langfuse: main (4.x)
- openai: 2.29.0
- Python: 3.14
- Dominant language
- Python
- Stars
- 468
- Forks
- 349
- Avg merge
- 15h 51m
- Merged PRs (30d)
- 24
Getting set up
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from langfuse/langfuse-python
-
mask is not applied to create_dataset_item or create_score(comment=)Possibly taken @hassiebp claimed this 4 days ago. Openbug compliance feat-data-masking sdk-python security
langfuse/langfuse-python#1896 · 1 comment · 1 assignee ·
Maintainers usually reply within 1 day
-
Scores bypass sample_rate since v4Possibly taken @hassiebp claimed this 9 days ago. Openfeat-scores sdk-python unconfirmed-bug
langfuse/langfuse-python#1890 · 1 assignee ·
Maintainers usually reply within 1 day
-
batch_evaluation fails on self-hosted v4 events_only deployments (uses unavailable v3 read endpoints)Possibly taken @hassiebp claimed this 22 days ago. Openbug feat-evals sdk-python
langfuse/langfuse-python#1861 · 2 comments · 1 assignee ·
Maintainers usually reply within 1 day
-
[HTTPXodus] Consider migrating from httpx to httpx2 (the actively maintained fork)Possibly taken @hassiebp claimed this 23 days ago. Openimprovement sdk-python
langfuse/langfuse-python#1856 · 1 assignee ·
Maintainers usually reply within 1 day
-
[HTTPXodus] Consider migrating from `httpx` to `httpx2` (the actively maintained fork)Possibly taken @hassiebp claimed this 23 days ago. Openimprovement sdk-python security
langfuse/langfuse-python#1855 · 1 assignee ·
Maintainers usually reply within 1 day
All issues in langfuse/langfuse-python
Similar issues
-
needs triage
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
openvinotoolkit/openvino_notebooks#3665 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
Maintainers usually reply within 1 day
-
docs
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Maintainers usually reply within 1 day
-
benchmark-gap
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day