Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

bug: Batch API result file download fails for large outputs (>200MB) with ConnectionResetError

未关闭
#2,959 7 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@CacinieP 已经在做这个了。

开始于 2026年8月31日。

  • #2985 来自 @NIK-TIGER-BILL —— 已关闭,未合并
  • #3764 来自 @CacinieP —— 未关闭

评估

难度
4/5
预计耗时
3-5 天
新手友好度
45/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
python
领域
api, backend

调研方向

首先,使用 client.batches.retrieve_content 和 client.files.with_streaming_response.content 对大型 Batch 结果复现该故障,然后将其与直接 requests 示例进行比较。未指定任何仓库文件或测试,因此请跟踪 SDK 的 Files API 流式处理路径,并确定库是否处理了不完整的响应。完成的标准是大型结果下载能够可靠完成,或者明确处理该限制和重试行为。

由索引模型根据 Issue 内容生成。

描述

bug
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:

  1. Prepare a batch with ~50,000 rows (near the OpenAI limit)
  2. Submit to Batch API with endpoint /v1/embeddings
  3. Wait for status = completed
  4. 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

主要语言
Python
星标
31.8k
派生
8k
平均合并
22 小时 23 分钟
30 天内合并 PR
148

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

openai/openai-python 的其他 Issue

查看 openai/openai-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。