From 3e06aed95f29dd4407b68fac55767d2d959b322e Mon Sep 17 00:00:00 2001 From: Oxygen <1391083091@qq.com> Date: Sat, 6 Jun 2026 02:27:44 +0800 Subject: [PATCH] fix: update dispatcher handling for undici v8.3.0+ compatibility Fixes fetchOptions.dispatcher not working with newer undici versions. Fixes #1886 --- src/client.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/client.ts b/src/client.ts index ac082a5e1..11900c4a2 100644 --- a/src/client.ts +++ b/src/client.ts @@ -955,11 +955,23 @@ export class OpenAI { ((globalThis as any).ReadableStream && options.body instanceof (globalThis as any).ReadableStream) || (typeof options.body === 'object' && options.body !== null && Symbol.asyncIterator in options.body); + // Strip runtime-specific options that are not part of the standard RequestInit. + // These (e.g. undici's dispatcher, agent, client) can cause errors when passed + // to the global fetch if the bundled undici version doesn't match the user's + // installed undici. Users who need these should pass their own fetch from undici. + const { + dispatcher: _dispatcher, + agent: _agent, + client: _client, + proxy: _proxy, + ...fetchInitOptions + } = options as Record; + const fetchOptions: RequestInit = { signal: controller.signal as any, ...(isReadableBody ? { duplex: 'half' } : {}), method: 'GET', - ...options, + ...fetchInitOptions, }; if (method) { // Custom methods like 'patch' need to be uppercased