bug: Batch API result file download fails for large outputs (>200MB) with ConnectionResetError
Maintainer antworten meist innerhalb von 1 Tag
@CacinieP arbeitet bereits daran.
Seit 31.8.2026.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 45/100
Rechercherichtung
Beginne damit, den Fehler über client.batches.retrieve_content und client.files.with_streaming_response.content mit einem großen Batch-Ergebnis zu reproduzieren, und vergleiche ihn anschließend mit dem Beispiel für direkte requests. Es werden keine Repository-Dateien oder Tests genannt; verfolge daher den Streaming-Pfad der Files API des SDK und ermittle, ob die unvollständige Antwort in der Bibliothek behandelt wird. Als erledigt gilt die Aufgabe, wenn Downloads großer Ergebnisse zuverlässig abgeschlossen werden oder die Einschränkung und das Retry-Verhalten ausdrücklich behandelt werden.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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
- Vorherrschende Sprache
- Python
- Sterne
- 32k
- Forks
- 7.3k
- Ø Merge
- 16 Std. 38 Min.
- Gemergte PRs (30 T.)
- 170
Entwicklungsumgebung
Startet den Dev-Container des Projekts im Browser, mit Ihrem eigenen GitHub-Konto.
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus openai/openai-python
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
openai/openai-python#4156 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
openai/openai-python#4022 · 23 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
fix(auth): SubjectTokenProviderError drops response and duplicates error message in workload identity providersEvtl. vergeben @mohmedmm hat das vor 31 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 86/100
openai/openai-python#4017 · 5 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
Define + export `ServiceTiers` string literalEvtl. vergeben @SparshGarg999 hat das vor 80 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
openai/openai-python#3556 · 3 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
Empty OPENAI_BASE_URL prevents fallback to default API endpointEvtl. vergeben @Sehastrajit-S hat das vor 46 Tagen übernommen. Offenbug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
openai/openai-python#2927 · 7 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in openai/openai-python
Ähnliche Issues
-
question
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 62/100
conda-forge/vc-feedstock#132 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
limitlessprojects/Go-Hybrid#3342 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 85/100
UKGovernmentBEIS/inspect_ai#6268 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
LSSTDESC/rail_sompz#42 ·
-
All tests fail with 'EXITED with status 3' on pytest 9.2.0 (TestReport._id is not marshallable)Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 66/100
pytest-dev/pytest-forked#113 ·