Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment on lines +963 to +967

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve runtime fetch options when calling compatible fetches

When users follow the documented proxy setup, e.g. new OpenAI({ fetch, fetchOptions: { dispatcher: proxyAgent } }), or the Bun/Deno proxy/client examples, these properties are removed before this.fetch is invoked, so the request silently bypasses the configured proxy/dispatcher even though the caller supplied a compatible fetch implementation. This should only strip or guard incompatible options for the problematic global-undici mismatch case, not unconditionally drop every runtime-specific fetch option.

Useful? React with 👍 / 👎.

} = options as Record<string, unknown>;

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
Expand Down