Responses.retrieve is not instrumented, so background responses lose output, usage and cost
@hassiebp ya está trabajando en esto.
Desde el 24/8/2026.
Evaluación
Este issue todavía no se ha evaluado.
Descripción
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
- Lenguaje dominante
- Python
- Estrellas
- 468
- Forks
- 349
- Merge medio
- 15 h 51 min
- PR fusionados (30 d)
- 24
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de langfuse/langfuse-python
-
bug compliance feat-data-masking sdk-python security
langfuse/langfuse-python#1896 · 1 asignado ·
-
feat-scores sdk-python unconfirmed-bug
langfuse/langfuse-python#1890 · 1 asignado ·
-
bug feat-evals sdk-python
langfuse/langfuse-python#1861 · 2 comentarios · 1 asignado ·
-
improvement sdk-python
langfuse/langfuse-python#1856 · 1 asignado ·
-
improvement sdk-python security
langfuse/langfuse-python#1855 · 1 asignado ·
Todos los issues de langfuse/langfuse-python
Issues similares
-
bug priority:low
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
CyberAgent/psd2svg#436 ·
-
area/install-update comp/cli comp/desktop P3 sweeper:risk-compatibility type/bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 86/100
NousResearch/hermes-agent#122386 · 1 comentario ·
-
ai-generated
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
vllm-project/production-stack#1105 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100