bug: Batch API result file download fails for large outputs (>200MB) with ConnectionResetError
Los mantenedores suelen responder en 1 día
@CacinieP ya está trabajando en esto.
Desde el 31/8/2026.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 45/100
Línea de trabajo
Comienza reproduciendo el fallo mediante client.batches.retrieve_content y client.files.with_streaming_response.content con un resultado grande de Batch y, después, compáralo con el ejemplo de requests directas. No se mencionan archivos ni pruebas del repositorio, así que sigue la ruta de streaming de la Files API del SDK y determina si la respuesta incompleta se gestiona en la biblioteca. Se considera terminado cuando las descargas de resultados grandes se completan de forma fiable o cuando la limitación y el comportamiento de reintento se abordan explícitamente.
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
Describe the bug
When using the Batch API to download large result files (specifically when the output .jsonl exceeds ~200-300MB, e.g., 50k embedding rows), the download connection is prematurely closed by the peer.
The error typically manifests as:
httpcore.RemoteProtocolError: peer closed connection without sending complete message body (received X bytes, expected Y bytes)
To Reproduce
Create a Batch job with 50,000 embedding requests (text-embedding-3-small).
Wait for the batch to complete (status: completed).
Attempt to download the result file using the SDK:
Python
Standard SDK approach that fails
content = client.batches.retrieve_content(batch.output_file_id)
content.with_streaming_response.content()
Or using the requests library directly with the file URL.
The download will consistently fail after receiving a few hundred megabytes.
Expected behavior
The SDK should handle large file streaming robustly, or provide a built-in chunked download/retry mechanism for massive Batch outputs (1GB+).
Environment
OS: macOS 15.x
Python Version: 3.12.x
Additional context
Workaround: I've confirmed that splitting the 50k requests into smaller batches of 10k (resulting in ~200MB files) allows for stable downloads. This suggests a potential timeout or buffer limitation on the server-side proxy or within the SDK's streaming implementation for payloads exceeding a certain threshold.
I am currently implementing a manual chunked-download helper with exponential backoff to bypass this. but i dont think it;s optimal
To Reproduce
To Reproduce:
- Prepare a batch with ~50,000 rows (near the OpenAI limit)
- Submit to Batch API with endpoint /v1/embeddings
- Wait for status = completed
- Attempt to download result file via Files API Code Snippets:
sample code:
from openai import OpenAI
client = OpenAI()
Result file is ~1GB when batch has 50,000 embeddings
result_content = client.files.content(result_file_id)
result_text = result_content.text # fails silently or raises
#failed on streaming :
with client.files.with_streaming_response.content(result_file_id) as resp:
with open("result.jsonl", "wb") as f:
for chunk in resp.iter_bytes(chunk_size=1024 * 1024):
f.write(chunk)
raises: peer closed connection without sending complete message body
(received 940216419 bytes, expected 1056098116)
#same for requests:
import requests
response = requests.get(
f"https://api.openai.com/v1/files/{result_file_id}/content",
headers={"Authorization": f"Bearer {api_key}"},
stream=True,
timeout=(10, 300)
)
same error, connection drops around 500-1000MB
Code snippets
OS
macOS
Python version
Python Version: 3.12.x
Library version
2.24.0
- Lenguaje dominante
- Python
- Estrellas
- 31.8k
- Forks
- 8k
- Merge medio
- 1 d 1 h
- PR fusionados (30 d)
- 137
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 72/100
openai/openai-python#4022 · 20 comentarios ·
Los mantenedores suelen responder en 1 día
-
fix(auth): SubjectTokenProviderError drops response and duplicates error message in workload identity providersPosiblemente ocupada @mohmedmm la tomó hace 13 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 86/100
openai/openai-python#4017 · 3 comentarios ·
Los mantenedores suelen responder en 1 día
-
Querystring drops explicit empty-string scalar valuesPosiblemente ocupada @sylvesterkaczmarek la tomó hace 35 días. Abiertosdk-breaking-change v4
Dificultad 2/5 1-3 horas Aptitud para principiantes 86/100
openai/openai-python#3837 ·
Los mantenedores suelen responder en 1 día
-
Define + export `ServiceTiers` string literalPosiblemente ocupada @SparshGarg999 la tomó hace 62 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
openai/openai-python#3556 · 3 comentarios ·
Los mantenedores suelen responder en 1 día
-
Empty OPENAI_BASE_URL prevents fallback to default API endpointPosiblemente ocupada @Sehastrajit-S la tomó hace 28 días. Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
openai/openai-python#2927 · 6 comentarios ·
Los mantenedores suelen responder en 1 día
Todos los issues de openai/openai-python
Issues similares
-
`burr` fails to start when the Python path has a space in itPosiblemente ocupada @enekoreto la tomó hoy. Abiertostatus/needs-triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 5 días
-
gemini 出现了新的域名需要加入Abierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 72/100
-
Dificultad 2/5 Medio día Aptitud para principiantes 72/100
debpalash/VoiceStudio#2903 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
dagster-io/community-integrations#367 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
aws-samples/sample-per-model-bedrock#243 ·
Los mantenedores suelen responder en 1 día