Responses create spends CPU proportional to the body size transforming a body it returns unchanged
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 52/100
- Tipo de issue
- Error
- Claridad
- Bastante claro
- Estado de actividad
- Activo
- Stack tecnológico
- python
- Área
- performance
Línea de trabajo
Start in _utils/_transform.py and trace async_maybe_transform from AsyncResponses.create and Responses.create. Use the reproduction script in the issue to compare transformation time and output equality for large plain-dict bodies. Done means unchanged bodies avoid the recursive walk while aliased, formatted, and file inputs still transform correctly.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Confirm this is an issue with the Python library and not an underlying OpenAI API
- This is an issue with the Python library
Describe the bug
AsyncResponses.create runs async_maybe_transform over the whole request body before every request. With a long input and many tools, that transform costs tens of milliseconds of CPU per request, and the cost grows linearly with the body size. For a body of plain dicts (no aliased keys, no format fields, no file inputs) the transform returns a body equal to its input, so the CPU time does not change the request.
The transform runs on the event loop. In an asyncio app that shares the loop with latency-sensitive work, such as streaming audio, each request blocks that work for the whole transform. A chat app sends the full history on every turn, so the block grows as the conversation gets longer. Responses.create (sync) runs the same transform.
Median of 11 runs, from the script under Code snippets:
| input items | tools | transform (ms) | output == input |
|---|---|---|---|
| 30 | 10 | 4.6 | True |
| 90 | 40 | 14.5 | True |
| 180 | 86 | 29.7 | True |
| 360 | 86 | 54.0 | True |
cProfile of one request with 180 input items and 86 tools: 21,068 calls to _utils/_transform.py:_async_transform_recursive, 7,857 calls to _async_transform_typeddict, and about 74,000 calls to typing.get_origin. The time goes to the walk over every nested dict and list, not to any field the transform rewrites.
A possible direction: decide once per type, and cache, whether its annotations contain any PropertyInfo (alias, format, discriminator). When a type contains none, return the data without walking it.
To Reproduce
- Build a Responses request body of plain dicts with a long
input(user messages,function_callandfunction_call_outputitems) and 86 functiontools. - Time
async_maybe_transform(body, ResponseCreateParamsStreaming), the callAsyncResponses.createmakes before it sends the request. - Compare the transformed body with the input.
The script under Code snippets does this with synthetic data and makes no network call. Its output:
input_items tools transform_ms output_equals_input
30 10 4.6 True
90 40 14.5 True
180 86 29.7 True
360 86 54.0 True
Code snippets
import asyncio
import time
from openai._utils import async_maybe_transform
from openai.types.responses import response_create_params
def build_body(turns: int, n_tools: int) -> dict:
items = []
for i in range(turns):
items.append({"role": "user", "content": [{"type": "input_text", "text": "lorem ipsum " * 100}]})
items.append({"type": "function_call", "call_id": f"call_{i}", "name": "lookup", "arguments": '{"q": "x"}'})
items.append({"type": "function_call_output", "call_id": f"call_{i}", "output": "result " * 200})
tools = [
{
"type": "function",
"name": f"tool_{i}",
"description": "does a thing " * 10,
"strict": False,
"parameters": {
"type": "object",
"properties": {f"arg_{j}": {"type": "string", "description": "an argument"} for j in range(8)},
"required": ["arg_0"],
},
}
for i in range(n_tools)
]
return {"model": "gpt-4.1", "input": items, "tools": tools, "stream": True}
async def median_ms(body: dict) -> tuple[float, bool]:
# The same call AsyncResponses.create makes before sending the request.
for _ in range(3):
out = await async_maybe_transform(body, response_create_params.ResponseCreateParamsStreaming)
runs = []
for _ in range(11):
start = time.perf_counter()
out = await async_maybe_transform(body, response_create_params.ResponseCreateParamsStreaming)
runs.append((time.perf_counter() - start) * 1000)
return sorted(runs)[5], out == body
async def main() -> None:
print("input_items tools transform_ms output_equals_input")
for turns, n_tools in [(10, 10), (30, 40), (60, 86), (120, 86)]:
body = build_body(turns, n_tools)
ms, same = await median_ms(body)
print(f"{len(body['input']):>11} {n_tools:>5} {ms:>12.1f} {same}")
asyncio.run(main())
OS
macOS 26.5 (arm64)
Python version
Python v3.14.3
Library version
openai v3.24.0
- Lenguaje dominante
- Python
- Estrellas
- 32.2k
- Forks
- 5.8k
- Merge medio
- 12 h 29 min
- PR fusionados (30 d)
- 112
Preparar el entorno
Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la 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 openai/openai-python
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
openai/openai-python#4338 ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
openai/openai-python#4337 ·
Los mantenedores suelen responder en 1 día
-
`BaseClient._prepare_url()` corrupts relative endpoint URLs when `base_url` contains query parametersPosiblemente ocupada @Rewaskc02-lang la tomó hace 2 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
openai/openai-python#4311 · 4 comentarios ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
openai/openai-python#4310 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
openai/openai-python#4309 · 1 comentario ·
Los mantenedores suelen responder en 1 día
Todos los issues de openai/openai-python
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 86/100
bad-antics/lateralus-lang#1140 ·
Los mantenedores suelen responder en 4 días
-
Groq: SQL fallback call sends tools with response_format, so a failed tool loop never recoversAbiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Los mantenedores suelen responder en 3 días
-
fixture good first issue help wanted vendor:cisco
Dificultad 1/5 1-3 horas Aptitud para principiantes 85/100