MCPcopy Create free account
hub / github.com/openai/openai-node / buildRequest

Method buildRequest

src/client.ts:1105–1138  ·  view source on GitHub ↗
(
    inputOptions: FinalRequestOptions,
    { retryCount = 0 }: { retryCount?: number } = {},
  )

Source from the content-addressed store, hash-verified

1103 }
1104
1105 async buildRequest(
1106 inputOptions: FinalRequestOptions,
1107 { retryCount = 0 }: { retryCount?: number } = {},
1108 ): Promise<{ req: FinalizedRequestInit; url: string; timeout: number }> {
1109 const options = { ...inputOptions };
1110 const { method, path, query, defaultBaseURL } = options;
1111
1112 const url = this.buildURL(path!, query as Record<string, unknown>, defaultBaseURL);
1113 if ('timeout' in options) validatePositiveInteger('timeout', options.timeout);
1114 options.timeout = options.timeout ?? this.timeout;
1115 const { bodyHeaders, body, isStreamingBody } = this.buildBody({ options });
1116
1117 if (isStreamingBody) {
1118 inputOptions.__metadata = {
1119 ...inputOptions.__metadata,
1120 hasStreamingBody: true,
1121 };
1122 }
1123
1124 const reqHeaders = await this.buildHeaders({ options: inputOptions, method, bodyHeaders, retryCount });
1125
1126 const req: FinalizedRequestInit = {
1127 method,
1128 headers: reqHeaders,
1129 ...(options.signal && { signal: options.signal }),
1130 ...((globalThis as any).ReadableStream &&
1131 body instanceof (globalThis as any).ReadableStream && { duplex: 'half' }),
1132 ...(body && { body }),
1133 ...((this.fetchOptions as any) ?? {}),
1134 ...((options.fetchOptions as any) ?? {}),
1135 };
1136
1137 return { req, url, timeout: options.timeout };
1138 }
1139
1140 private async buildHeaders({
1141 options,

Callers 4

makeRequestMethod · 0.95
index.test.tsFile · 0.45
log.test.tsFile · 0.45
azure.test.tsFile · 0.45

Calls 4

buildURLMethod · 0.95
buildBodyMethod · 0.95
buildHeadersMethod · 0.95
validatePositiveIntegerFunction · 0.90

Tested by

no test coverage detected