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

Method fetchWithAuth

src/client.ts:968–990  ·  view source on GitHub ↗
(
    url: RequestInfo,
    init: RequestInit,
    timeout: number,
    controller: AbortController,
    schemes: { bearerAuth?: boolean; adminAPIKeyAuth?: boolean } = {
      bearerAuth: true,
      adminAPIKeyAuth: true,
    },
  )

Source from the content-addressed store, hash-verified

966 }
967
968 protected async fetchWithAuth(
969 url: RequestInfo,
970 init: RequestInit,
971 timeout: number,
972 controller: AbortController,
973 schemes: { bearerAuth?: boolean; adminAPIKeyAuth?: boolean } = {
974 bearerAuth: true,
975 adminAPIKeyAuth: true,
976 },
977 ): Promise<Response> {
978 if (this._workloadIdentityAuth && schemes.bearerAuth) {
979 const headers = init.headers as Headers;
980 const authHeader = headers.get('Authorization');
981 if (!authHeader || authHeader === `Bearer ${WORKLOAD_IDENTITY_API_KEY_PLACEHOLDER}`) {
982 const token = await this._workloadIdentityAuth.getToken();
983 headers.set('Authorization', `Bearer ${token}`);
984 }
985 }
986
987 const response = await this.fetchWithTimeout(url, init, timeout, controller);
988
989 return response;
990 }
991
992 async fetchWithTimeout(
993 url: RequestInfo,

Callers 1

makeRequestMethod · 0.95

Calls 3

fetchWithTimeoutMethod · 0.95
getMethod · 0.80
getTokenMethod · 0.80

Tested by

no test coverage detected