INNER CODE UNIT · TypeScript

getWorkersAIProvider

Jazee6/cloudflare-ai-web · app/api/index.ts:37

export const getWorkersAIProvider = () => {
  const credentials = getCloudflareCredentials();
  const gatewayCredentials = getCloudflareGatewayCredentials();
  if (!gatewayCredentials) {
    return createWorkersAI(credentials);
  }

  const { gatewayId, gatewayToken } = gatewayCredentials;
  const gatewayFetch: typeof globalThis.fetch = Object.assign(
    (input: Parameters<typeof globalThis.fetch>[0], init?: RequestInit) => {
      const headers = new Headers(init?.headers);
      headers.set("cf-aig-authorization", `Bearer ${gatewayToken}`);
      return globalThis.fetch(input, { ...init, headers });
    },
    { preconnect: globalThis.fetch.preconnect },
  );

  return createWorkersAI({

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…