OpenAI icon indicating copy to clipboard operation
OpenAI copied to clipboard

Add support for custom HTTP headers

Open benvolioT opened this issue 2 years ago • 1 comments

Is your feature request related to a problem? Please describe. I would like to integrate with OpenAI via the Helicone proxy, but to do so, I need to be able to specify a custom HTTP header.

Describe the solution you'd like Proxy APIs like Helicone wrap OpenAI's APIs with additional functionality. To use Helicone, you not only need to point the OpenAI client at the Helicone host, but you also have to set an additional HTTP header on the requests. For details, please refer to https://docs.helicone.ai/getting-started/integration-method/openai-proxy.

To enable this, I propose:

  1. Changing OpenAI.swift's Configuration struct to take an optional dictionary of key/value pairs, where the key is the name of the HTTP header, and the value is its value.
  2. Modifying performRequest() and performSteamingRequest() in that file to pass that optional dictionary to URLRequestBuildable.build() in a similar manner as organizationIdentifier is passed today
  3. Changing the URLRequestBuildable.build() interface to accept that optional dictionary
  4. Changing JSONRequest.build(), MultipartFormDataRequest.build(), etc. to conform to the updated interface, setting the header(s) on the request that is built if any were supplied in the optional dictionary.

Describe alternatives you've considered I think taking an optional dictionary of headers is preferable to explicitly covering every possible header that might be used by other proxies like Helicone. Other than that, I can't think of too many other ways to do this.

Additional context N/A

benvolioT avatar Jul 21 '23 16:07 benvolioT

Submitted pull request #93 for this issue.

benvolioT avatar Jul 30 '23 04:07 benvolioT