portkey-node-sdk icon indicating copy to clipboard operation
portkey-node-sdk copied to clipboard

Custom Fetch Client

Open jczstudios opened this issue 1 year ago • 0 comments

Thoughts on support for a custom Fetch implementation? For example, in my Cloudflare worker, I'd like to use a worker to worker binding to call my Portkey gateway. I am able to do this with the Open AI like this:

const portkey = new OpenAI({
    baseURL: baseUrl ?? env.PORTKEY_URL,
    apiKey: provider === 'openai' ? env.OPENAI_API_KEY : env.ANTHROPIC_API_KEY,
    defaultHeaders: createHeaders({
      provider: provider,
    }),
    fetch: (url, options) => {
      if (env.AI_GATEWAY) {
        return env.AI_GATEWAY.fetch(url, options)
      }

      return fetch(url, options)
    },
  })

jczstudios avatar Jan 22 '25 16:01 jczstudios