openai/openai-node

Allow to create `OpenAI` client without specifying apiKey or to be defined as an environment variable.

samuelint opened this issue · 1 comments

Confirm this is a feature request for the Node library and not the underlying OpenAI API.

  • This is a feature request for the Node library

Describe the feature or improvement you're requesting

It would be useful to allow the creation of OpenAI client without specifying an apiKey (or OPENAI_API_KEY as an environment variable).

The use case for that is:

  • Have a server with API compatible with OpenAI spec, instead of writing a custom wrapper. (This can save a lot of time and efforts)
  • Have the APIKey managed on the server
  • Use the OpenAI official client in the browser directly and change the baseURL for my custom server
  • If the api key is provided from the client, use the one passed in request. Otherwise, use the default one on the server.

As of today

Using this approach as of today, require to:

  • set a mock "apiKey" on the client
  • Set the flag dangerouslyAllowBrowser: true on the client
  • ignore the passed api key on the server side

and does not support the use case If the api key is provided from the client, use the one passed in request. Otherwise, use the default one on the server.. Would need to pass some header or another workaround to tell the server to ignore the key (which is not clean)

new OpenAI({
    baseURL,
    apiKey: 'my-mock-key',
    dangerouslyAllowBrowser: true,
  })

With the proposed change

new OpenAI({
    baseURL,
    dangerouslyAllowBrowser : true,
  })

Additional context

No response